Created
April 13, 2011 09:27
-
-
Save cassiel/917260 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
# OSC-level testing. | |
# $Id: arc-test-0.py,v 7e921a75f124 2011/04/07 16:26:54 nick $ | |
from net.loadbang.osc.comms import UDPTransmitter | |
from net.loadbang.osc.data import Message | |
from java.net import InetAddress | |
from java.lang import System | |
RINGSIZE = 64 | |
LEVELS = 16 | |
transmitter = UDPTransmitter(InetAddress.getByName('localhost'), 10332) | |
#pat = [0.5, 0.1, 0.3, 1.0, 0.3, 0.1, 0.5] | |
#pat = [1.0] | |
mainPat = [0.5, 1.0, 0.0, 1.0, 0.5] | |
backPat = [0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3] | |
def xmit(enc, buffer): | |
m = Message('/example/ring/map').addInteger(enc) | |
for i in range(RINGSIZE): m.addInteger(buffer[i]) | |
transmitter.transmit(m) | |
def level(f): | |
i = int(f * (LEVELS - 1) + 0.5) | |
i = max(min(i, 15), 0) | |
return i | |
def render(enc, ring): | |
xmit(enc, [level(ring[i]) for i in range(RINGSIZE)]) | |
def fiducial(ring): | |
for i in range(0, 63, 16): ring[i] = 0.05 | |
def draw(position, pat, ring): | |
''' position is a float, nominally 0.0...1.0 (but will wrap). ''' | |
ledPosition = (position % 1) * 64.0 # Careful: int() wraps to zero, not down, so try | |
# to avoid int(neg). | |
loLED = int(ledPosition) | |
hiLED = loLED + 1 | |
loAmount = hiLED - ledPosition | |
hiAmount = ledPosition - loLED | |
offset = -((len(pat) - 1) / 2) | |
for i in range(len(pat)): | |
ring[(offset + loLED + i) % RINGSIZE] += (pat[i] * loAmount) | |
ring[(offset + hiLED + i) % RINGSIZE] += (pat[i] * hiAmount) | |
def drawAll(s, enc, position): | |
ring = [0.0 for _ in range(RINGSIZE)] | |
if s < 0.5: fiducial(ring) | |
draw(position, mainPat, ring) | |
draw(position + 0.5, backPat, ring) | |
render(enc, ring) | |
def doit(): | |
t = System.currentTimeMillis() + 1000.0 * 60.0 * 60.0 | |
d = (t / (1000.0 * 60.0 * 60.0 * 12.0)) % 1 | |
h = (t / (1000.0 * 60.0 * 60.0)) % 1 | |
m = (t / (1000.0 * 60.0)) % 1 | |
s = (t / 1000.0) % 1 | |
drawAll(s, 0, d) | |
drawAll(s, 1, h) | |
drawAll(s, 2, m) | |
drawAll(s, 3, s) | |
def _cleanup(): | |
print "Closing %s" % str(transmitter) | |
transmitter.close() | |
engine.addCleanup(_cleanup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment