Created
May 30, 2012 03:08
-
-
Save abarth500/2833489 to your computer and use it in GitHub Desktop.
receiver2 on JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//メッセージはココで受信 | |
//チャンネル削除 | |
msg = msg.substring(msg.indexOf(":")+1); | |
//カンマで分けて配列へ | |
var fields = msg.split(","); | |
//配列最初の要素はコマンド名なので取り出します。 | |
var cmd = fields.shift(); | |
//コマンドに応じて処理を切り替えます。 | |
switch(cmd){ | |
case "mouse": | |
//注:サーバから来たデータは文字列として扱われているため、 | |
//数値を送った場合使用時はparseInt等で数値化する。 | |
if(X > -1){ | |
ctx.beginPath(); | |
ctx.moveTo(X, Y); | |
ctx.lineTo(parseInt(fields[0]), parseInt(fields[1])); | |
/* 三角形を線で描画 */ | |
ctx.stroke(); | |
} | |
X = parseInt(fields[0]); | |
Y = parseInt(fields[1]); | |
break; | |
case "down": | |
//線の色を赤に | |
ctx.strokeStyle = 'rgb(254, 0, 0)'; | |
break; | |
case "up": | |
//線の色を白に | |
ctx.strokeStyle = 'rgb(254, 254, 254)'; | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment