簡単な歯車
微妙にタイミングが・・・
/**
* Copyright 178ep3 ( http://wonderfl.net/user/178ep3 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8rC5
*/
//微妙にタイミングが・・・
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Point;
import flash.events.Event;
public class Gear extends Sprite
{
private var s:Shape;
private var s2:Shape;
private var s3:Shape;
public function Gear()
{
s = addChild(new Shape()) as Shape;
s.x = stage.stageWidth/2;
s.y = stage.stageHeight/2;
s.graphics.beginFill(0xff0000,0.6);
DrawGear(s,1,0x00,72,150,140);
s2 = addChild(new Shape()) as Shape;
s2.x = stage.stageWidth/2+180;
s2.y = stage.stageHeight/2+120;
s2.graphics.beginFill(0x00ff00,0.6);
DrawGear(s2,1,0x00,32,75,65);
s3 = addChild(new Shape()) as Shape;
s3.x = -23;
s3.y = -127;
s3.graphics.beginFill(0x0000ff,0.6);
DrawGear(s3,1,0x00,144,300,285);
addEventListener(Event.ENTER_FRAME,loop);
}
private function DrawGear(shape:*,linePoint:uint,lineColor:uint,gear:uint,R:Number,r:Number):void
{
shape.graphics.lineStyle(linePoint,lineColor);
var angle:Number = 90/gear * Math.PI/180;
var fp:Point = Point.polar(R,angle*0);
shape.graphics.moveTo(fp.x,fp.y);
for(var i:uint=0; i<4*gear; i+=4)
{
var _0p:Point = Point.polar(R,angle*i);
var _1p:Point = Point.polar(R,angle*(i+1));
var _2p:Point = Point.polar(r,angle*(i+2));
var _3p:Point = Point.polar(r,angle*(i+3));
shape.graphics.lineTo(_0p.x,_0p.y);
shape.graphics.lineTo(_1p.x,_1p.y);
shape.graphics.lineTo(_2p.x,_2p.y);
shape.graphics.lineTo(_3p.x,_3p.y);
}
shape.graphics.lineTo(fp.x,fp.y);
shape.graphics.endFill();
}
private function loop(e:Event):void
{
s.rotation += 0.5;
s2.rotation -= 1.125;
s3.rotation -= 0.25;
}
}
}