Growing Homegrown Tentacles

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));
		}
	}
}

Trackback URL

4 Comments on "Growing Homegrown Tentacles"

  1. Ricki
    Kaolin Fire
    10/09/2009 at 12:35 Permalink

    Just wanted to share playing around with different radius values. I think ((_index – c) / LENGTH) * N is basically what Justin had. The one in the bottom left… is a lot cooler to watch than to see statically. ;)

    4 different formulas for radius. I don’t know why, these are awfully sexy to me right now.

  2. Ricki
    Ricki
    10/09/2009 at 18:49 Permalink

    Hi Kaolin

    That is great:) I like that you took screen shoots, I always forget to do that…
    The one in the bottom left looks like it is giving out strange radius values?
    Is it because the joints grow and then shrink, like a bubbly effect? That would be awesome, can I see it live?

    Thanks for sharing!

  3. Ricki
    Kaolin Fire
    11/09/2009 at 05:13 Permalink

    Yeah, it was a bubbly effect, kind of like those “snake” firework-ish things. I think it could be better fine-tuned than I did, but it was fun :)

    Do you use flashdevelop? I could send you the project most easily.

    swf here

    src zip

  4. Ricki
    Ricki
    22/09/2009 at 15:12 Permalink

    This is cool, You actually made the opposite of what I was going for:) I tried to make them
    look organic, these ones look like they are made of metal (which surely adds to the “evilness” of the tentacles).
    Im on OS X so sadly no FD for me, but I can peek in the source.

    Cheers!

Hi Stranger, leave a comment:

ALLOWED XHTML TAGS:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to Comments