Last active
July 10, 2019 22:57
-
-
Save fchikwekwe/bdaa606a3057359fb433193bd93c7732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I am writing a class called GenericCar and trying to create a new car object | |
that should be blue. I got stuck when trying to pass in the car color, but | |
I'm not sure how to solve the issue. I tried looking at the p5.js reference | |
section for help, but I'm not sure how to use it yet. | |
*/ | |
function setup(){ | |
createCanvas(400, 400); | |
} | |
function draw(){ | |
var fastCar = new GenericCar(100, 55, "blueu"); | |
fastCar.drawCar() | |
} | |
class GenericCar { | |
constructor(x, y, color){ | |
this.x = x; | |
this.y = y; | |
this.color = color; | |
} | |
drawCar(){ | |
// adapted from https://editor.p5js.org/samchasan/sketches/r15Tt312W | |
// car body | |
fill(this.color); | |
rectMode(CORNER); | |
rect(this.x, this.y, 100, 50); | |
// car wheels | |
fill(0); | |
ellipse(this.x + 20, this.y + 45, 40, 40); | |
ellipse(this.x + 80, this.y + 45, 40, 40); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment