阅读更多
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author hacker47
*/
public class Main extends Sprite
{
private var angle:Number = 0;
private var speed:Number = .05;
private var range:Number = 200;
private var vx:Number = 1;
private var startx:Number=100;
private var starty:Number=300;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
this.graphics.lineStyle(2,0xff0000,1,true);
this.graphics.moveTo(startx, starty);
addEventListener(Event.ENTER_FRAME, function running(e:Event):void {
var dx:Number = startx + vx;
var dy:Number = starty+Math.sin(angle) * range;
angle += speed;
graphics.lineTo(dx, dy);
startx = dx;
trace(angle);
});
}
}
}
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author hacker47
*/
public class Main1 extends Sprite
{
private var angle:Number = 0;
private var speed:Number = .05;
private var range:Number = 200;
private var vx:Number = 1;
private var startx:Number=100;
private var starty:Number=300;
public function Main1():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
this.graphics.lineStyle(2,0xff0000,1,true);
this.graphics.moveTo(startx, starty);
addEventListener(Event.ENTER_FRAME, function running(e:Event):void {
var dx:Number = startx + vx;
var dy:Number = starty+Math.sin(angle) * range;
angle += speed;
graphics.lineTo(dx, dy);
startx = dx;
if ((angle * 180 / Math.PI) > 360) {
range-= 30;
angle = 0;
trace("一个周期");
}
});
}
}
}
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author hacker47
*/
public class Main2 extends Sprite
{
private var angle:Number = 0;
private var speed:Number = .05;
private var range:Number = 200;
private var vx:Number = 2;
private var startx:Number=100;
private var starty:Number=300;
public function Main2():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
this.graphics.lineStyle(2,0xff0000,1,true);
this.graphics.moveTo(startx, starty);
addEventListener(Event.ENTER_FRAME, function running(e:Event):void {
var dx:Number = startx + vx;
var sin:Number = Math.sin(angle);
if (sin > 0) sin *= -1;
var dy:Number = starty+sin * range;
angle += speed;
graphics.lineTo(dx, dy);
startx = dx;
if ((angle * 180 / Math.PI) > 180) {
range-= 30;
angle = 0;
trace("一个周期");
if (range < 0) {
removeEventListener(Event.ENTER_FRAME, running);
}
}
});
}
}
}
- 大小: 17.2 KB
- 大小: 46.6 KB
- 大小: 38.9 KB