flash on 2010-5-19
//////////////////////////////////////////////////////////////////////////////
[AS3.0] ドットの光 (6)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1095
//////////////////////////////////////////////////////////////////////////////
/**
* Copyright Geo877 ( http://wonderfl.net/user/Geo877 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lW3G
*/
// forked from ProjectNya's DotLight [Red]
////////////////////////////////////////////////////////////////////////////////
// [AS3.0] ドットの光 (6)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1095
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]
import flash.display.BitmapData;
import flash.ui.Mouse;
import flash.events.Event;
public class Main extends Sprite {
public var grph:BitmapData;
public var grphDisplay:Bitmap;
public var pointsArrayX:Array;
public var pointsArrayY:Array;
public var gfx:MovieClip;
public function Main() {
pointsArrayX = new Array();
pointsArrayY = new Array();
grph = new BitmapData(465,465,false,0xFFFFFFFF);
grphDisplay = new Bitmap(grph);
addChild(grphDisplay);
gfx = new MovieClip();
addChild(gfx);
addEventListener(Event.ENTER_FRAME,mainLoop);
}
public var a:Number = 0;
public var b:Number = 0;
public var p:Number = 0.21;
public var q:Number = 0.41;
public var largest_d:Number = 0;
public function iterate():void{
//a|n+1 = a|n * b|n +p
//b|n+1 = 2a|n * (b|n - 2) +p
var a_n:Number = a;var b_n:Number = b;
a = a_n*b_n + p;
b = 2*a_n*(b_n-2) + q;
var d:Number = Math.sqrt(a*a+b*b);
if(d>largest_d)largest_d = d;
pointsArrayX.push(a);
pointsArrayY.push(b);
}
public function mainLoop(e:Event = null):void{
grph.fillRect(grph.rect,0xFFFFFF);
var i:Number = 0;
while(i<500){
iterate();
i++;
}
plot();
p+=0.001;
a = 0;
b = 0;
largest_d = 0;
pointsArrayX = [];
pointsArrayY = [];
}
public function plot():void{
xp = grph.width/2 - 0;
yp = grph.width/2 - 0;
grph.setPixel(xp,yp,0xFF0000);
grph.setPixel(xp,yp-1,0xFF0000);
grph.setPixel(xp,yp+1,0xFF0000);
grph.setPixel(xp,yp-2,0xFF0000);
grph.setPixel(xp,yp+2,0xFF0000);
grph.setPixel(xp,yp-3,0xFF0000);
grph.setPixel(xp,yp+3,0xFF0000);
grph.setPixel(xp-1,yp,0xFF0000);
grph.setPixel(xp+1,yp,0xFF0000);
gfx.graphics.clear();
gfx.graphics.lineStyle(1,0x000000,0.3);
gfx.graphics.moveTo(xp,yp);
gfx.graphics.lineTo(0,yp);
gfx.graphics.moveTo(xp,yp);
gfx.graphics.lineTo(xp,0);
gfx.graphics.moveTo(xp,yp);
gfx.graphics.lineTo(xp*2,yp);
gfx.graphics.moveTo(xp,yp);
gfx.graphics.lineTo(xp,yp*2);
gfx.graphics.lineStyle(1,0xAA1111,0.3);
var r:Number = Math.sqrt((grph.width/2)*(grph.width/2)+(grph.height/2)*(grph.height/2))/largest_d;
var i:Number = pointsArrayX.length-1;
while(i>=0){
var xp:Number = pointsArrayX[i];
var yp:Number = pointsArrayY[i];
xp*=r/1.5;
yp*=r/1.5;
xp = grph.width/2 - xp;
yp = grph.height/2 - yp;
if(i==pointsArrayX.length-1){
gfx.graphics.moveTo(xp,yp);
}else{
gfx.graphics.lineTo(xp,yp);
}
grph.setPixel(xp,yp,0x000000);
grph.setPixel(xp,yp-1,0x000000);
grph.setPixel(xp,yp+1,0x000000);
grph.setPixel(xp-1,yp,0x000000);
grph.setPixel(xp+1,yp,0x000000);
i--;
}
}
}
}