Skip to content

Instantly share code, notes, and snippets.

@mimetaur
Created November 5, 2019 16:44
Show Gist options
  • Save mimetaur/2f6712e5ac0e6278d614cbc9c94e5dd0 to your computer and use it in GitHub Desktop.
Save mimetaur/2f6712e5ac0e6278d614cbc9c94e5dd0 to your computer and use it in GitHub Desktop.
Line of Squares Class
let myLineOfSquares;
function setup() {
createCanvas(400, 400);
myLineOfSquares = new LineOfSquares(height / 2, 9, 1.5, 140, 255, 140)
}
function draw() {
background(40);
myLineOfSquares.draw();
}
class LineOfSquares {
constructor(y, numSquares, spacer, colorR, colorG, colorB) {
this.y = y;
this.numSquares = numSquares;
this.spacer = spacer;
this.colorR = colorR;
this.colorG = colorG;
this.colorB = colorB;
this.size = width / numSquares;
}
draw() {
rectMode(CENTER);
fill(this.colorR, this.colorG, this.colorB);
for (let i = 0; i < this.numSquares; i++) {
rect(i * (this.size * this.spacer), height / 2, this.size, this.size)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment