Ricki »
11 August 2009 »
In ActionScript 3.0 , ActionScript3 , Flash »
This time the spores turned into a tree. It is by no means perfect, the branches does not move upwards with the stem as it should, were this a real orange colored scary spore tree.
This was just some “while Im doing nothing, let’s put whatever in the ‘fun’ category” but if anyone would like the code, throw me a comment and I’ll send it off. I is uncommented and messy.
Continue reading...
Tags: actionscript , algorithm , AS3 , Bitmap , fun , recursive , spore , tree
Ricki »
08 August 2009 »
In ActionScript 3.0 , ActionScript3 , Flash »
Well, I just got time to look into how to get the tentacles growing, i.e. start out small and have all the joints gradually increase in size, instead of the joint getting smaller all the time. (think I just tried to explain the definition of growing by using the definition of growing??).
Thanks again to Justin .
The spore Class turned out to look like this, it needs going over, but I was thinking on porting it to Processing and really get my tentacles on
The code:
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Point;
import flash.utils.setTimeout;
public class Spore extends Sprite
{
private static const LENGTH:int = 90;
private var _posX:Vector.;
private var _posY:Vector.;
private var angStep:Number;
private var posStep:Number;
private var curl:Number;
private var n:Number = 0;
private var a:Number = Math.random() * Math.PI * 2;
private var _index:int;
private var _g:Graphics;
public function Spore()
{
_posX = new Vector.( LENGTH, true );
_posY = new Vector.( LENGTH, true );
_g = graphics;
this.generate( range( 0.01, 0.05 ), range( 2.0, 3.0 ), range( 0.2, 1.0 ) );
}
public function generate( aStep:Number, pStep:Number, c:Number ):void
{
_index = 0;
angStep = aStep;
posStep = pStep;
curl = c;
var loc:Point = new Point( 0, 0 );
while( _index < LENGTH )
{
n += Math.random() * (angStep - -angStep) + -angStep;
n *= 0.9 + curl * 0.1;
a += n;
loc.x += Math.cos( a ) * posStep;
loc.y += Math.sin( a ) * posStep;
_posX[ _index ] = loc.x;
_posY[ _index ] = loc.y;
_index++;
}
_index = 0;
}
public function step():void
{
_g.clear();
_g.lineStyle( 0, 0x000000, 0.7 );
var c:int = 0;
var radius:Number;
while( c < _index )
{
radius = _index / c;
if( radius > 10 ) radius = 10;
_g.beginFill( 0xFF6600, 0.4 );
_g.drawCircle( _posX[ c ], _posY[ c ], radius );
_g.endFill();
c++;
}
_index++;
if( _index >= LENGTH )
{
this.generate( range( 0.01, 0.05 ), range( 2.0, 3.0 ), range( 0.2, 1.0 ) );
}
}
private function range(min:Number, max:Number = NaN):Number
{
if(isNaN(max)) {max = min; min = 0}
return min + (Math.random() * (max - min));
}
}
}
Continue reading...