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();
}
}
The first thing that the script does is check to make sure that the x and y coordinates in our variables havent ranged outside of the visible stage area; only then does it start to do the really random stuff.
What Ive done is create equations where a new value for each variable is created every time the frame cycles, by taking the previous value and multiplying it by the arctangent of itself (using Math.atan) and then times a number generated by Math.random. I just used arctangent because I liked the way it made the drawing move, but there are a number of Math.function functions that you can use to adjust the behavior, control it, and create more complex equations for more deliberated drawing.
With the new values for xstart and ystart created, the script then uses the drawing API to draw a curve starting at the current (x,y) coordinate and going to coordinates at (xstart,ystart) with curve towards points defined as the original x or y point plus twenty and times a number generated by Math.random. Again, these are just mathematical functions I made up just to see an effect.
Theres also an else statement that resets the values of xstart and ystart should they exceed the stage area.


