summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/client/index.js b/client/index.js
index 12d466e..6e348cd 100644
--- a/client/index.js
+++ b/client/index.js
@@ -5,7 +5,7 @@ import { browser, requestAudioContext, clamp, firstTouch } from './lib/util'
const compressor = new Tone.Compressor(-30, 3).toMaster()
-const GRAIN_TIME = 1/20
+const GRAIN_TIME = 1/2
const SAMPLE_RATE = 44100
const GRAIN_SIZE = GRAIN_TIME * SAMPLE_RATE
@@ -39,17 +39,18 @@ player.fadeIn = 0.25
player.fadeOut = 0.25
player.connect(compressor)
-let intensity = 0, inertialIntensity = 0, inertia = 16
+let intensity = 0, inertialIntensity = 0, inertia = 5
function tick (time) {
if (! offsets.length) return
// let offsetIndex = clamp( Math.floor(mouse.y * offsets.length + Math.cos(time/20)), 0, offsets.length-1 )
inertialIntensity = Math.max(intensity, (intensity + inertialIntensity*(inertia-1))/inertia)
console.log(inertialIntensity)
- let offsetIndex = Math.floor(inertialIntensity * offsets.length + Math.cos(time))
+ let offsetIntensity = 0.98 * inertialIntensity
+ let offsetIndex = Math.floor(offsetIntensity * offsets.length + Math.cos(time))
let offset = Math.max((offsets[offsetIndex] || 0) * GRAIN_TIME + ( 0.25 * Math.sin(time*17/7) ), 0)
// console.log(offset, offsets[offsetIndex] * GRAIN_TIME, ( 0.25 * Math.cos(time*13/7)))
- player.start('applause', time, offset, GRAIN_TIME * 4)
+ player.start('applause', time, offset, GRAIN_TIME * 4, 0, inertialIntensity)
}
let mouse = { x: 0, y: 0 }
@@ -74,8 +75,8 @@ function move (e){
if (drawing) {
intensity = Math.min(0.999, intensity + v*0.1)
inertialIntensity = Math.min(0.999, intensity)
- if (intensity == 0.999) intensity -= (Math.random() * 0.01)
- if (inertialIntensity == 0.999) inertialIntensity -= (Math.random() * 0.01)
+ if (intensity == 0.999) intensity -= (Math.random() * 0.45)
+ if (inertialIntensity == 0.999) inertialIntensity -= (Math.random() * 0.35)
const gray = Math.floor( clamp(1-(10*v),0,1)*255 )
ctx.fillStyle = 'rgb(' + [gray,gray,gray] + ')'
ctx.beginPath()
@@ -90,8 +91,8 @@ function up (e) {
intensity = 0
}
setInterval( () => {
- inertialIntensity += 0.1
-}, 2000)
+ inertialIntensity += 0.001
+}, 5000)
if (browser.isMobile) {
document.body.addEventListener('touchstart', firstTouch(down))
@@ -107,8 +108,8 @@ else {
function animate(){
requestAnimationFrame(animate)
ctx.save()
- ctx.fillStyle='rgba(255,255,255,0.11)'
- ctx.globalAlpha = 0.1
+ ctx.fillStyle='rgba(255,255,255,' + (1-(intensity || 0.01)) + ')'
+ ctx.globalAlpha = 0.001
ctx.fillRect(0,0,window.innerWidth,window.innerHeight)
ctx.restore()
}