flash on 2010-1-5★をおくだけ
♥0 |
Line 77 |
Modified 2010-03-30 14:57:15 |
MIT License
archived:2017-03-20 10:49:36
ActionScript3 source code
/**
* Copyright otherone ( http://wonderfl.net/user/otherone )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gvIK
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.events.MouseEvent;
public class Test extends Sprite {
//variables
private var bg:Sprite;
private var txt:TextField;
public function Test() {
// write as3 code here..
bg=new Sprite;
bg.graphics.beginFill(0xddddddd);
bg.graphics.drawRect(0,0,1000,1000);
bg.graphics.endFill();
addChild(bg);
//graphics.lineStyle(2,0x000000);
//graphics.lineTo(50,100);
txt=new TextField();
addChild(txt);
txt.x=txt.y=200;
//onPressの代わり
addEventListener(MouseEvent.CLICK,fn_btnck);
addEventListener(MouseEvent.MOUSE_MOVE,fn_btnck);
}//
//method
private function fn_btnck(event:MouseEvent):void {
switch (event.type) {
case MouseEvent.CLICK :
//txt.text="クリック";
break;
case MouseEvent.MOUSE_MOVE :
//setSp();
setStar();
break;
}
}
private function setSp():void {
var sp:Sprite=new Sprite();
addChild(sp);
sp.graphics.beginFill(ran(0xffff00));
sp.graphics.drawRect(0,0,ran(10)+10,ran(10)+10);
sp.graphics.endFill();
sp.x=mouseX;
sp.y=mouseY;
}
private function setStar():void {
/*var shape = new Shape();
stage.addChild(shape);
var g = shape.graphics;
//g.lineStyle(1, 0x000000, 1.0);//
g.beginFill(0xFF0000, 1.0);//
g.moveTo(0,50);
g.lineTo(200,50);
g.lineTo(50,170);
g.lineTo(100,0);
g.lineTo(150,170);
g.endFill();
shape.x=mouseX;
shape.y=mouseY;
*/
var i;
var px =0;//
var py = 0;//
var radius = 50;//
var num = 5;//
var d = 0.5;//
var shape = new Shape();
addChild(shape);
shape.rotation=ran(180)
var g = shape.graphics;
g.lineStyle(1, ran(0xffff00), 1.0);// 線のスタイル指定
g.beginFill(ran(0xffff00), 1.0);// 面のスタイル設定
g.moveTo(px + radius, py);
var l = num * 2;
for (i=0; i < l; i++) {
var rad = i / l * Math.PI * 2;
if (i % 2) {
g.lineTo(
px + Math.cos(rad) * radius * d,
py + Math.sin(rad) * radius * d
);
} else {
g.lineTo(
px + Math.cos(rad) * radius,
py + Math.sin(rad) * radius
);
}
}
g.endFill();
shape.x=mouseX;
shape.y=mouseY;
}
//乱数を作る
private function ran(range:uint):uint {
var v:uint=Math.floor(Math.random() * range);
return v;
}
}//end of class
}//end of package