code on 2008-12-19
package {
[SWF(width="465", height="465", backgroundColor="#242424", frameRate="30")]
dynamic public class Fern extends MovieClip {
public function Fern() { screen = this; container = this;
//---------------------------------------------- ここから >>
var canvas:BitmapData = new BitmapData(465, 465, true, 0xFF242424);
addChildAt(this.bitmap = new Bitmap(canvas), 0);
var a:Vector.<Number> = Vector.<Number>([ 0, 0.85, 0.20, -0.15]);
var b:Vector.<Number> = Vector.<Number>([ 0, 0.04, -0.26, 0.28]);
var c:Vector.<Number> = Vector.<Number>([ 0, -0.04, 0.23, 0.26]);
var d:Vector.<Number> = Vector.<Number>([0.16, 0.85, 0.22, 0.24]);
var e:Vector.<Number> = Vector.<Number>([ 0, 0, 0, 0]);
var f:Vector.<Number> = Vector.<Number>([ 0, 1.60, 1.60, 0.44]);
var N:int = 4;
var M:int = 25 * N;
var i:int, j:int, k:int, r:int;
var x:Number, y:Number, s:Number, t:Number;
var ip:Vector.<int> = new Vector.<int>(N);
var table:Vector.<int> = new Vector.<int>(M);
var p:Vector.<Number> = new Vector.<Number>(N);
s = 0;
for (i = 0; i < N; i++)
{
p[i] = abs(a[i] * d[i] - b[i] * c[i]);
s += p[i];
ip[i] = i;
}
for (i = 0; i < N-1; i++)
{
k = i;
for (j = i + 1; j < N; j++ )
if (p[j] < p[k]) k = j;
t = p[i]; p[i] = p[k]; p[k] = t;
r = ip[i]; ip[i] = ip[k]; ip[k] = r;
}
r = M;
for (i = 0; i < N; i++)
{
k = (r * p[i] / s + 0.5) >> 0;
s -= p[i];
do
{
table[--r] = ip[i];
}
while (--k > 0);
}
x = y = 0;
for (i = 0; i < 30000; i++)
{
j = table[random(0xFFFFFFFF) / (0xFFFFFFFF / M + 1) >> 0];
t = a[j] * x + b[j] * y + e[j];
y = c[j] * x + d[j] * y + f[j];
x = t;
if (i >= 10)
{
canvas.setPixel(200 + x * 40, 440 - y * 40, 0xFFFFFF);
}
}
//---------------------------------------------- ここまで
} // end of constructor
public function set loop (value:Function) : void
{
if (value is Function)
{
_loop = function(e:Event):void
{
value.call(screen, null);
}
addEventListener("enterFrame", _loop);
}
else
{
removeEventListener("enterFrame", _loop);
}
};
public function set click (value:Function) : void
{
if (value is Function)
{
_click = function(e:Event):void
{
value.call(screen, null);
}
stage.addEventListener("click", _click);
}
else
{
removeEventListener("click", _click);
}
};
private var _loop:Function;
private var _click:Function;
} // end of class
import flash.display.*;
import flash.geom.*;
import flash.filters.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import caurina.transitions.Tweener;
import caurina.transitions.properties.*;
{ // initialize
ColorShortcuts.init();
FilterShortcuts.init();
}
} // end of package
var screen:*;
var container:*;
const PI:Number = 3.141592653589793;
const PI2:Number = 6.283185307179586;
const PI_HALF:Number = 1.5707963267948966;
const PI_QUOT:Number = 0.7853981633974483;
const PI_RADIAN:Number = 0.017453292519943295;
const PI_DEGREE:Number = 57.29577951308232;
const E:Number = 2.71828182845905;
function abs (v:Number):Number { if (v < 0) return -v; return v; }
function cos (v:Number):Number { return Math.cos(v); }
function sin (v:Number):Number { return Math.sin(v); }
function tan (v:Number):Number { return Math.tan(v); }
function log (v:Number):Number { return Math.log(v); }
function sqrt (v:Number):Number { return Math.sqrt(v); }
function pow (v:Number, n:Number):Number { return Math.pow(v, n); }
function atan2 (y:Number, x:Number):Number { return Math.atan2(y, x); }
function random (max:Number=1, min:Number=0):Number { return Math.random() * (max - min) + min; }
function rgb (r:uint, g:uint, b:uint, a:Number = 0):uint { return a * 0xFF << 24 | r << 16 | g << 8 | b << 0; }
function hsl (h:Number, s:Number, l:Number, a:Number = 0.0):uint { var r:Number = 0, g:Number = 0, b:Number = 0, cmin:Number, cmax:Number; if (s < 0) s = 0; if (s > 1) s = 1; if (l < 0) l = 0; if (l > 1) l = 1; h = h % 360; if (h < 0) h = h + 360; if (l <= 0.5) { cmin = l * ( 1 - s ); cmax = 2 * l - cmin; } else { cmax = l * ( 1 - s ) + s; cmin = 2 * l - cmax; }; r = _h2v(h + 120, cmin, cmax) * 0xFF; g = _h2v(h, cmin, cmax) * 0xFF; b = _h2v(h - 120, cmin, cmax) * 0xFF; a *= 0xFF; return a << 24 | r << 16 | g << 8 | b << 0; }
function _h2v (h:Number, min:Number, max:Number):Number { h = h % 360; if (h < 0) h = h + 360; if (h < 60) return min + (max - min) * h / 60; if (h >= 60 && h < 180) return max; if (h >= 180 && h < 240) return min + (max - min) * (240 - h) / 60; return min; }