Created
November 5, 2019 16:44
-
-
Save mimetaur/2f6712e5ac0e6278d614cbc9c94e5dd0 to your computer and use it in GitHub Desktop.
Line of Squares Class
This file contains hidden or 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
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