2012年3月25日日曜日

C# ビープ音 (1)


// 救急車のサイレン音を再生
// ↓コンパイル方法
// csc /out:TestBeep.exe TestBeep.cs
class TestBeep
{
 public static void Main()
 {
  int loopNum = 2; // ループ回数
  for(int i = 0; i < loopNum; i++) {
   System.Console.Beep(988, 900); // シー
   System.Console.Beep(784, 900); // ソー
  }
  for(int i = 0; i < loopNum; i++) {
   System.Console.Beep(932, 900); // シ♭ー
   System.Console.Beep(740, 900); // ソ♭ー
  }
  for(int i = 0; i < loopNum; i++) {
   System.Console.Beep(880, 900); // ラー
   System.Console.Beep(698, 900); // ファー
  }
 }
}

2012年3月24日土曜日

Unity エディットウィンドウ(2) 三角形の描画

エディットウィンドウで三角形を描画するテスト
GLを使用すると描画できた
Editor/EditWindowD.cs


using UnityEngine;
using UnityEditor;

public class EditWindowD : EditorWindow {
    Material    m_Material;    // マテリアル
    Vector2 []  m_VecArray;    // 頂点の配列
    int         m_VecNum = 3;  // 頂点数

    // メニューに追加
    [MenuItem ("Window/EditWindowD")]
    static void Init() {
        EditWindowD window = (EditWindowD)EditorWindow.GetWindow( typeof (EditWindowD) );
        window.Show();
    }

    // スクリプトのロード時に呼ばれる ScriptableObject.OnEnable()
    void OnEnable() {
        CreateVertexArray();
        CreateMaterial();
    }
    
    // エディタウィンドウのGUI処理をここに記述 EditorWindow.OnGUI()
    void OnGUI() {
        // 再描画イベント時に描画処理を行う
        if (EventType.Repaint != Event.current.type) return;

        // 実行するとウィンドウが真っ白
        //GL.Clear(false, true, Color.white);

        m_Material.SetPass(0);
        DrawLine();
    }

    // マテリアルの作成
    void CreateMaterial() {
        m_Material = new Material( "Shader \"Lines/Colored_Blended\" {" +
            "SubShader { Pass { " +
            "    Blend SrcAlpha OneMinusSrcAlpha " +
            "    ZWrite Off Cull Off Fog { Mode Off } " +
            "    BindChannels {" +
            "      Bind \"vertex\", vertex" + 
            "      Bind \"color\", color" +
            "} } } }" );
        m_Material.hideFlags = HideFlags.HideAndDontSave;
        m_Material.shader.hideFlags = HideFlags.HideAndDontSave;
    }

    // 頂点の配列を作成
    void CreateVertexArray() {
        m_VecArray = new Vector2[m_VecNum];
        m_VecArray[0] = new Vector2(50, 10);
        m_VecArray[1] = new Vector2(10, 60);
        m_VecArray[2] = new Vector2(90, 60);
    }

    // 線分の描画
    void DrawLine() {
        GL.Color(Color.blue);
        GL.Begin( GL.LINES );
        for(int i = 0; i < m_VecNum; i++) {
            int idx0 = i;
            int idx1 = (i == m_VecNum - 1) ? 0 : idx0 + 1;
            GL.Vertex(m_VecArray[idx0]);
            GL.Vertex(m_VecArray[idx1]);
        }
        GL.End();
    }
}

2012年3月20日火曜日

Redis Cygwin上で使用


Redis v2.4.9 をDL
makeするとエラー発生
 redis.c の setupSignalHandlers() SA_ONSTACK が未定義らしい
 テストなので、SA_ONSTACKを削除して make -> OK

デフォルト設定でサーバー起動
./redis-server

設定ファイルを指定してサーバー起動
./redis-server redis.conf

クライアントを起動
./redis-cli


データの追加、取得を行ってみる
> SET key value1  # キーと値を設定
> GET key         # キーの値を取得
> OK


#設定ファイル redis.conf
# ↓TODO
loglevel notice
maxmemory 1mb

MAXScript 形状のブール演算


-- メッシュのブール演算のテスト
fn Test5 = (
 -- 形状を作成
 s1 = box width:150 height:5
 
 s2 = sphere radius:20
 s2.pos.x = 50

 s3 = pyramid depth:55
 s3.pos.x = -50
 s3.pos.z = 2.5
 
 -- 減算
 s1 = s1 - s2
 
 -- 加算
 s1 += s3
 
 delete s2
 delete s3
 s1
)

Test5()

MAXScript 配列とビット配列


-- .NETオブジェクトの ArrayList を使用するテスト
fn TestArray1 = (
 -- .NET のArrayListオブジェクトを取得
 arrayList = dotNetObject "System.Collections.ArrayList"
 
 -- ArrayListに要素を追加
 arrayList.Add("A")
 arrayList.Add("BC")
 arrayList.Add("D")
 
 -- 配列の要素数を出力
 format "arrayList.Count = %\n" arrayList.Count
 
-- format "%\n" arrayList[1] -- ERROR
 
 str = arrayList.ToString()
 format "str = %\n" str
 
 item1 = arrayList.Item(1)
 format "%\n" item1
 
 for i = 0 to arrayList.Count - 1 do (
  --  ↓ ERROR発生
--  format "arrayList[%] = %\n" i arrayList[i] -- ERROR
  -- 指定したインデックスの要素を取得
  item = arrayList.Item(i)
  format "arrayList[%] = %\n" i item
 )

-- arrayList.Item(1) = "bc"
 
 item1 = arrayList.Item(1)
 format "item1 = %\n" item1

 for i = 0 to arrayList.Count - 1 do (
  --  ↓ get_Item()が出力される
  format "arrayList[%] = %\n" i arrayList.Item(i)
 )
)

-- 配列とビット配列のテスト
fn TestArray2 = (
 -- 空の配列を作成
 a = #()

 -- 配列に値を追加
 append a 1
 append a 2

 format "a = %\n" a

 -- 配列の要素を削除
 deleteItem a 2
 --deleteItem a 1

 format "a = % a.count = %\n" a a.count

 -- 空のビット配列を作成
 b0 = #{}
 b1 = #{}

 --b0[0] = true -- ERROR インデックスは1から開始
 b0[1] = false
 b0[20] = true
 b0[32] = true
 
 b1[8] = true

 format "b0 = % b0.count = %\n" b0 b0.count
 format "b1 = % b1.count = %\n" b1 b1.count
 
 b2 = b0 + b1 -- OR演算
 b3 = b0 * b1 -- AND演算
 
 format "b0 + b1 = %\n" b2
 format "b0 * b1 = %\n" b3
 
 b4 = -b1  -- ビットの反転
 format "-b1 = %\n" b4
 
 b1[20] = true
 b5 = b0 - b1 -- 差
 format "b0 - b1 = %\n" b5
 
 b6 = #{1..7, 16}
 format "b6 = % b6.numberSet = %\n" b6 b6.numberSet
)

TestArray2()

2012年3月4日日曜日