Skip to content
Snippets Groups Projects
Commit 42136762 authored by Micah Elizabeth Scott's avatar Micah Elizabeth Scott
Browse files

Different kind of left-hand wobble, closer to what we wanted

parent 87da0ecc
No related branches found
No related tags found
No related merge requests found
...@@ -41,14 +41,21 @@ particleLifetime = 1.0 ...@@ -41,14 +41,21 @@ particleLifetime = 1.0
brightness = 1.0 brightness = 1.0
spinRate = 1.0 spinRate = 1.0
midiTime = 0
previousNow = 0 previousNow = 0
spinAngle = 0 spinAngle = 0
input.on 'message', (deltaTime, message) -> # Time clock in seconds
clock = () -> 0.001 * new Date().getTime()
# Midi to frequency
midiToHz = (key) -> 440 * Math.pow 2, (key - 69) / 12
# Keep time # Midi note to angle, one rev per octave
midiTime += deltaTime midiToAngle = (key) -> (2 * Math.PI / 12) * key
input.on 'message', (deltaTime, message) ->
console.log message
switch message[0] switch message[0]
when 0x80 # Voice 0, note off when 0x80 # Voice 0, note off
...@@ -61,7 +68,7 @@ input.on 'message', (deltaTime, message) -> ...@@ -61,7 +68,7 @@ input.on 'message', (deltaTime, message) ->
info = info =
key: key key: key
velocity: message[2] velocity: message[2]
timestamp: midiTime timestamp: clock()
# Split keyboard into particles and LFOs # Split keyboard into particles and LFOs
if key >= 60 if key >= 60
...@@ -72,7 +79,7 @@ input.on 'message', (deltaTime, message) -> ...@@ -72,7 +79,7 @@ input.on 'message', (deltaTime, message) ->
when 0xb0 # Voice 0, Control Change when 0xb0 # Voice 0, Control Change
switch message[1] switch message[1]
when 7 # "Data entry" slider, brightness when 7 # "Data entry" slider, brightness
brightness = message[2] * 3.0 / 127 brightness = message[2] * 2.0 / 127
when 1 # "Modulation" slider, particle speed when 1 # "Modulation" slider, particle speed
particleLifetime = 0.1 + message[2] * 2.0 / 127 particleLifetime = 0.1 + message[2] * 2.0 / 127
...@@ -85,7 +92,7 @@ input.on 'message', (deltaTime, message) -> ...@@ -85,7 +92,7 @@ input.on 'message', (deltaTime, message) ->
draw = () -> draw = () ->
# Time delta calculations # Time delta calculations
now = 0.001 * new Date().getTime() now = clock()
timeStep = now - previousNow timeStep = now - previousNow
previousNow = now previousNow = now
...@@ -103,47 +110,49 @@ draw = () -> ...@@ -103,47 +110,49 @@ draw = () ->
for p in particles for p in particles
# Angle: Global spin, thne positional mapping to key # Angle: Global spin, thne positional mapping to key
theta = spinAngle + (Math.PI / 5) * p.note.key theta = midiToAngle p.note.key
# Positioned in polar coordinates, on unit circle # Radius: Particles spawn in center, fly outward
x = Math.cos theta radius = 3.0 * (1 - p.life)
y = Math.sin theta
# Add influence of LFOs # Positioned in polar coordinates
for key, note of lfoNotes x = radius * Math.cos theta
y = radius * Math.sin theta
# Down several octaves, to useful LFO frequencies # One rainbow per octave
transpose = -12 * 5 hue = (p.note.key - 60 + 0.1) / 12.0
p.color = OPC.hsv hue, 0.3, 0.8
# Midi note to frequency # Intensity mapped to velocity, nonlinear
hz = 440 * Math.pow 2, (note.key - 69 + transpose) / 12 p.intensity = Math.pow(p.note.velocity / 100, 3.0) * 0.25 * brightness
# Wobble amplitude driven by LFO # Falloff gets sharper as the note gets higher
wobbleAmp = Math.sin Math.PI * 2 * now * hz p.falloff = 20 + (p.note.key - 60) * 20
# Wobble angle driven by LFO note and particle life # Add influence of LFOs
wobbleAngle = 10.0 * p.life + (Math.PI / 5) * p.note.key for key, note of lfoNotes
age = now - note.timestamp
hz = midiToHz key
lfoAngle = midiToAngle key
x += wobbleAmp * Math.cos wobbleAngle # Amplitude starts with left hand velocity
y += wobbleAmp * Math.sin wobbleAngle wobbleAmp = Math.pow(note.velocity / 100, 3.0)
# Radius: Particles spawn in center, fly outward # Scale based on particle fuzziness
radius = 3.0 * (1 - p.life) wobbleAmp *= 100.0 / p.falloff
x *= radius
y *= radius
# Use the XZ plane # Fade over time
p.point = [x, 0, y] wobbleAmp /= 1 + age
# One rainbow per octave # Wobble
hue = (p.note.key - 60) / 12.0 wobbleAmp *= Math.sin(p.life * Math.pow(3, (p.note.key - 35) / 12.0))
p.color = OPC.hsv hue, 0.5, 0.8
# Intensity mapped to velocity, nonlinear # Wobble angle driven by LFO note and particle life
p.intensity = Math.pow(p.note.velocity / 100, 5.0) * brightness x += wobbleAmp * Math.cos lfoAngle
y += wobbleAmp * Math.sin lfoAngle
# Falloff gets sharper as the note gets higher # Use the XZ plane
p.falloff = 20 + (p.note.key - 60) * 20 p.point = [x, 0, y]
p.life -= timeStep / particleLifetime p.life -= timeStep / particleLifetime
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment