Skip to content

Instantly share code, notes, and snippets.

@galElmalah
Created May 26, 2020 13:01
Show Gist options
  • Save galElmalah/43c6bf1ae60edbce4b9274b2c4ab8fab to your computer and use it in GitHub Desktop.
Save galElmalah/43c6bf1ae60edbce4b9274b2c4ab8fab to your computer and use it in GitHub Desktop.
visualisation for a single array member
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