19.3.15

Draw a Circle - Final

Test the program out now. If there are only two or three dots showing up on the screen, change the scaling number to 1 in the actions panel and then test it again. Here you have it. The program picks out the first spot, when angle is zero, and then from there it adds one degree every tenth of a second until it gets to 30 degrees. You can see the slight curve in the line, which indicates that if continued, the program will make a complete circle. I should've had you do this in the beginning, but I wanted the program to move faster:

timer= new Timer(100, 30);
timer.addEventListener(TimerEvent.TIMER, createCircle);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, createCircleStop);
timer.start()

Go to the timer declaration and change the number of iterations from 30 to 360. That should give us a full circle.

And you're done.

Oh, and one more thing. It appears that we have introduced a new error when changing the amount added to angle. Take a look at this (at the top):

var cirqy:Number = 220;
var cirqx:Number = 250;
var angle:uint = 0;
var scaling:uint = 1;

This code initializes the variable angle as a uint. What is a uint? An unsigned integer. What's that?
An unsigned integer is a whole number (no fractions allowed) that does not have a sign, meaning that it can never be negative. In previous iterations of the program, we could use a uint because we were just adding three every time. No negatives; no decimal numbers. Now we are dividing pi by 180, which means all of our numbers will not be whole numbers. So we need to change this variable type from uint to Number, much like cirqy and cirqx above it.

There. Now we're done xD

No comments:

Post a Comment