Last active
October 13, 2016 17:18
-
-
Save AlexTiTanium/c432a8b0430778e9e4aa1106dddd248e to your computer and use it in GitHub Desktop.
debug draw devkit
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
this.render = function(ctx) { | |
ctx.save(); | |
var line = this.layer.collisionLine; | |
var l = this.layer.l; | |
var c = this.layer.c; | |
var px = this.layer.pointX; | |
var py = this.layer.pointY; | |
var cpx = this.cpointX; | |
var cpy = this.cpointY; | |
if (line) { | |
this.drawLine(ctx, line.x1, line.y1, line.x2, line.y2, "red"); | |
} | |
if (l) { | |
this.drawLine(ctx, l.x1, l.y1, l.x2, l.y2, "green"); | |
} | |
if (c) { | |
ctx.fillStyle = "blue"; // locs cercle | |
var r = Math.sqrt(c.r); | |
var w = r * 2; | |
var wh = w / 2 ; | |
ctx.fillRect(c.x-wh, c.y-wh, w, w); | |
} | |
ctx.restore(); | |
}; | |
this.drawLine = function(ctx, x1, y1, x2, y2, color) { | |
var dx = x2 - x1; | |
var dy = y2 - y1; | |
ctx.fillStyle = color || "red"; | |
var start = x1; | |
var end = x2; | |
if (dx < 0) { | |
start = x2; | |
end = x1; | |
} | |
for (var x = start; x < end; x++) { | |
var y = y1 + dy * (x - x1) / dx; | |
ctx.fillRect(x, y, 5, 5); | |
} | |
}; |
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
this.render = function(ctx) { | |
ctx.save(); | |
var l = this.layer.l; | |
var b = this.layer.b; | |
var li = this.layer.li; | |
var line = this.layer.collisionLine; | |
if (l) { | |
this.drawCircle(ctx, l[0], l[1], l[2], "green"); | |
} | |
if (b) { | |
this.drawCircle(ctx, b[0], b[1], b[2], "blue"); | |
} | |
if (li) { | |
this.drawLine(ctx, li[0], li[1], li[2], li[3], "red"); | |
} | |
if (line) { | |
this.drawLine(ctx, line.x1, line.y1, line.x2, line.y2, "red"); | |
} | |
ctx.restore(); | |
}; | |
this.drawCircle = function (ctx, x, y, radius, color) { | |
ctx.strokeStyle = color || 'green'; | |
ctx.lineWidth = 3; | |
ctx.beginPath(); | |
ctx.arc(x, y, radius, 0, Math.PI * 2); | |
ctx.fillStyle = color || 'green'; | |
ctx.fill(); | |
ctx.stroke(); | |
} | |
this.drawLine = function(ctx, x1, y1, x2, y2, color) { | |
ctx.strokeStyle = color || red; | |
ctx.lineWidth = 3; | |
ctx.beginPath(); | |
ctx.moveTo(x1,y1); | |
ctx.lineTo(x2, y2); | |
ctx.stroke(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment