Quick Links

Education Edu

Simulations Sims

Math Tools Math

Games Games

Generative ArtArt

Actinoscript Prog

Farmville Farm

 

 


Dandelions

Dandelions

Click the above-left picture of Dandelions applet to start the application full screen.

 
 

Dandelions

Video Conferencing Nifties

I discovered that my laptop's video conferencing software had some sort of overlay of dandelion seeds blowing in the breeze and I tried to create my own. Mine doesn't look anything like theirs, but I like the result. Of course, it is yet another particle system. Clicking restores the seeds to the dandelion stem. It exists entirely in the 1st frame's actionscript, no symbols, so a nice small 3k.

Result

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Code

Here's what the frame 1 actonscript 3 looks like.

var numSeeds:Number = 50; var seeds:Array = [] var seedLength:Number = 20; var stemLength:Number = 30; var fluffLength:Number = 30; var seedColor:Number = 0xFFFFFF; var bulbR:Number = 20; function reset(e:MouseEvent):void {doReset();} var dandelion:MovieClip = new MovieClip(); addChild(dandelion); dandelion.graphics.beginFill(0xFFFFFF,0.75); dandelion.graphics.drawCircle(stage.stageWidth/2, stage.stageHeight/2, 25); dandelion.graphics.endFill(); dandelion.graphics.lineStyle(5, 0xFFFFFF,1); //seedColor, 1); dandelion.graphics.moveTo(272,222); dandelion.graphics.curveTo(267,250, 241,318); dandelion.graphics.curveTo(227,360, 221,398); var dTh:Number = 360/numSeeds; // angle of protrusion from bulb var d2r:Number = Math.PI/180; // constant for quick conversion to radians var matrix:Matrix = new Matrix(); matrix.createGradientBox( fluffLength, fluffLength, 0, -fluffLength/2, -fluffLength/2); var bf:BlurFilter = new BlurFilter(); var tsLogo:MovieClip = new MovieClip(); addChild(tsLogo); var ts_tf:TextField = new TextField(); var ts_tff:TextFormat = new TextFormat(); ts_tff.color = 0xFFFFFF; ts_tff.font = "Verdana"; ts_tff.size = 36; ts_tf.width = 400; ts_tf.text = "touchspin.com"; ts_tf.setTextFormat(ts_tff); tsLogo.x = stage.stageWidth/2; tsLogo.y = stage.stageHeight - 64; tsLogo.addChild(ts_tf); bf.blurX = bf.blurY = 7; tsLogo.filters = [bf]; function doReset():void { for(var jt:Number=dandelion.numChildren-1; jt>=0; jt--) { dandelion.removeChildAt(jt); } for(var it:Number = 0; it<numSeeds; it++) { var drawLength:Number; var seed:MovieClip = new MovieClip(); seeds.push(seed); dandelion.addChild(seeds[it]); seeds[it].x = stage.stageWidth/2; seeds[it].y = stage.stageHeight/2; var myAngle:Number = it*dTh*d2r; var iX:Number = bulbR*Math.cos(myAngle); // initial X var iY:Number = bulbR*Math.sin(myAngle); // initial Y seeds[it].graphics.lineStyle(2, seedColor, 1); seeds[it].graphics.moveTo(iX, iY); drawLength = seedLength; seeds[it].graphics.lineTo(iX+drawLength*Math.cos(myAngle),iY+drawLength*Math.sin(myAngle)); seeds[it].graphics.lineStyle(1, seedColor, 1); drawLength += stemLength; seeds[it].graphics.lineTo(iX+drawLength*Math.cos(myAngle),iY+drawLength*Math.sin(myAngle)); seeds[it].graphics.lineStyle(0, seedColor, 0); var fluff:MovieClip = new MovieClip(); seeds[it].addChild(fluff); fluff.graphics.beginGradientFill( "radial", [0xFFFFFF, 0xFFFFFF], [0.75, .25], [0, 255], matrix, "pad", "rgb", 0); fluff.x = iX+drawLength*Math.cos(myAngle); fluff.y = iY+drawLength*Math.sin(myAngle); fluff.graphics.drawCircle(0, 0, fluffLength/2); seeds[it].dx = 1+Math.random(); seeds[it].dy = (Math.random()-0.5)/2; seeds[it].dr = 2*Math.random()-1; } } doReset(); stage.addEventListener(Event.ENTER_FRAME, moveSeeds); stage.addEventListener(MouseEvent.CLICK, reset); dandelion.x = -200; function moveSeeds(e:Event):void { var normX:Number; for(var it:Number = 0; it<seeds.length; it++) { normX = Math.abs(seeds[it].x)/stage.stageWidth; seeds[it].x += seeds[it].dx*seeds[it].scaleX; seeds[it].y += seeds[it].dy; seeds[it].rotation += seeds[it].dr; seeds[it].alpha = 1-normX; bf.blurX = bf.blurY = 5*normX; seeds[it].filters = [bf]; seeds[it].scaleX = seeds[it].scaleY = (10*normX+1)/8; if ( (seeds[it].x > stage.stageWidth) || (seeds[it].alpha < 0.05) ) { seeds[it].scaleX = seeds[it].scaleY = 1/8; seeds[it].x=-seeds[it].height-dandelion.x; seeds[it].y=stage.stageHeight/2; seeds[it].alpha=1; bf.blurX = bf.blurY = 0; } } }