ルーレット
画面クリック後、キータイプで回転
/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aA0M
*/
//画面クリック後、キータイプで回転
package {
import flash.net.FileReference;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Sprite;
import caurina.transitions.Tweener;
import com.bit101.components.*;
[SWF(width=465, height=465, backgroundColor=0x000000)]
public class FlashTest extends Sprite {
private var roullet:Roullet;
private var text:TextArea;
private var focust:InputText;
private var window:Window;
private var button:PushButton;
private var div:int = 10;
private var key_code:String = "0123456789pqwertyuio";
private var file:FileReference = new FileReference();
public function FlashTest() {
// write as3 code here..
roullet = new Roullet( div );
var triangle:Triangle = new Triangle();
addChild( roullet );
addChild( triangle );
roullet.x = 230; roullet.y = 180;
triangle.x = 230; triangle.y = 300;
stage.addEventListener( "keyDown", key );
text = new TextArea( stage,5,390 );
text.setSize( 455, 50 );
text.visible = true;
button = new PushButton(stage,350,442,"save",save);
window = new Window( stage,100,100,"focust" );
window.setSize( 120, 90 );
focust = new InputText( window,10,35,"0" );
var ok:PushButton = new PushButton( window,10,60,"ok", function f():void{window.visible=false} );
}
private function key(e:KeyboardEvent ):void {
if( e.keyCode != Keyboard.SHIFT && stage.focus == null){
var target:int = key_code.indexOf( String.fromCharCode(e.charCode) )
do{
var check:Boolean = false
var rand:Number = Math.random() * 1800 + 1800;
var select:int = Math.floor( (rand / 360 * div)+0.5 ) % div
if( 0 <= target && div > target ){
if( (select == target) == e.shiftKey ){check = true}
}
}while( check )
Tweener.addTween( roullet ,{
time: rand / 180,
rotation: -rand,
transition: "easeOutExpo",
onComplete: function f():void{
text.text = select + ", " + text.text;
if(select + "" == focust.text){ text.text = "o" + text.text; Sound.se(0); }
else{ Sound.se(1); }
window.visible = true
}
});
}
}
private function save(e:Event = null):void{
file.save( text.text, "result.txt");
}
}
}
import flash.text.TextFormat;
import flash.text.TextField;
import flupie.textanim.*;
import flash.display.*;
class Roullet extends Sprite{
public function Roullet( num:int ){
for(var i:int=0; i<num; i++){
var seg:Segment = new Segment( 160, num, i );
addChild( seg );
seg.rotation = 360 * (i/num)
}
}
}
class Segment extends Sprite{
private var colorArr:Array = [0x880000,0x006600];
public function Segment( r:Number, div:Number, num:int ){
graphics.lineStyle( 5, 0x333333, 1.0 );
graphics.beginFill( colorArr[ num % colorArr.length ] );
graphics.moveTo(0,0);
graphics.lineTo( r*Math.sin( -Math.PI/div ), r*Math.cos( -Math.PI/div ) );
graphics.lineTo( r*Math.sin( Math.PI/div ), r*Math.cos( Math.PI/div ) );
graphics.endFill();
var text:TextField = new TextField();
var format:TextFormat = new TextFormat("_typewriter",60,0xFFFFFF,true);
text.defaultTextFormat = format;
text.text = "" + num;
var bitmap:Bitmap = new Bitmap( new BitmapData(40,60,false,colorArr[ num % colorArr.length ]) );
bitmap.bitmapData.draw(text);
addChild( bitmap );
bitmap.y = 90;
bitmap.x = -20;
}
}
class Triangle extends Sprite{
public function Triangle(){
graphics.lineStyle( 5, 0x333333, 1.0 );
graphics.beginFill( 0xFFFFFF );
graphics.moveTo(0,0);
graphics.lineTo( -10, 80 );
graphics.lineTo( 10, 80 );
}
}
//SiON-----------------------------
import org.si.sion.*;
class MyDriver extends SiONDriver {
function MyDriver():void{
super();
setSamplerData(0, render("%5@4 l36 <<<gecgecbgecbagfedc"));
setSamplerData(1, render("%5@1 <c18>>c6"));
play();
}
}
class Sound{
static public var driver:MyDriver = new MyDriver();
static public function se(i:int,delay:int=0):void{
driver.playSound(i,0,delay);
}
}