Actionscript:

var circle:Shape = Shape(addChild(new Shape));

with(circle.graphics) beginFill(0x000000), drawCircle(0,0,5);


var bezierPoint:Point = new Point();

function bezier(a:Number, x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number):void {

var b:Number =1a;

var pre1:Number=a*a;

var pre2:Number=2*a*b;

var pre3:Number=b*b;

bezierPoint.x = pre1*x1 + pre2*x2 + pre3*x3;

bezierPoint.y = pre1*y1 + pre2*y2 + pre3*y3;

}


var inc:Number = 0;

var theta:Number = 0;


addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {


graphics.clear();

graphics.lineStyle(0,0xFF0000);

graphics.moveTo(200,200);

graphics.curveTo(mouseX, mouseY, 400, 200);


theta+= .05;

inc = .5 + .5*Math.sin(theta);


bezier(inc, 200, 200, mouseX, mouseY, 400, 200);

circle.x = bezierPoint.x;

circle.y = bezierPoint.y;

}
The above animates a circle along a quadratic bezier curve. This snippet was written in response to a question spurned by some of the recent bezier posts. I used Math.sin() to animate the circle but you could just as easily use modulus... simply replace lines 2526 with the following:
Actionscript:

inc += .03;

inc %= 1;
3 Comments
Hi Zevan,
Just wanted to say thank you because this snippet is exactly what I need for a university project.
Greatly appreciated,
YC
Hey YuChung,
Glad to hear you’ll be able to make use of this snippet. If you have any questions or problems related to it… feel free to post them here… and I’ll help if I can
Hi. This is a really cool snippet. I am quite new to AS3, but I am trying to do something quite advanced and am a bit lost. I am trying to animate an electron flying somewhat randomly around a point (the nucleus). I don’t want the animation to be fixed on a predefined Bezier curve, but would rather continually add new points to the Bezier while removing points which the electron has already passed. By adding the points randomly I hope to get something that looks like nice, random animation. Do you know if this is possible?
Currently I am just animating the electron to a new random point within a certain radius of the nucleus, once the electron reaches the new point, I just add another and it flies there, etc. The problem with this is that the animation ends up looking very angular, like the electron is just turning on a dime.
Any input would be much appreciated!