Skip to content

Instantly share code, notes, and snippets.

@fchikwekwe fchikwekwe/car.js
Last active Jun 17, 2019

Embed
What would you like to do?
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;
}
// Please help!! The car color is wrong. 😟
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
You can’t perform that action at this time.