1. Home
  2. Computing & Technology
  3. Animation

Dynamic Animation in Flash: Controlling the Drawing API with Equations

By , About.com Guide

4 of 6

Now comes the complicated part: the code. I’m going to start off by showing you the full block of code that accomplishes my drawing animation, and then break it down piece by piece:
onClipEvent(load) {
xstart=Math.random()*300;
ystart=Math.random()*300;
_root.createEmptyMovieClip ("twisty", 1);
_root.twisty.lineStyle (1, 0x5566FF, 40);
_root.twisty.moveTo (xstart, ystart);
}

onClipEvent(enterFrame){
if(xstart>0&&xstart<300&&ystart>0&&ystart<300) {
xstart=xstart*Math.atan(xstart)*Math.random();
ystart=ystart*Math.atan(ystart)*Math.random();
_root.twisty.curveTo(xstart+20*Math.random(), ystart-20*Math.random(), xstart, ystart);
}
else {
ystart=300*Math.random();
xstart=300*Math.random();
}
}
Explore Animation
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Dynamic Animation in Flash: Controlling the Drawing API with Equations

©2009 About.com, a part of The New York Times Company.

All rights reserved.