Japanino Twitter Grind sesame
forked from Japanino Twitter FURIKAKE (diff: 13)
D6ポートにリードスイッチをつないで、回した回数をツイートします 1. JapaninoPOVFirmataをJapaninoにアップロードする 2. Funnel Serverを起動してボードタイプとシリアルポートを選択する (2回目以降はFunnel Serverを起動するだけでOKです) 3. 右側のボタンをクリックしてこのコンテンツを再生する 4. いきなりカウントダウンがスタートしますので、D6-GNDにはドアスイッチを先につないでおきます。 5. 10分間でタイムアウトしたら、Twitter投稿用のボタンが表示されます その後、カウントダウンが再開します 6. このサンプルからFORKして、もっと面白いコンテンツに発展させて ください:-) 参考:セットアップ方法の詳細に関しては、以下のページでの説明を 参照してください。 大人の科学マガジンVol.27 http://otonanokagaku.net/magazine/vol27/ wonderfl x japanino http://wonderfl.net/event/japanino/ 注意:光残像キットは、あまり激しく操作すると壊れてしまうことが ありますので注意してください。
Related images
- a10012d05d0097679e7bc10186b62aa730188ad8
- 5f16fb9e7b6b224936dd5dca92bffc9c2fd204d1
- cd822c4ebc86121f95167ac25e1990f480da64bc
ActionScript3 source code
/**
* Copyright hacker_zen0qr6h ( http://wonderfl.net/user/hacker_zen0qr6h )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3al6
*/
// forked from hacker_zen0qr6h's Japanino Twitter FURIKAKE
// forked from hacker_zen0qr6h's forked from: Japanino Twitter Frige
// forked from kotobuki's Japanino Twitter Example
// D6ポートにリードスイッチをつないで、回した回数をツイートします
// forked from kotobuki's Japanino Test
// 1. JapaninoPOVFirmataをJapaninoにアップロードする
// 2. Funnel Serverを起動してボードタイプとシリアルポートを選択する
// (2回目以降はFunnel Serverを起動するだけでOKです)
// 3. 右側のボタンをクリックしてこのコンテンツを再生する
// 4. いきなりカウントダウンがスタートしますので、D6-GNDにはドアスイッチを先につないでおきます。
// 5. 10分間でタイムアウトしたら、Twitter投稿用のボタンが表示されます
// その後、カウントダウンが再開します
// 6. このサンプルからFORKして、もっと面白いコンテンツに発展させて
// ください:-)
//
// 参考:セットアップ方法の詳細に関しては、以下のページでの説明を
// 参照してください。
//
// 大人の科学マガジンVol.27
// http://otonanokagaku.net/magazine/vol27/
//
// wonderfl x japanino
// http://wonderfl.net/event/japanino/
//
// 注意:光残像キットは、あまり激しく操作すると壊れてしまうことが
// ありますので注意してください。
package {
import com.bit101.components.*;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import com.bit101.components.*;
import flash.display.*;
import flash.events.*;
import flash.net.*
import flash.utils.*;
import funnel.*;
import flash.display.MovieClip;
import flash.display.Sprite;
public class JapaninoTwitterExample extends Sprite {
// 制限時間
private static const TIME_LIMIT:int = 10;
// Japanino
private var _japanino:Arduino;
// カウントを表示するためのテキストフィールド
private var _countLabel:Label;
// 残りの時間を表示するためのテキストフィールド
private var _remainingTimeLabel:Label;
// 光残像キットのハンドルを回転させた回数
private var _count:int = 0;
// 残り時間
private var _remainingTime:int = TIME_LIMIT;
// カウントダウン用のタイマ
private var _countdownTimer:Timer;
// for teitter use
private var _text:String;
private var _footer:String;
private var post:String;
private var linkURL:String;
private var hashTag:String;
public function JapaninoTwitterExample() {
// Japaninoのインスタンスを生成
_japanino = new Arduino(Arduino.FIRMATA);
// カウントを表示するためのテキストフィールドを生成
_countLabel = new Label(this, 100, 200);
_countLabel.text = "Waiting...";
_countLabel.scaleX = 2;
_countLabel.scaleY = 2;
addChild(_countLabel);
// 残り時間を表示するためのテキストフィールドを生成
_remainingTimeLabel = new Label(this, 100, 160);
_remainingTimeLabel.scaleX = 2;
_remainingTimeLabel.scaleY = 2;
addChild(_remainingTimeLabel);
// Japaninoの準備が完了した時に発生するイベントに対するイベントリスナをセット
_japanino.addEventListener(FunnelEvent.READY, onReady);
}
// Japaninoの準備ができると呼ばれる
private function onReady(event:FunnelEvent):void {
// Japaninoの準備ができたら、10秒間をカウントダウンするタイマを生成してスタート
// タイムアウトが発生した時にonTimeoutを呼び出す
_countdownTimer = new Timer(1000, TIME_LIMIT);
_countdownTimer.addEventListener(TimerEvent.TIMER, onTick);
_countdownTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimeout);
_countdownTimer.start();
// JapaninoのFIRMATA_STRINGイベントに対するイベントリスナをセット
_japanino.addEventListener(FunnelEvent.FIRMATA_STRING, onMessage);
// 残り時間の表示とカウンタの表示を更新する
_remainingTimeLabel.text = "Remaining Time: " + TIME_LIMIT;
_countLabel.text = "Grind sesame";
}
// Japaninoからメッセージを受信すると呼ばれる
private function onMessage(event:FunnelEvent):void {
// メッセージが"!"でかつ残り時間があれば
if (event.message == "!" && (_remainingTime > 0)) {
// カウントを増やしてテキストフィールドの表示を更新
_count++;
_countLabel.text = "Count: " + _count;
var nR:int = Math.ceil(Math.random() * 5) + 5;
// 色をランダムで選ぶ
var color:int = 0x000000;
// 位置をランダムで選ぶ
var centerX:Number = Math.round(Math.random()*400) + 50;
var centerY:Number = Math.round(Math.random()*400) + 50;
// 円のクラスのインスタンスを作る
var oneCircle:MovieClip = new DrawCircle1(centerX, centerY, nR, color);
// 円のインスタンスを表示リストに追加する
addChild(oneCircle);
}
}
// カウントダウン用のタイマでイベントが発生すると呼ばれる
private function onTick(e:TimerEvent):void {
// 残り時間を1つずつ減らして表示を更新する
_remainingTime = _countdownTimer.repeatCount
- _countdownTimer.currentCount;
trace(_remainingTime);
_remainingTimeLabel.text = "Remaining Time: " + _remainingTime;
}
private function onTimeout(e:TimerEvent):void {
// Japaninoからのイベントを受取らないようにリスナを削除
_japanino.removeEventListener(FunnelEvent.FIRMATA_STRING, onMessage);
// 投稿用文字列を更新して表示する
linkURL = "http://wonderfl.net/c/3al6/";
hashTag = "#wonderfl #japanino";
_text = "ゴマすり器を" + _count + "回まわしました。";
_footer = " " + linkURL + " " + hashTag;
post = _text + _footer; // 投稿する文章
navigateToURL(new URLRequest("http://twitter.com/home?status="
+ escapeMultiByte(post)), "_blank");
// restart timer
_countdownTimer.reset();
_count = 0;
_countLabel.text = "Count: " + _count;
_remainingTime = TIME_LIMIT;
//_countdownTimer.start();
}
}
}
import flash.display.MovieClip;
class DrawCircle1 extends MovieClip {
public function DrawCircle1(nX:int, nY:int, nR:int, color:int) {
// 線の太さを10, 色をcolorにセットする
graphics.lineStyle(10, color);
// nX, nYを中心とする半径nRの円を描く
graphics.beginFill(color);
graphics.drawCircle(nX, nY, nR);
graphics.endFill();
}
}
