You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
994 B
JavaScript
34 lines
994 B
JavaScript
// https://stackoverflow.com/a/29676404
|
|
|
|
context = document.getElementById("canvas").getContext("2d");
|
|
defaultFillStyle = '#000';
|
|
|
|
function Rectangle(params) {
|
|
this.name = params.name;
|
|
this.x = params.x || 0;
|
|
this.y = params.y || 0;
|
|
this.width = params.width || 0;
|
|
this.height = params.height || 0;
|
|
this.fillStyle = params.fillStyle || "#FFFFFF";
|
|
this.strokeStyle = params.strokeStyle || "#000000";
|
|
this.lineWidth = params.lineWidth || 0;
|
|
}
|
|
|
|
Rectangle.prototype.draw = function () {
|
|
if (this.fillStyle) {
|
|
console.log('X: '+this.x+' Y: '+this.y);
|
|
console.log('W: '+this.width+' H: '+this.height);
|
|
}
|
|
if (this.fillStyle) {
|
|
context.fillStyle = this.fillStyle;
|
|
context.fillRect(this.x, this.y, this.width, this.height);
|
|
context.fillStyle = defaultFillStyle; // Reset back to default
|
|
}
|
|
if (this.strokeStyle && this.lineWidth) {
|
|
context.strokeStyle = this.strokeStyle;
|
|
context.lineWidth = this.lineWidth;
|
|
context.strokeRect(this.x, this.y, this.width, this.height);
|
|
}
|
|
}
|
|
|