spiral
フィボナッチ数列をlineToで結んでみました。
フィボナッチの勉強
数値の変化でどんな感じになるのか見たかったです。
ところどころなんか可愛い動きがあってかわいいですww
/**
* Copyright tananuka13 ( http://wonderfl.net/user/tananuka13 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vkBr
*/
// forked from yamadori's フィボナッチ数列をlineToで結んでみた
/*
*フィボナッチ数列をlineToで結んでみました。
*/
// forked from _azzip's フィボナッチの勉強
/*
* フィボナッチの勉強
*
* 数値の変化でどんな感じになるのか見たかったです。
*
* ところどころなんか可愛い動きがあってかわいいですww
*
*/
package
{
import flash.geom.Rectangle;
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()
{
Render.init(this)
shape = new Shape();
bd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
addChild(new Bitmap(bd));
ct = new ColorTransform(0.7, 0.7, 0.7);
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
{
Render.update()
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);
}
}
bd.colorTransform(bd.rect, ct);
bd.draw(shape);
}
}
}
class Particle
{
public var x:Number;
public var y:Number;
function Paticle()
{
}
}
import flash.display.BlendMode;
import flash.geom.ColorTransform;
import flash.filters.BlurFilter;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Bitmap;
class Render extends Sprite
{
private static const ZERO:Point = new Point()
private static const MERGE:uint = 0x10
private static const BLUR:BlurFilter = new BlurFilter(5, 5)
private static const SCALE:Number = 1//
private static const SCALE_COLOR:ColorTransform = new ColorTransform(SCALE, SCALE, SCALE, SCALE)
private static var rect:Rectangle
private static var bm_render:BitmapData
private static var bm_effect:BitmapData
private static var main:Sprite
public static function init(main_:Sprite)
{
main = main_
main.stage.frameRate = 15
bm_render = new BitmapData(main.stage.stageWidth, main.stage.stageHeight, false, 0x000000)
bm_effect = bm_render.clone()
rect = bm_render.rect
main.addChildAt( new Bitmap(bm_render), 0 )
}
public static function update(e:Event = null):void
{
// render
bm_render.lock()
bm_render.draw(main)
bm_render.applyFilter( bm_render, rect, ZERO, BLUR)
//bm_effect.draw(main, null, SCALE_COLOR, BlendMode.ADD)
//bm_render.merge(bm_effect, rect, ZERO, MERGE,MERGE,MERGE,MERGE)
bm_render.unlock()
}
}