PDA

View Full Version : Stars


TheCanadian
01-03-2007, 02:59 AM
A function for drawing stars:

function drawStar(mc:MovieClip, p:Number, er:Number, ir:Number, x:Number, y:Number, ps:Number):Void {
if(ps == undefined) {
if(p % 2) {
ps = -Math.PI / 2;
} else if((p - 6) % 4 == 0) {
ps = 0;
} else {
ps = Math.PI / p;
}
}
var i:Number = 2 * Math.PI / p;
var j:Number = i / 2;
var ts:Number;
for(var t:Number = 0; t < 2 * Math.PI; t += i) {
ts = t - ps;
mc[t ? "lineTo" : "moveTo"](x + Math.cos(ts) * er, y + Math.sin(ts) * er);
mc.lineTo(x + Math.cos(ts + j) * ir, y + Math.sin(ts + j) * ir);
}
mc.lineTo(x + Math.cos(ps) * er, y + Math.sin(-ps) * er)
}
//drawStar(mc:MovieClip, p:Number, er:Number, ir:Number, x:Number, y:Number, [ps:Number]):Void
//mc - The movie clip in which to draw the star
//p - The number of points on the star
//er - The radius of the external circumscribed circle
//ir - The radius if the internal circumscribed circle
//x - The x centre of the circumscribed circle
//y - the y centre of the circumscribed circle
//ps - The phase shift or angular offset of the polygons' vertices (ie the rotation)
Example (http://img54.imageshack.us/my.php?image=starmc4.swf)

Pattt
01-03-2007, 08:04 AM
Very nice. :) And it's fast, even with 360 points. :D

tomkenn
01-08-2007, 05:28 PM
I would like information on how the data from the NumericSteppers is transfered to the movie clip that is a part of the drawStar function in your drawing Stars example. Thank you.