Polar Distribution shapevent forked:1favorite:8lines:69license : MIT License modified : 2010-03-04 04:23:02 Embed Tweet package { import flash.display.*; import flash.events.*; import flash.text.*; [SWF(width = 500, height = 500)] public class PolarDist extends MovieClip { private var dotNum:int; private var dotRad:Number; private var txt:TextField; public function PolarDist(){ // init dotNum = 1000; dotRad = 0.5; x = y = 130 txt = TextField(addChild(new TextField())); txt.text = "Click the stage to refresh"; txt.autoSize = "left"; txt.x = txt.y = -120 txt.border = true; txt.background = true; txt.backgroundColor = 0xFFFFFF; // extra stuff to display what the functions can do stage.addEventListener(MouseEvent.CLICK, onDrawAll); onDrawAll(); // main part from the video } // private methods private function onDrawAll(evt:Event=null):void{ graphics.clear(); for (var i:int = 0; i<9; i++){ var m:Number; var rad:Number = 120; var xp:Number = i % 3 * rad var yp:Number = int(i / 3) * rad var type:int = int(Math.random() * 4); if (type == 0){ makeShape(xp, yp, rad-60, Math.random() , 1); }else if (type == 1){ makeShape(xp, yp, rad-60, 1, Math.random()); } else if (type == 2){ m = Math.random() * 2; makeShape(xp, yp, rad-Math.random()*120, m, m); } else if (type == 3){ m = Math.random() * 2; makeShape(xp, yp, rad-Math.random()*120, m, m/2); } } } private function makeShape(xp:Number, yp:Number, maxRad:Number = 100,m0:Number=1, m1:Number=1):void{ var polarX:Number; var polarY:Number; var radius:Number; graphics.lineStyle(0, 0); var theta:Number = Math.random() * Math.PI * 2; for (var i:int = 0; i<dotNum; i++){ radius = Math.random() * maxRad polarX = xp + radius * Math.cos(theta * m0); polarY = yp + radius * Math.sin(theta * m1); theta += 0.1; makeDot(polarX, polarY); } } private function makeDot(xp:Number, yp:Number, fillColor:uint = 0x000000):void{ graphics.beginFill(fillColor); graphics.drawCircle(xp, yp, dotRad); graphics.endFill(); } } } Code Fullscreen Preview Fullscreen developedAS qwty digitrick oreore nki2 carbonhci : 图形图像算法 zmaxlin : BitmapDatamath, chacker : particles BitmapData coordinates, graphics math, particles polar shapes, 图形图像 算法 type backgroundColor border background clear TextField drawCircle MouseEvent.CLICK addEventListener autoSize Math.random endFill beginFill MovieClip lineStyle Math.cos text addChild Math.sin Math.PI sort new page view favorite forked pv432 forked from: Polar Distributio.. homiho forked:0 favorite:1lines:69 (diff:2) tag: dot