1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
| package com.arcticcode.greenFlames.graphics.abstract
{
import com.arcticcode.greenFlames.geom.LWPoint;
import com.arcticcode.greenFlames.graphics.Curves.QuadBez;
import flash.display.Sprite;
public class Amoeba extends Sprite
{
private var _w:Number;
private var _h:Number;
private var _vx:Number=0;
private var _vy:Number=0;
private var points:Array;
private var bounds:Array;
private var vpoints:Array;
private var i:uint = 0;
private var friction:Number = 0.95;
private var _cI:Object = {c1:0,c2:0xFFFFFF,t:4,f:0};
public function get vx():Number
{
return _vx;
}
public function set vx(value:Number):void
{
_vx = value;
}
public function get vy():Number
{
return _vy;
}
public function set vy(value:Number):void
{
_vy = value;
}
public function Amoeba(width:Number=100,height:Number=100,fillColour:uint=0xFFFFFF, lineColour:uint=0x000000, lineThickness:Number=4)
{
_w = width;
_h = height;
_cI.c1 = lineColour;
_cI.t = lineThickness;
_cI.f = fillColour;
init();
}
private function init():void
{
points = new Array();
points[0] = new LWPoint(Math.random()*_w/2,Math.random()*-_h/2);
points[1] = new LWPoint(Math.random()*_w/2,Math.random()*_h/2);
points[2] = new LWPoint(Math.random()*-_w/2,Math.random()*_h/2);
points[3] = new LWPoint(Math.random()*-_w/2,Math.random()*-_h/2);
vpoints = new Array();
vpoints[0] = new LWPoint(0,0);
vpoints[1] = new LWPoint(0,0);
vpoints[2] = new LWPoint(0,0);
vpoints[3] = new LWPoint(0,0);
bounds = new Array();
bounds[0] = {min: new LWPoint(0,-_w/2), max:new LWPoint(_w/2,0)};
bounds[1] = {min: new LWPoint(0,0), max:new LWPoint(_w/2,_h/2)};
bounds[2] = {min: new LWPoint(-_w/2,0), max:new LWPoint(0,_h/2)};
bounds[3] = {min: new LWPoint(-_w/2,-_h/2), max:new LWPoint(0,0)};
}
public function draw():void
{
for(i=0;i<points.length;i++)
{
var _a:LWPoint = vpoints[i];
_a.x += Math.random() * 0.2 - 0.1;
_a.y += Math.random() * 0.2 - 0.1;
_a.x *= friction;
_a.y *= friction;
var _b:LWPoint = points[i];
checkBounds(bounds[i].min.x,bounds[i].max.x,bounds[i].min.y,bounds[i].max.y,_b,_a);
_b.x += _a.x;
_b.y += _a.y;
QuadBez.draw(this.graphics,points,{c1:_cI.c1,c2:_cI.c2,la:1,t:_cI.t,f:_cI.f,fa:1},true);
}
}
private function checkBounds(minX:Number,maxX:Number,minY:Number,maxY:Number,cp:LWPoint,vp:LWPoint):void
{
if(cp.x < minX)
{
vp.x *= -1;
}
else if(cp.x > maxX)
{
vp.x *= -1;
}
if(cp.y < minY)
{
vp.y *= -1;
}
else if(cp.y > maxY)
{
vp.y *= -1;
}
}
}
} |