Compare commits
No commits in common. "master" and "thresholding" have entirely different histories.
master
...
thresholdi
62
firestar.py
62
firestar.py
@ -77,7 +77,7 @@ def runsimple(ss):
|
|||||||
b.set_light([edges[e].light_id for e in subs[i]], thiscmd)
|
b.set_light([edges[e].light_id for e in subs[i]], thiscmd)
|
||||||
time.sleep((transition_to + hold_time)/10)
|
time.sleep((transition_to + hold_time)/10)
|
||||||
|
|
||||||
runsimple(intro)
|
#runsimple(intro)
|
||||||
|
|
||||||
# The most symmetric five-coloring of edges
|
# The most symmetric five-coloring of edges
|
||||||
fivecs = [];
|
fivecs = [];
|
||||||
@ -126,62 +126,12 @@ fivecolors = [vb(c) for c in ['R', 'Y', 'G', 'B', 'K']]
|
|||||||
|
|
||||||
# Nick's coloring (NC) "0"
|
# Nick's coloring (NC) "0"
|
||||||
fivetour = [(fivecs[0], fivecolors)]
|
fivetour = [(fivecs[0], fivecolors)]
|
||||||
# 1: Step NC "0" to NC "1"
|
# Step NC "0" to NC "1"
|
||||||
fivetour.append(([[3,21,26],[4,19,28]], [vb('K'),vb('Y')]))
|
fivetour.append(([[3,21,26],[4,19,28]], [vb('K'),vb('Y')]))
|
||||||
# 2: Step NC "1" to NC "0"
|
# Step NC "1" to NC "0"
|
||||||
fivetour.append(([[3,21,26],[4,19,28]], [vb('Y'),vb('K')]))
|
fivetour.append(([[3,21,26],[4,19,28]], [vb('Y'),vb('K')]))
|
||||||
# 3: Step NC "1" to NC "2"
|
|
||||||
fivetour.append(([[0,12,25],[1,10,27]], [vb('G'),vb('R')]))
|
|
||||||
# 4: Step NC "2" to NC "1"
|
|
||||||
fivetour.append(([[0,12,25],[1,10,27]], [vb('R'),vb('G')]))
|
|
||||||
# 5: Step NC "2" to NC "3"
|
|
||||||
fivetour.append(([[1,22],[3,24]], [vb('K'),vb('R')]))
|
|
||||||
# 6: Step NC "3" to NC "2"
|
|
||||||
fivetour.append(([[1,22],[3,24]], [vb('R'),vb('K')]))
|
|
||||||
# 7: Step NC "3" to NC "4"
|
|
||||||
fivetour.append(([[12,20],[11,19]], [vb('Y'),vb('G')]))
|
|
||||||
# 8: Step NC "4" to NC "3"
|
|
||||||
fivetour.append(([[12,20],[11,19]], [vb('G'),vb('Y')]))
|
|
||||||
# 9: Step NC "4" to NC "5"
|
|
||||||
fivetour.append(([[0,15,19],[3,9,27]], [vb('R'),vb('G')]))
|
|
||||||
# 10: Step NC "5" to NC "4"
|
|
||||||
fivetour.append(([[0,15,19],[3,9,27]], [vb('G'),vb('R')]))
|
|
||||||
# 11: Step NC "5" to NC "6"
|
|
||||||
fivetour.append(([[4,12,16],[1,6,26]], [vb('K'),vb('Y')]))
|
|
||||||
# 12: Step NC "6" to NC "5"
|
|
||||||
fivetour.append(([[4,12,16],[1,6,26]], [vb('K'),vb('Y')]))
|
|
||||||
# 13: Step NC "4" to NC "7"
|
|
||||||
fivetour.append(([[0,19,25],[1,21,26]], [vb('K'),vb('G')]))
|
|
||||||
# 14: Step NC "7" to NC "4"
|
|
||||||
fivetour.append(([[0,19,25],[1,21,26]], [vb('K'),vb('G')]))
|
|
||||||
|
|
||||||
# Would need to add asymmetric colorings here, but no time :-(
|
tour5show = (fivetour, [(0,30,20),(1,5,5),(2,5,5),(1,5,5),(2,5,5),(1,5,30)])
|
||||||
|
|
||||||
tour5show = (fivetour, [(0,30,20),
|
runsimple(interlude)
|
||||||
(1,5,5),(2,5,5),(1,5,5),(2,5,5),(1,5,30),
|
runsimple(tour5show)
|
||||||
(3,5,5),(4,5,5),(3,5,5),(4,5,5),(3,5,30),
|
|
||||||
(5,5,5),(6,5,5),(5,5,5),(6,5,5),(5,5,30),
|
|
||||||
(7,5,5),(8,5,5),(7,5,5),(8,5,5),(7,5,30),
|
|
||||||
(9,5,5),(10,5,5),(9,5,5),(10,5,5),(9,5,30),
|
|
||||||
(11,5,5),(12,5,5),(11,5,5),(12,5,5),(11,5,100),
|
|
||||||
(12,5,5),(11,5,5),(12,5,5),(11,5,5),(12,5,30),
|
|
||||||
(10,5,5),(9,5,5),(10,5,5),(9,5,5),(10,5,30),
|
|
||||||
(13,5,5),(14,5,5),(13,5,5),(14,5,5),(13,5,100),
|
|
||||||
(14,5,5),(13,5,5),(14,5,5),(13,5,5),(14,5,30),
|
|
||||||
(8,5,5),(7,5,5),(8,5,5),(7,5,5),(8,5,30),
|
|
||||||
(6,5,5),(5,5,5),(6,5,5),(5,5,5),(6,5,30),
|
|
||||||
(4,5,5),(3,5,5),(4,5,5),(3,5,5),(4,5,30),
|
|
||||||
(2,5,5),(1,5,5),(2,5,5),(1,5,5),(2,5,100),
|
|
||||||
])
|
|
||||||
|
|
||||||
while True:
|
|
||||||
runsimple(interlude)
|
|
||||||
runsimple(jmsshow1)
|
|
||||||
runsimple(interlude)
|
|
||||||
runsimple(jmsshow2)
|
|
||||||
|
|
||||||
runsimple(interlude)
|
|
||||||
runsimple(starshow)
|
|
||||||
|
|
||||||
runsimple(interlude)
|
|
||||||
runsimple(tour5show)
|
|
||||||
|
172
interactions.py
172
interactions.py
@ -10,7 +10,7 @@ import phue, pygame, colorsys
|
|||||||
viewsize = 600
|
viewsize = 600
|
||||||
shrink = 0.9
|
shrink = 0.9
|
||||||
vertices = [(viewsize*(1 + shrink*x)/2, viewsize*(1 + shrink*y)/2) for x, y in
|
vertices = [(viewsize*(1 + shrink*x)/2, viewsize*(1 + shrink*y)/2) for x, y in
|
||||||
[(0, 0)] + [(sin(n*pi/5), -cos(n*pi/5)) for n in range(10)] + [(0, 0)]
|
[(0, 0)] + [(cos(-n*pi/5), sin(-n*pi/5)) for n in range(10)] + [(0, 0)]
|
||||||
]
|
]
|
||||||
|
|
||||||
# edges as vertex pairs. FireStar will rest on vertices 6 (A), 5 (B), 7 (C)
|
# edges as vertex pairs. FireStar will rest on vertices 6 (A), 5 (B), 7 (C)
|
||||||
@ -55,8 +55,8 @@ clock = pygame.time.Clock()
|
|||||||
|
|
||||||
# --- copied from firestar.py
|
# --- copied from firestar.py
|
||||||
|
|
||||||
b = phue.Bridge('172.18.130.12')
|
##b = phue.Bridge('172.18.130.12')
|
||||||
##b = None
|
b = None
|
||||||
Nedges = 30;
|
Nedges = 30;
|
||||||
edgecode = [None] * Nedges;
|
edgecode = [None] * Nedges;
|
||||||
|
|
||||||
@ -91,40 +91,6 @@ def set_light_hsv(e, color, hit_bridge):
|
|||||||
rgb_color = tuple(255*c for c in colorsys.hsv_to_rgb(*color))
|
rgb_color = tuple(255*c for c in colorsys.hsv_to_rgb(*color))
|
||||||
pygame.draw.aaline(screen, rgb_color, vertices[vertex_adj[e][0]], vertices[vertex_adj[e][1]])
|
pygame.draw.aaline(screen, rgb_color, vertices[vertex_adj[e][0]], vertices[vertex_adj[e][1]])
|
||||||
|
|
||||||
# === messages and mode selection ===
|
|
||||||
|
|
||||||
mode = 0
|
|
||||||
|
|
||||||
# data labels
|
|
||||||
updates_label = font.render('updates', True, (255, 255, 255))
|
|
||||||
energy_label = font.render('energy', True, (255, 255, 255))
|
|
||||||
position_label = [
|
|
||||||
font.render('temp[0]', True, (255, 255, 255)),
|
|
||||||
font.render('charge[0]', True, (255, 255, 255))
|
|
||||||
]
|
|
||||||
|
|
||||||
# instructions
|
|
||||||
mode_inds = [
|
|
||||||
[
|
|
||||||
font.render('[d] heat', True, (255, 255, 255)),
|
|
||||||
font.render('[f] wave', True, (150, 150, 150))
|
|
||||||
],
|
|
||||||
[
|
|
||||||
font.render('[d] heat', True, (150, 150, 150)),
|
|
||||||
font.render('[f] wave', True, (255, 255, 255))
|
|
||||||
]
|
|
||||||
]
|
|
||||||
bop_instr = [
|
|
||||||
font.render('press [j] to bop', True, (255, 255, 255)),
|
|
||||||
font.render('press [j] or [k] to bop', True, (255, 255, 255))
|
|
||||||
]
|
|
||||||
drain_instr = font.render('hold [space] to drain', True, (255, 255, 255))
|
|
||||||
|
|
||||||
# set up background
|
|
||||||
background = pygame.Surface(screen.get_size()).convert()
|
|
||||||
background.fill((32, 32, 32))
|
|
||||||
background.blit(drain_instr, (340, 60 + viewsize))
|
|
||||||
|
|
||||||
# === interaction parameters ===
|
# === interaction parameters ===
|
||||||
|
|
||||||
# these frame rate and threshold settings are untested, but the exponential
|
# these frame rate and threshold settings are untested, but the exponential
|
||||||
@ -134,18 +100,13 @@ ema_weight = 2/(frame_rate+1)
|
|||||||
|
|
||||||
inductance = 0.001
|
inductance = 0.001
|
||||||
|
|
||||||
therm_conduct = 0.01
|
therm_conduct = 0.001
|
||||||
|
|
||||||
drain = False
|
drain = False
|
||||||
drain_rate = 0.1
|
drain_rate = 0.1
|
||||||
|
|
||||||
# === phase space ===
|
# === phase space ===
|
||||||
|
|
||||||
# heat equation
|
|
||||||
temp = 30*[0]
|
|
||||||
new_temp = 30*[0]
|
|
||||||
|
|
||||||
# wave equation
|
|
||||||
charge = 12*[0]
|
charge = 12*[0]
|
||||||
current = 30*[0]
|
current = 30*[0]
|
||||||
|
|
||||||
@ -156,13 +117,11 @@ change_threshold = 0.15
|
|||||||
|
|
||||||
def heat_evolution():
|
def heat_evolution():
|
||||||
for e, f in cyc_edge_adj:
|
for e, f in cyc_edge_adj:
|
||||||
flow = therm_conduct*(temp[e] - temp[f])
|
flow = therm_conduct*(current[e] - current[f])
|
||||||
new_temp[e] -= flow
|
current[e] -= flow
|
||||||
new_temp[f] += flow
|
current[f] += flow
|
||||||
for e in range(30):
|
|
||||||
if drain:
|
if drain:
|
||||||
new_temp[e] *= 1 - drain_rate
|
current[v] *= 1 - drain_rate
|
||||||
temp[e] = max(new_temp[e], 0)
|
|
||||||
|
|
||||||
def wave_evolution():
|
def wave_evolution():
|
||||||
# use verlet integration, first updating the currents and then using the new
|
# use verlet integration, first updating the currents and then using the new
|
||||||
@ -178,15 +137,6 @@ def wave_evolution():
|
|||||||
for v in range(12):
|
for v in range(12):
|
||||||
charge[v] *= 1 - drain_rate
|
charge[v] *= 1 - drain_rate
|
||||||
|
|
||||||
def set_heat_light(e, i):
|
|
||||||
new_litness = 1 - exp(-2*i)
|
|
||||||
if abs(new_litness - litness[e]) > change_threshold:
|
|
||||||
hit_bridge = True
|
|
||||||
litness[e] = new_litness
|
|
||||||
else:
|
|
||||||
hit_bridge = False
|
|
||||||
set_light_hsv(e, (0.167*litness[e], 1 - 0.5*litness[e]*litness[e], litness[e]), hit_bridge)
|
|
||||||
|
|
||||||
def set_wave_light(e, i):
|
def set_wave_light(e, i):
|
||||||
new_litness = 1 - exp(-2*i*i)
|
new_litness = 1 - exp(-2*i*i)
|
||||||
if abs(new_litness - litness[e]) > change_threshold:
|
if abs(new_litness - litness[e]) > change_threshold:
|
||||||
@ -196,24 +146,41 @@ def set_wave_light(e, i):
|
|||||||
hit_bridge = False
|
hit_bridge = False
|
||||||
set_light_hsv(e, (0.45 + litness[e]*0.25, 1 - 0.5*litness[e]*litness[e], litness[e]), hit_bridge)
|
set_light_hsv(e, (0.45 + litness[e]*0.25, 1 - 0.5*litness[e]*litness[e], litness[e]), hit_bridge)
|
||||||
|
|
||||||
def handle_heat_events():
|
def show_data(screen):
|
||||||
global drain, mode
|
# light updates
|
||||||
for event in pygame.event.get():
|
global updates, new_updates
|
||||||
if event.type == pygame.KEYDOWN:
|
updates = ema_weight*new_updates + (1 - ema_weight)*updates
|
||||||
if event.key == pygame.K_j:
|
new_updates = 0
|
||||||
new_temp[0] += 10
|
text = font.render('updates', True, (255, 255, 255))
|
||||||
elif event.key == pygame.K_SPACE:
|
screen.blit(text, (20, viewsize))
|
||||||
drain = True
|
text = font.render(str(frame_rate * updates), True, (255, 255, 255))
|
||||||
elif event.key == pygame.K_f:
|
screen.blit(text, (120, viewsize))
|
||||||
mode = 1
|
|
||||||
elif event.type == pygame.KEYUP:
|
|
||||||
if event.key == pygame.K_SPACE:
|
|
||||||
drain = False
|
|
||||||
elif event.type == pygame.QUIT:
|
|
||||||
quit()
|
|
||||||
|
|
||||||
def handle_wave_events():
|
# energy
|
||||||
global drain, mode
|
energy = 0.5*(sum(q*q for q in charge) + inductance*sum(i*i for i in current))
|
||||||
|
text = font.render('energy', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (20, 30 + viewsize))
|
||||||
|
text = font.render(str(energy), True, (255, 255, 255))
|
||||||
|
screen.blit(text, (120, 30 + viewsize))
|
||||||
|
|
||||||
|
# charge[0]
|
||||||
|
text = font.render('charge[0]', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (20, 60 + viewsize))
|
||||||
|
text = font.render(str(charge[0]), True, (255, 255, 255))
|
||||||
|
screen.blit(text, (120, 60 + viewsize))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# set up background
|
||||||
|
background = pygame.Surface(screen.get_size()).convert()
|
||||||
|
background.fill((32, 32, 32))
|
||||||
|
text = font.render('press [j] or [k] to pluck', True, (255, 255, 255))
|
||||||
|
background.blit(text, (340, viewsize))
|
||||||
|
text = font.render('hold [space] to drain', True, (255, 255, 255))
|
||||||
|
background.blit(text, (340, 30 + viewsize))
|
||||||
|
|
||||||
|
to_light = 0
|
||||||
|
while True:
|
||||||
|
# handle events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_j:
|
if event.key == pygame.K_j:
|
||||||
@ -224,69 +191,26 @@ def handle_wave_events():
|
|||||||
charge[7] -= 100
|
charge[7] -= 100
|
||||||
elif event.key == pygame.K_SPACE:
|
elif event.key == pygame.K_SPACE:
|
||||||
drain = True
|
drain = True
|
||||||
elif event.key == pygame.K_d:
|
pygame.draw.aaline(screen, (255, 255, 255), (0, 0), (viewsize, viewsize))
|
||||||
mode = 0
|
|
||||||
elif event.type == pygame.KEYUP:
|
elif event.type == pygame.KEYUP:
|
||||||
if event.key == pygame.K_SPACE:
|
if event.key == pygame.K_SPACE:
|
||||||
drain = False
|
drain = False
|
||||||
elif event.type == pygame.QUIT:
|
elif event.type == pygame.QUIT:
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
def show_data(screen):
|
|
||||||
# light updates
|
|
||||||
global updates, new_updates
|
|
||||||
updates = ema_weight*new_updates + (1 - ema_weight)*updates
|
|
||||||
new_updates = 0
|
|
||||||
updates_value = font.render(str(frame_rate * updates), True, (255, 255, 255))
|
|
||||||
screen.blit(updates_label, (20, viewsize))
|
|
||||||
screen.blit(updates_value, (120, viewsize))
|
|
||||||
|
|
||||||
# energy
|
|
||||||
if mode == 0:
|
|
||||||
energy = sum(temp)
|
|
||||||
elif mode == 1:
|
|
||||||
energy = 0.5*(sum(q*q for q in charge) + inductance*sum(i*i for i in current))
|
|
||||||
energy_value = font.render(str(energy), True, (255, 255, 255))
|
|
||||||
screen.blit(energy_label, (20, 30 + viewsize))
|
|
||||||
screen.blit(energy_value, (120, 30 + viewsize))
|
|
||||||
|
|
||||||
# a position
|
|
||||||
##position_value = None
|
|
||||||
if mode == 0:
|
|
||||||
position_value = font.render(str(temp[0]), True, (255, 255, 255))
|
|
||||||
elif mode == 1:
|
|
||||||
position_value = font.render(str(charge[0]), True, (255, 255, 255))
|
|
||||||
screen.blit(position_label[mode], (20, 60 + viewsize))
|
|
||||||
screen.blit(position_value, (120, 60 + viewsize))
|
|
||||||
|
|
||||||
# instructions
|
|
||||||
screen.blit(mode_inds[mode][0], (340, viewsize))
|
|
||||||
screen.blit(mode_inds[mode][1], (420, viewsize))
|
|
||||||
screen.blit(bop_instr[mode], (340, 30 + viewsize))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
while True:
|
|
||||||
# handle events
|
|
||||||
if mode == 0:
|
|
||||||
handle_heat_events()
|
|
||||||
elif mode == 1:
|
|
||||||
handle_wave_events()
|
|
||||||
|
|
||||||
# clear screen
|
# clear screen
|
||||||
screen.blit(background, (0, 0))
|
screen.blit(background, (0, 0))
|
||||||
|
|
||||||
# show data and instructions
|
# show data
|
||||||
show_data(screen)
|
show_data(screen)
|
||||||
|
|
||||||
# show state and evolve state
|
# show state
|
||||||
if mode == 0:
|
|
||||||
for e in range(30):
|
|
||||||
set_heat_light(e, temp[e])
|
|
||||||
heat_evolution()
|
|
||||||
elif mode == 1:
|
|
||||||
for e in range(30):
|
for e in range(30):
|
||||||
set_wave_light(e, current[e])
|
set_wave_light(e, current[e])
|
||||||
|
|
||||||
|
# evolve state
|
||||||
wave_evolution()
|
wave_evolution()
|
||||||
|
##heat_evolution()
|
||||||
|
|
||||||
# step
|
# step
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
Loading…
Reference in New Issue
Block a user