Add f***ing max bracket size!
This commit is contained in:
parent
04639f3603
commit
4497248615
1 changed files with 17 additions and 2 deletions
19
index.html
19
index.html
|
@ -26,6 +26,9 @@ var _COLOR_GRASS = '#388E3C',
|
||||||
_COLOR_HOLE = '#000000',
|
_COLOR_HOLE = '#000000',
|
||||||
_COLOR_BRACKET = '#000000'
|
_COLOR_BRACKET = '#000000'
|
||||||
|
|
||||||
|
|
||||||
|
var _MAX_BRACKET = 100
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
ctx = $('canvas')[0].getContext('2d')
|
ctx = $('canvas')[0].getContext('2d')
|
||||||
staticctx = $('canvas')[1].getContext('2d')
|
staticctx = $('canvas')[1].getContext('2d')
|
||||||
|
@ -40,7 +43,11 @@ var _COLOR_GRASS = '#388E3C',
|
||||||
$(document).mousemove(function(e){
|
$(document).mousemove(function(e){
|
||||||
pX = e.pageX - $('canvas').offset().left
|
pX = e.pageX - $('canvas').offset().left
|
||||||
pY = e.pageY - $('canvas').offset().top
|
pY = e.pageY - $('canvas').offset().top
|
||||||
});
|
})
|
||||||
|
|
||||||
|
$(document).mousedown(function(e){
|
||||||
|
// TODO: Add functionality
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function animLoop() {
|
function animLoop() {
|
||||||
|
@ -78,9 +85,17 @@ var _COLOR_GRASS = '#388E3C',
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawBracket() {
|
function drawBracket() {
|
||||||
|
var x = pX,
|
||||||
|
y = pY
|
||||||
|
if(Math.hypot(pX - bX, pY - bY) > _MAX_BRACKET){
|
||||||
|
angle = Math.atan2(pY - bY, pX - bX)
|
||||||
|
x = bX+_MAX_BRACKET*Math.cos(angle)
|
||||||
|
y = bY+_MAX_BRACKET*Math.sin(angle)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(bX, bY)
|
ctx.moveTo(bX, bY)
|
||||||
ctx.lineTo(pX, pY)
|
ctx.lineTo(x, y)
|
||||||
ctx.strokeStyle = _COLOR_BRACKET
|
ctx.strokeStyle = _COLOR_BRACKET
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
ctx.closePath()
|
ctx.closePath()
|
||||||
|
|
Reference in a new issue