[Xerte] AS2 draw functions

Julian Tenney Julian.Tenney at nottingham.ac.uk
Mon Feb 22 13:53:18 GMT 2010


Why the need for terseness? This is what Xerte has in the engine, and it
draws proper circles, unlike some other circle drawing functions. You
could probably make the function more terse if you alwaays draw at 0,0
and always have xRadius = yRadius (as this draw ovals too)

Are you aware of prototype51? There are a ton of useful functions on
there: http://proto.layer51.com/


MovieClip.prototype.drawOval = function(x, y, radius, yRadius) {
	// ==============
	// mc.drawOval() - by Ric Ewing (ric at formequalsfunction.com) -
version 1.1 - 4.7.2002
	// 
	// x, y = center of oval
	// radius = radius of oval. If [optional] yRadius is defined, r
is the x radius.
	// yRadius = [optional] y radius of oval.
	// ==============
	if (arguments.length<3) {
		return;
	}
	// init variables  
	var theta, xrCtrl, yrCtrl, angle, angleMid, px, py, cx, cy;
	// if only yRadius is undefined, yRadius = radius
	if (yRadius == undefined) {
		yRadius = radius;
	}
	// covert 45 degrees to radians for our calculations  
	theta = Math.PI/4;
	// calculate the distance for the control point
	xrCtrl = radius/Math.cos(theta/2);
	yrCtrl = yRadius/Math.cos(theta/2);
	// start on the right side of the circle
	angle = 0;
	this.moveTo(x+radius, y);
	// this loop draws the circle in 8 segments
	for (var i = 0; i<8; i++) {
		// increment our angles
		angle += theta;
		angleMid = angle-(theta/2);
		// calculate our control point
		cx = x+Math.cos(angleMid)*xrCtrl;
		cy = y+Math.sin(angleMid)*yrCtrl;
		// calculate our end point
		px = x+Math.cos(angle)*radius;
		py = y+Math.sin(angle)*yRadius;
		// draw the circle segment
		this.curveTo(cx, cy, px, py);
	}
};

-----Original Message-----
From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Dave Burnett
Sent: Monday, February 22, 2010 1:48 PM
To: Xerte list
Subject: [Xerte] AS2 draw functions


Anyone have a terse method of drawing a circle in AS2?

Cheers,
Dave
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/________________________
_______________________
Xerte mailing list
Xerte at lists.nottingham.ac.uk
http://lists.nottingham.ac.uk/mailman/listinfo/xerte


More information about the Xerte mailing list