xxxxxxxxxx
60
// Emoji Race
// Three objects
// they move on their own - left to right
// there seems to be some randomness in the movement
// Race Track with start and end line 👍
// We need to annouce the winner!
let blancX = 25;
let rougeX = 25;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(252,186, 3);
// start line
stroke(0,0,0);
strokeWeight(100);
line(0,0,0,400);
// end line
noStroke();
fill(100,225,20);
rect(550, 0, 50, 400);
// Blanc
fill(255,255,255);
circle(blancX,200,50);
blancX = blancX + random(1, 5);
textSize(20);
if(blancX > 550){
text("Blanc wins the race!", width/2, 200);
noLoop();
}
// Rouge
fill(255,50,100);
circle(rougeX,100,50);
rougeX = rougeX + random(1,5);
textSize(20);
if(rougeX > 550){
text("Rouge wins the race!", width/2, 200);
noLoop();
}
}
/* Challenges
1. Add a third participant.
2. Change the participants from circles to triangles.
3. Change the participants from shapes to emojis. see the Project Page.
Optional
1. Make the race run vertically.
2. Add obstacles that decrease the velocity of the racer.
3. Add power ups that increase the velocity of the racer.
*/