Created
November 13, 2012 11:48
-
-
Save AlexHannigan/4065383 to your computer and use it in GitHub Desktop.
250 semi-transparent circles, of random size, colour and position, drawn in AS3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.display.Sprite; | |
import flash.display.Graphics; | |
import flash.events.Event; | |
import flash.display.Stage; | |
public class Shapes extends Sprite { | |
private var myShapes:Array = new Array(); | |
private var myCircle:Sprite = new Sprite(); | |
private var myCircle2:Sprite = new Sprite(); | |
private var myCircle3:Sprite = new Sprite(); | |
private var myCircle4:Sprite = new Sprite(); | |
private var numShapes:int = 250; | |
private var maxXSpeed:int = 3; | |
private var maxYSpeed:int = 4; | |
public function Shapes() { | |
addEventListener(Event.ENTER_FRAME, makeThemMove); | |
//trace (stage.stageWidth); | |
//adding shapes to the array | |
for (var i:int = 0; i < numShapes; i++){ | |
var ranRad:int = Math.floor(Math.random()*40); | |
var ranCol = Math.random()*0xFFFFFF; | |
myShapes.push(drawCircle(ranRad, ranCol)); | |
} | |
//displaying shapes | |
for (i = 0; i < numShapes; i++){ | |
addChild(myShapes[i]); | |
var ranX:int = Math.floor(Math.random()*stage.stageWidth); | |
var ranY:int = Math.floor(Math.random()*stage.stageHeight); | |
myShapes[i].x = ranX; | |
myShapes[i].y = ranY; | |
} | |
} | |
private function drawCircle(rad: int, f:uint=0XCCCCCC, l:int=1, lCol:uint=0X000000):Sprite { | |
//drawing circle inside the graphics object | |
var temp:Sprite = new Sprite(); | |
var gr:Graphics = temp.graphics; | |
gr.lineStyle(l, lCol, 0.5); | |
gr.beginFill(f, 0.5); | |
gr.drawCircle(0,0,rad); | |
gr.endFill(); | |
return temp; | |
} | |
private function makeThemMove(e:Event){ | |
//var ranXSpeed:int = Math.floor(Math.random() * (maxXSpeed * 2)) - maxXSpeed; | |
//var ranYSpeed:int = Math.floor(Math.random() * (maxYSpeed * 2)) - maxYSpeed; | |
//trace("I am the move function."); | |
for (var i:int = 0; i < numShapes; i++){ | |
addChild(myShapes[i]); | |
//myShapes[i].x -= ranXSpeed; | |
//myShapes[i].y += ranYSpeed; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment