Question: Add variable speed and assign number 1 Update carX values by speed. This will move the car to the right. Note that the wheels may

Add variable speed and assign number 1

Update carX values by speed. This will move the car to the right. Note that the wheels may not move. Add a command to move them. The entire car should move (out of the canvas).

Add a keyPressed() input function that includes code to reassign ALL variables of X to their original values as declared at the top. This will draw the car at the original location on keyPressed.

Run and press any key to make sure it works.

// This program will draw a 2D car with red body and semi transparent top // and two black wheels

int carX = 200; // car body int carY = 200; int wheelX = carX + 20; int wheelY = carY + 40; // both wheel Y are the same //setup void setup() { size(500,400); noStroke(); }// end of setup

void draw() { background(255); // main body fill(255,0,0); // in red rectMode(CORNER); rect(carX, carY, 120, 40); //Top fill(255,0,0,150); // in red and semi transparent rectMode(CORNER); rect(carX+20, carY-30, 80, 30); // on top of the body //two back wheels (circles) with half of the wheel overlaps the body fill(0); ellipseMode(CENTER); strokeWeight(2); stroke(255); ellipse(wheelX, wheelY, 30, 30); // left wheel ellipse(wheelX+100, wheelY, 30, 30); // right wheel

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!