Last active
September 9, 2018 18:26
-
-
Save eamonnmcevoy/d1be9539a3be1e7d22bb349d25b822a6 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
class Grid { | |
constructor(width, height, blockarea, margin, ctx) { | |
... | |
this.generateDataSet(); | |
} | |
generateDataSet() { | |
this.dataset = []; | |
for (let x = 0; x < width; x++) { | |
this.dataset[x] = [height]; | |
for (let y = 0; y < height; y++) { | |
this.setPoint({ x, y }, 'off'); | |
} | |
} | |
} | |
setPoint(point, state) { | |
this.dataset[point.x][point.y] = state; | |
} | |
getPoint(point) { | |
return this.dataset[point.x][point.y]; | |
} | |
render() { | |
... | |
const point = {x,y}; | |
const state = this.getPoint(point); | |
this.ctx.fillStyle = this.getFillStyle(state); | |
... | |
} | |
getFillStyle(state) { | |
switch(state) { | |
case 'on': | |
return 'green'; | |
case 'off': | |
return 'lightgrey'; | |
default: | |
return 'lightgrey'; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment