Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
victusfate committed Nov 14, 2012
1 parent edea0e6 commit e17ba68
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions js/canvas_bkg.coffee
Expand Up @@ -3,27 +3,37 @@ ctx = null
grad = null
body = document.getElementsByTagName("body")[0]
color = 255
canvasAdjust = true
if canvas.getContext("2d")
ctx = canvas.getContext("2d")
ctx.clearRect 0, 0, 900, 700
ctx.save()
grad = ctx.createRadialGradient(0, 0, 0, 0, 0, 900)
grad.addColorStop 0, "#000"
grad.addColorStop 1, "rgb(" + color + ", " + color + ", " + color + ")"
ctx.fillStyle = grad
ctx.fillRect 0, 0, 900, 700
ctx.save()
body.onmousemove = (event) ->
width = window.innerWidth
height = window.innerHeight
x = event.clientX
y = event.clientY
rx = 900 * x / width
ry = 700 * y / height
xc = ~~(256 * x / width)
yc = ~~(256 * y / height)
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 900)
grad.addColorStop 0, "#000"
grad.addColorStop 1, [ "rgb(", xc, ", ", (255 - xc), ", ", yc, ")" ].join("")
ctx.fillStyle = grad
ctx.fillRect 0, 0, 900, 700
ctx = canvas.getContext("2d")
ctx.clearRect 0, 0, 900, 700
ctx.save()
grad = ctx.createRadialGradient(0, 0, 0, 0, 0, 900)
grad.addColorStop 0, "#000"
grad.addColorStop 1, "rgb(" + color + ", " + color + ", " + color + ")"
ctx.fillStyle = grad
ctx.fillRect 0, 0, 900, 700
ctx.save()
body.onmousemove = (event) ->
if canvasAdjust
width = window.innerWidth
height = window.innerHeight
x = event.clientX
y = event.clientY
rx = 900 * x / width
ry = 700 * y / height
xc = ~~(256 * x / width)
yc = ~~(256 * y / height)
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 900)
grad.addColorStop 0, "#000"
grad.addColorStop 1, [ "rgb(", xc, ", ", (255 - xc), ", ", yc, ")" ].join("")
ctx.fillStyle = grad
ctx.fillRect 0, 0, 900, 700
null

body.onclick = (event) ->
if canvasAdjust
canvasAdjust = false
else
canvasAdjust = true
null

0 comments on commit e17ba68

Please sign in to comment.