Return to Snippet

Revision: 20643
at November 20, 2009 12:24 by sottenad

Initial Code
Steve Ottenad - Nov 20, 2009 - AS3 Circle Drawing/ Clock Wipe Snippet

This Snippet works by drawing and then fading a succession of small triangles to make a circle/polygon.
It relies on TweenMax, a free tweening engine found at

centerX        (Number) - The X coordinate of the center of the circle to be drawn.
centerY        (Number) - The Y coordinate of the center of the circle to be drawn.
radius         (Number) - The desired radius of the circle.
increment      (Number) - The amount of degrees you want to add each time a wedge is drawn. If increment = 2, then 180 wedges will be drawn (360/2). If increment = 36, then 10 wedges will be drawn (360/10).
timeIncrement  (Number) - The amount of milliseconds between each wedge being drawn.
Container   (MovieClip) - The containing element.

Sample Usage: drawCircle(centerX, centerY , radius, increment , timeIncrement, container);

function drawCircle(centerX:Number, centerY:Number, radius:Number, increment:Number, timeIncrement:Number, container:MovieClip){

//Define Variables
var radius:Number = radius;
var iniX:Number = centerX;
var iniY:Number = centerY;
var increment:Number = increment;
var totalDegrees:Number = 0;
var degInRad:Number;
var degInRad1:Number;
outline.visible = true;

//Create Timer
var maskTimer:Timer = new Timer(timeIncrement);
maskTimer.addEventListener(TimerEvent.TIMER, drawSegment);

//Start Drawing, iniY);
	function drawSegment(e:TimerEvent){
		if(totalDegrees < 362 && keepLoading){
			//Convert to Radians
			degInRad = totalDegrees * (Math.PI / 180);
			degInRad1 = Number(totalDegrees+increment) * (Math.PI / 180);
			//Find X,Y
			var x1:Number = radius * Math.cos( degInRad ) + iniX;
			var y1:Number = radius * Math.sin( degInRad ) + iniY;
			var x2:Number = radius * Math.cos( degInRad1 ) + iniX;
			var y2:Number = radius * Math.sin( degInRad1 ) + iniY;
			var wedge:Sprite = new Sprite();
			wedge.alpha = 0;
			//Define Color;, iniY);, y1);, y2);, iniY);
			//Fade In (Time == 1 in this example (wedge, 1, {alpha:1});
			totalDegrees+= increment

Initial URL

Initial Description
This is a snippet that will animate in a circle in a clockwise fashion based on the parameters the function is passed. It can be used to create a circular or clock wipe when used as a mask.

Initial Title
Create a fading circular mask

Initial Tags
actionscript, animation, 3

Initial Language
ActionScript 3