Watch Fun Programing [video 33]
Write a program that creates three cars that race across the screen. The speed of each of the cars is chosen randomly at the beginning of the program.
Here’s a program skeleton you can use:
float car1_speed;
float car2_speed;
float car3_speed;
float norm_x = 0;
void setup()
{
size(600,400);
car1_speed =
car2_speed =
car3_speed =
}
void draw()
{
background(#FCFAC2);
draw_car(norm_x * car1_speed,100,#FF0000); // red car
draw_car(norm_x * car2_speed,200,#00FF00); // blue car
draw_car(norm_x * car3_speed,300,#0000FF); // green car
norm_x = norm_x + 1;;
}
void draw_car(float x,float y,color carcolor)
{
// Draw a car at location(x,y)
}
For extra fun, make your car super fancy, have the program display a text count down to start the race, announce the winner etc.
Upload your program to Open Processing
Show a mentor, mark the board and claim a prize
.