-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
73 lines (51 loc) · 1.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<!-- https://github.com/benfoxall/cursory-hack/ -->
<html>
<head>
<meta charset="utf-8">
<title>cursory hack</title>
<style media="screen">
body {height:100vh;, margin:0;}
</style>
</head>
<body>
<script type="text/javascript">
// limit for cursor size is 128
var canvas = document.createElement('canvas')
canvas.width = canvas.height = 128
var ctx = canvas.getContext('2d')
ctx.fillStyle = 'rgba(255,0,100,0.8)'
ctx.strokeStyle = 'rgba(255,0,100,0.5)'
var cx, cy, x, y, animation
document.body.addEventListener('mousemove', function(e){
cx = e.clientX
cy = e.clientY
x = cx / window.innerWidth
y = cy / window.innerHeight
if(!animation) animation = requestAnimationFrame(animate)
})
function animate(time){
animation = null
ctx.clearRect(0,0,128,128)
// THIS IS SUPER UGLY,
// BUT YOU GET THE IDEA, YEAH?
var angle = Math.atan2(x-.5, y-.5)
var extent = Math.max(Math.abs(x-.5), Math.abs(y-.5)) * 2
ctx.save()
ctx.translate(64, 64)
ctx.rotate(-angle)
ctx.translate(-64, -64)
ctx.beginPath()
ctx.arc(64,64 + (54*extent),10,0,Math.PI*2)
ctx.fill()
ctx.beginPath()
ctx.moveTo(64,64 + (54*extent))
ctx.lineTo(64,(1-extent) * 64)
ctx.stroke()
ctx.restore()
var url = canvas.toDataURL()
document.body.style.cursor = 'url('+url+') '+(1-x)*128+' '+(1-y)*128+', crosshair'
}
</script>
</body>
</html>