Last active
August 19, 2016 14:08
-
-
Save antonhornquist/67d518733e7ada2856590bbfa37ea41b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
var app = \bulb; | |
var position, size, alpha; | |
var plotpath, update; | |
var client; | |
Archive.global.at(\apps, app).isNil.if { | |
Archive.global.put(\apps, app, \position, `(8.rand@8.rand))); | |
Archive.global.put(\apps, app, \size, `50); | |
Archive.global.put(\apps, app, \alpha, `0); | |
}; | |
position = Archive.global.at(\apps, app, \position); | |
size = Archive.global.at(\apps, app, \size); | |
alpha = Archive.global.at(\apps, app, \alpha); | |
plotpath = { |to| | |
var steps = 5; | |
var delta = (to - position.get) / steps; | |
fork { | |
steps.do { | |
position.set(position.get + delta).changed; | |
0.025.wait; | |
}; | |
position.set(to).changed; | |
} | |
}; | |
update = { | |
var levels = Array.fill(8) { |gridy| | |
Array.fill(8) { |gridx| | |
var distance; | |
distance = (gridx@gridy) dist: position.get; | |
15-(distance*((100-size.get)/100*15)).round.clip(0, 15); | |
} | |
}.flat * (1-(alpha.get/100)); | |
// TODO: compare with previous Array and only change when needed | |
client.ledLevelMap(0, 0, levels); | |
}; | |
[position, size, alpha] do: _.addDependant(update); | |
client = SerialOSCClient.gridEnc(app); | |
client.onGridRefreshed = { | |
SerialOSCGrid.clearLeds; // TODO: could be implied | |
update.(); | |
}; | |
client.onGridKey = { |x, y, state| if (state) { plotpath.(x@y) } }; | |
client.onEncDelta = { |n, delta| | |
switch (n) { 0 } { size } { 1 } { alpha } !? { |ref| | |
ref.set((ref.get + (delta/2)).clip(0, 100)).changed; | |
}; | |
}; | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment