コッホ雪片
コッホ雪片 by ton
created:2008/12/21 22:45:47
ずっと動かしてるとめちゃくちゃ重くなるから注意してね!
//コッホ雪片 by ton
//created:2008/12/21 22:45:47
//ずっと動かしてるとめちゃくちゃ重くなるから注意してね!
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
[SWF(width=465, height=465, frameRate=60, backgroundColor=0x000000)]
public class KochSnow extends Sprite {
private var list:Array = [];
private var endPoint:Point;
private const W:int = stage.stageWidth;
private const H:int = stage.stageHeight;
private const L:int = W/2;
function KochSnow() {
var p1:Point = new Point(W/2, H/2 - L);
var p2:Point = new Point(L * Math.cos(Math.PI/6) + W/2, L * Math.sin(Math.PI/6) + H/2);
var p3:Point = new Point(L * Math.cos(Math.PI/6*5) + W/2, L * Math.sin(Math.PI/6) + H/2);
addLine(p1, p2);
addLine(p2, p3);
addLine(p3, p1);
stage.addEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
}
private function onEnterFrameHandler(event:Event):void {
var line:Line=list[0];
stage.removeChild(line);
list.splice(0, 1);
var p1:Point=new Point(Math.cos(line.angle)*line.distance/3+line.startP.x, Math.sin(line.angle)*line.distance/3+line.startP.y);
var p2:Point=new Point();
p2.x=Math.cos(line.angle - Math.PI / 3) * line.distance / 3 + p1.x;
p2.y=Math.sin(line.angle - Math.PI / 3) * line.distance / 3 + p1.y;
var p3:Point=new Point();
p3.x=Math.cos(line.angle + Math.PI / 3) * line.distance / 3 + p2.x;
p3.y=Math.sin(line.angle + Math.PI / 3) * line.distance / 3 + p2.y;
addLine(line.startP, p1);
addLine(p1, p2);
addLine(p2, p3);
addLine(p3, line.endP);
}
private function addLine(p1:Point, p2:Point):void{
var line:Line = new Line(p1, p2);
stage.addChild(line);
list.push(line);
}
}
}
import flash.display.Shape;
import flash.geom.Point;
class Line extends Shape{
public var startP:Point;
public var endP:Point;
public var distance:Number;
public var angle:Number;
function Line(startP:Point, endP:Point) {
this.startP = startP;
this.endP = endP;
distance = Point.distance(startP, endP);
angle = Math.atan2(endP.y-startP.y, endP.x-startP.x);
graphics.lineStyle(0,0xffffff);
graphics.moveTo(startP.x, startP.y);
graphics.lineTo(endP.x, endP.y);
graphics.endFill();
}
}