Skip to content

Instantly share code, notes, and snippets.

@fchikwekwe
Last active July 10, 2019 22:57
Show Gist options
  • Save fchikwekwe/bdaa606a3057359fb433193bd93c7732 to your computer and use it in GitHub Desktop.
Save fchikwekwe/bdaa606a3057359fb433193bd93c7732 to your computer and use it in GitHub Desktop.
/*
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