Speed Coded Mouse Toy
d = document
b = d.body
b.style.margin = 0
with (b.appendChild(
Object.assign(d.createElement`canvas`, {
width: innerWidth,
height: innerHeight,
})
).getContext`2d`) {
mx = 0
my = 0
onresize = _ => {
canvas.width = innerWidth
canvas.height = innerHeight
}
onpointermove = e => {
mx = e.clientX,
my = e.clientY
}
r = 0
loop = () => {
save()
globalCompositeOperation = 'hard-light'
translate(innerWidth / 2, innerHeight / 2)
rotate(r += .02)
translate(-innerWidth / 2, -innerHeight / 2)
fillStyle = 'rgba(55, 55, 55, .01)'
fillRect(0, 0, innerWidth, innerHeight)
fillStyle = 'rgba(116, 196, 221, .02)'
fillRect(0, my, innerWidth, 20);
fillStyle = 'rgba(255, 255, 255, .02)'
fillRect(mx, 0, 20, innerHeight);
fillStyle = 'rgba(0, 0, 0, .03)'
fillRect(0, innerHeight - my, innerWidth, 20);
fillStyle = 'rgba(116, 196, 221, .02)'
fillRect(innerWidth - mx, 0, 20, innerHeight);
restore()
requestAnimationFrame(loop)
}
loop()
}
Speed coded mouse toy…