Created
May 26, 2020 13:01
-
-
Save galElmalah/43c6bf1ae60edbce4b9274b2c4ab8fab to your computer and use it in GitHub Desktop.
visualisation for a single array member
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
function ArrayMember(x, y, width, height, color = "gray") { | |
this.x = x; | |
this.y = y; | |
this.width = width; | |
this.height = height; | |
this.color = color; | |
this.draw = () => { | |
ctx.fillStyle = this.color; | |
ctx.fillRect(this.x, this.y, this.width, this.height); | |
}; | |
this.resetColor = () => this.setColor("gray"); | |
this.setColor = (color) => { | |
if (!this.isSorted()) { | |
this.color = color; | |
} | |
}; | |
this.isSorted = () => this.color === "green"; | |
this.sorted = () => (this.color = "green"); | |
this.setValue = (v, color) => { | |
if (!this.isSorted()) { | |
this.height = v; | |
this.setColor(color); | |
} | |
}; | |
this.getValue = (v) => this.height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment