フィボナッチ数列をlineToで結んでみた
/**
* Copyright yamadori ( http://wonderfl.net/user/yamadori )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jg9n
*/
/*
*フィボナッチ数列をlineToで結んでみました。
*/
// forked from _azzip's フィボナッチの勉強
/*
* フィボナッチの勉強
*
* 数値の変化でどんな感じになるのか見たかったです。
*
* ところどころなんか可愛い動きがあってかわいいですww
*
*/
package
{
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.events.Event;
import flash.text.*;
import flash.display.Shape;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.ColorTransform;
import frocessing.color.ColorHSV;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]
public class Main extends Sprite
{
private var particles:Array = [];
private var angles:Array = new Array();
private var angle:Number;
private var count:Number = 2;
private var totalNum:int = 200;
private var tf:TextField;
private var shape:Shape;
private var bd:BitmapData;
private var ct:ColorTransform;
private var color:ColorHSV
private var glow:GlowFilter;
public function Main()
{
shape = new Shape();
bd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x0);
addChild(new Bitmap(bd));
ct = new ColorTransform(0.7, 0.7, 0.7);
tf = new TextField();
var tfmt:TextFormat = new TextFormat("ARIAL",null,0xFFFFFF);
tf.defaultTextFormat = tfmt;
tf.x = 0;
tf.y = 0;
addChild(tf);
color = new ColorHSV();
shape.graphics.lineStyle(1,color.value);
for(var i:int =0; i<totalNum; i++)
{
angle = i * Math.PI * count * ((1 + Math.sqrt(5))/2);
angles.push(angle);
var p:Particle = new Particle();
particles.push(p);
particles[i].x = stage.stageWidth/2 + (i+1) * Math.cos(angles[i]);
particles[i].y = stage.stageHeight/2 + (i+1) * Math.sin(angles[i]);
if(i != 0)
{
if(i == 1) shape.graphics.moveTo(particles[i-1].x, particles[i-1].y);
else shape.graphics.lineTo(particles[i-1].x, particles[i-1].y);
shape.graphics.lineTo(particles[i].x, particles[i].y);
}
/*
if(i >= 4)
{
shape.graphics.moveTo(particles[i-4].x, particles[i-4].y);
shape.graphics.lineTo(particles[i].x, particles[i].y);
}
*/
}
bd.draw(shape);
addEventListener(Event.ENTER_FRAME,enterHandler);
}
private function enterHandler(e:Event):void
{
color.h += 1;
shape.graphics.clear();
shape.graphics.lineStyle(1, color.value);
count += 0.04;
tf.text = "π: " + String(Math.floor(count));
for(var i:int =0; i<totalNum; i++)
{
angles[i] = i * Math.PI * Math.floor(count) * ((1 + Math.sqrt(5))/2);
particles[i].x += ((stage.stageWidth/2 + (i+1) * Math.cos(angles[i])) - particles[i].x)/5;
particles[i].y += ((stage.stageHeight/2 + (i+1) * Math.sin(angles[i])) - particles[i].y)/5;
if(i != 0)
{
if(i == 1) shape.graphics.moveTo(particles[i-1].x, particles[i-1].y);
else shape.graphics.lineTo(particles[i-1].x, particles[i-1].y);
shape.graphics.lineTo(particles[i].x, particles[i].y);
}
/*
if(i >= 4)
{
graphics.moveTo(particles[i-4].x, particles[i-4].y);
graphics.lineTo(particles[i].x, particles[i].y);
}
*/
}
//bd.fillRect(bd.rect, 0x0);
bd.colorTransform(bd.rect, ct);
bd.draw(shape);
}
}
}
class Particle
{
public var x:Number;
public var y:Number;
function Paticle()
{
}
}