Interactive animation: Creating Bubbles

Image by PistoCasero
This illustration has been generated randomly by the user interacting with computer code ActionScript 3.
Check the interactive animation here: www.gilbertomoya.es/creating_bubbles.html
How to create random size, color and alpha objects on a random position on the stage using ActionScript 3 language:
var yourObject:Sprite = new Sprite();
var yourRandomColor:ColorTransform = new ColorTransform();
var yourStageWidth:Number = stage.stageWidth;
var yourStageHeight:Number = stage.stageHeight;
var yourObjectBorderColor:ColorTransform = new ColorTransform();
stage.addEventListener(KeyboardEvent.KEY_DOWN, createRandomObjects);
function createRandomObjects(event:KeyboardEvent):void
{
var key = event.keyCode;
switch (key) {
case Keyboard.SPACE :
var i:Number = 0;
for(i = 0; i < 5; i++)
{
var yourObject:MovieClip = new MovieClip();
yourObject.name = i + "yourObject";
addChild(yourObject);
}
yourObject.x = (Math.round(Math.random()*yourStageWidth));
yourObject.y = (Math.round(Math.random()*yourStageHeight));
yourObject.transform.colorTransform = yourRandomColor;
yourObject.graphics.lineStyle(1, 0×0000);
yourObject.graphics.beginFill(0xFF0000, Math.random()); // random Alpha
yourObject.graphics.drawCircle((Math.round((Math.random()*120) – 60)),
(Math.round((Math.random()*120) – 60)),
(Math.round((Math.random()*120) – 60)));
yourRandomColor.redOffset = Math.round(Math.random() * 480) – 240;
yourRandomColor.greenOffset = Math.round(Math.random() * 480) – 240;
yourRandomColor.blueOffset = Math.round(Math.random() * 480) – 240;
yourObjectBorderColor.redOffset = Math.round(Math.random() * 240) – 120;
yourObjectBorderColor.greenOffset = Math.round(Math.random() * 240) – 120;
yourObjectBorderColor.blueOffset = Math.round(Math.random() * 240) – 120;
}
}
/*
If you have any question
feel free to ask me.
Don’t forget to check the animation here:
www.gilbertomoya.es/creating_bubbles.html
*/
Designed and programmed by: Gilberto Moya
.
Recommended Reading