for (initial-statement; condition; iteration-statement) body-statement; // This can be many statements inside { }Often for loops are used for repetition when there is a counter that is to be incremented or decremented each time through the loop. In that case, the loop takes the form:
for (i = start_value; i < end_value; i++) body-statement;In this lab you will:
#include "Random.h" // random longs and doubles #include "Delay.h" // delay & pause tools
for (x = 35; x < 365; x++){ PaintCircle(x, y, radius); Delay(1); // waits one sixtieth of a second // this function is in Delay.h }We create the illusion of motion by drawing the ball in different positions. If the drawing happens to slowly or too quickly, the illusion is spoiled.
Comment out the statement Delay(1); and see what happens.
Now write the code to move the ball around the rest of the track. Change x when it is moving horizontally, Change y when it is moving vertically.
Note that after the first loop x has the right value for the second loop.
(1) Move the ball down the right side
(2) Move the ball back across the bottom
(3) Move the ball up the left side
Use the statement:
SetForeColor(red, green, blue);where 0 <= red, green, blue <= 255. When working with light, yellow is an even mix of red and green.
Make spots around the track
(5)
// Copy the loops from FixedTrack() // then change the iteration-statement in each loop // to make the centers of the balls 30 pixels apart.(6) // Play the System Beep sound
The statement SysBeep(1); will play whatever system beep is currently set. The number 1 is leftover from the days when the system beep was a constant note and you had to tell how many ticks to hold it for. Now, the value doesn't matter but there must be a number there.
(7) // Set the drawing color back to black
The margin and the radius are set for you.
(8) Add the inner square to finish the track
Make sure that there are width pixels between the inner and outer tracks.
Roll a ball around the track
(9) // Declare x and y and set y to the middle height of the top part of the track. Express y in terms of margin and radius.
(10) // Write 4 for loops that will roll the ball around the track leaving a black trace. Your initial-statement and condition must depend on "margin" and "radius" Where x starts and ends depends on margin and radius.
(11)// In each loop, add a statement before the PaintCircle statement that will make the drawing color depend on x and y. Remember that each of the red, green, and blue values should be between 0 and 255.
x + y is a simple function that depends on x and y but it must be scaled (multiplied or divided by a constant) to give values that are between 0 and 255.
You don't have to use the same color scheme as in the LoopsLabSolution but make it change as smoothly as possible. How smooth it can change depends on the color available on your machine, i.e. how much VRAM your machine has and how much it is set to use.