summaryrefslogtreecommitdiff
path: root/client/draw.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-02-21 14:44:43 +0100
committerJules Laplace <julescarbon@gmail.com>2018-02-21 14:44:43 +0100
commit486d1d22f64fb930bd15707ffbde10a68f37ea7d (patch)
tree8c0ef9fa86d8c20be07db2312ea72c5e68f050f7 /client/draw.js
parent4965ee2d60b8f671b2ea243f32c69f249b41caab (diff)
refining glass sound
Diffstat (limited to 'client/draw.js')
-rw-r--r--client/draw.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/client/draw.js b/client/draw.js
index 0a86d4a..d3affbd 100644
--- a/client/draw.js
+++ b/client/draw.js
@@ -6,25 +6,48 @@ import {
import mouse from './lib/mouse'
import color from './lib/color'
+let w, h
+let rx, ry
+
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
+
document.body.appendChild(canvas)
+document.body.addEventListener('resize', resize)
+resize()
+recenter()
+requestAnimationFrame(animate)
-let w, h
function resize(){
w = canvas.width = window.innerWidth
h = canvas.height = window.innerHeight
}
-document.body.addEventListener('resize', resize)
-resize()
-
+function recenter(){
+ rx = randint(w), ry = randint(h)
+}
+function animate(t){
+ requestAnimationFrame(animate)
+ ctx.save()
+ ctx.globalAlpha = 0.0001
+ ctx.translate(w/2, h/2)
+ ctx.rotate(0.1)
+ ctx.translate(-rx, -ry)
+ ctx.drawImage(canvas, 0, 0)
+ ctx.restore()
+}
function clear(n){
ctx.fillStyle = 'rgba(255,255,255,' + (n || 0.5) + ')'
ctx.fillRect(0,0,w,h)
+ recenter()
+}
+function triangle(px,py,r){
+ setTimeout( () => tri(px,py,r), Math.random()*10)
+ // setTimeout( () => tri(px,py,r), Math.random()*200)
+ // setTimeout( () => tri(px,py,r), Math.random()*300)
}
-function triangle(px, py, r) {
+function tri(px, py, r) {
ctx.save()
- ctx.globalCompositeOperation = 'difference'
+ ctx.globalCompositeOperation = 'multiply'
ctx.fillStyle = color((px+py)/(w+h), 0, 1, 1)
function p(){
let theta = randrange(0, Math.PI*2)