Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions