forked from: forked from: flash on 2009-8-19
forked from forked from: flash on 2009-8-19 (diff: 81)
but now it's gone too far from it...
ActionScript3 source code
/**
* Copyright tenasaku ( http://wonderfl.net/user/tenasaku )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ivWk
*/
// forked from hacker_kuukuu's forked from: flash on 2009-8-19
// but now it's gone too far from it...
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest():void {
var i:uint;
var kame:LineDrawer = new LineDrawer();
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.North();
kame.Teleport(100);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.Turn(144);
kame.Walk(100);
kame.West();
kame.Teleport(100);
for ( i = 0; i < 20; ++i ){
kame.Walk(80);
kame.Turn(126);
}
addChild(kame);
}
}
}
import flash.display.Sprite;
class LineDrawer extends Sprite{
private var x0:int = 240;
private var y0:int = 240;
private var theta:Number = 90*Math.PI/180;
public function LineDrawer(){
graphics.lineStyle(2,0x000000);
graphics.moveTo(x0,y0);
}
public function Teleport(length:Number):void {
if (length >= 0) {
x0 = Math.round( x0 + length*Math.cos(theta) );
y0 = Math.round( y0 + length*Math.sin(theta) );
graphics.moveTo(x0,y0);
}
}
public function Walk(length:Number):void {
if (length >= 0) {
x0 = Math.round( x0 + length*Math.cos(theta) );
y0 = Math.round( y0 + length*Math.sin(theta) );
graphics.lineTo(x0,y0);
}
}
// change direction (alpha) degree clockwise.
public function Turn(alpha:Number):void {
theta += alpha*Math.PI/180;
while (theta >= Math.PI*2) {
theta -= Math.PI*2;
}
while (theta < 0) {
theta += Math.PI*2;
}
}
// set direction (UP)
public function North():void {
theta = 270*Math.PI/180;
}
// set direction (RIGHT)
public function East():void {
theta = 0*Math.PI/180;
}
// set direction (LEFT)
public function West():void {
theta = 180*Math.PI/180;
}
// set direction (DOWN)
public function South():void {
theta = 90*Math.PI/180;
}
}
