Compare commits

...

11 Commits

Author SHA1 Message Date
Glen Whitney b8d86d501e Merge fival version of branch 'interactions' 2019-09-29 10:59:21 -04:00
Glen Whitney 5fdc58a499 Update to the show as run 2019Sep28 2019-09-29 10:57:54 -04:00
Aaron Fenyes d54d4628af Turn on bridge connection 2019-09-29 16:35:06 +02:00
Aaron Fenyes fef5385da7 Reorient display
This reflects the way the FireStar sits on the ground.
2019-09-29 16:28:28 +02:00
Aaron Fenyes 9dc6098ff3 Set up heat/wave mode switch 2019-09-29 16:26:08 +02:00
Aaron Fenyes a52ed7a90e Merge branch 'heat' into interactions
Wave code hasn't been re-tested yet.
2019-09-29 15:36:12 +02:00
Aaron Fenyes 56f42684f3 Turn on bridge connection 2019-09-29 03:42:13 +02:00
Aaron Fenyes b11420daab Update instructions 2019-09-29 03:40:43 +02:00
Aaron Fenyes 0ac76265a0 Start developing heat evolution 2019-09-29 01:23:02 +02:00
Glen Whitney 0c2b31a99e Merge branch 'interactions' 2019-09-28 16:36:04 -04:00
Glen Whitney f57588064b trivial commit to test pushing via github account 2019-09-28 11:55:17 -04:00
2 changed files with 187 additions and 61 deletions

View File

@ -77,7 +77,7 @@ def runsimple(ss):
b.set_light([edges[e].light_id for e in subs[i]], thiscmd)
time.sleep((transition_to + hold_time)/10)
#runsimple(intro)
runsimple(intro)
# The most symmetric five-coloring of edges
fivecs = [];
@ -126,12 +126,62 @@ fivecolors = [vb(c) for c in ['R', 'Y', 'G', 'B', 'K']]
# Nick's coloring (NC) "0"
fivetour = [(fivecs[0], fivecolors)]
# Step NC "0" to NC "1"
# 1: Step NC "0" to NC "1"
fivetour.append(([[3,21,26],[4,19,28]], [vb('K'),vb('Y')]))
# Step NC "1" to NC "0"
# 2: Step NC "1" to NC "0"
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')]))
tour5show = (fivetour, [(0,30,20),(1,5,5),(2,5,5),(1,5,5),(2,5,5),(1,5,30)])
# Would need to add asymmetric colorings here, but no time :-(
runsimple(interlude)
runsimple(tour5show)
tour5show = (fivetour, [(0,30,20),
(1,5,5),(2,5,5),(1,5,5),(2,5,5),(1,5,30),
(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)

View File

@ -10,7 +10,7 @@ import phue, pygame, colorsys
viewsize = 600
shrink = 0.9
vertices = [(viewsize*(1 + shrink*x)/2, viewsize*(1 + shrink*y)/2) for x, y in
[(0, 0)] + [(cos(-n*pi/5), sin(-n*pi/5)) for n in range(10)] + [(0, 0)]
[(0, 0)] + [(sin(n*pi/5), -cos(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)
@ -55,8 +55,8 @@ clock = pygame.time.Clock()
# --- copied from firestar.py
##b = phue.Bridge('172.18.130.12')
b = None
b = phue.Bridge('172.18.130.12')
##b = None
Nedges = 30;
edgecode = [None] * Nedges;
@ -91,6 +91,40 @@ def set_light_hsv(e, color, hit_bridge):
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]])
# === 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 ===
# these frame rate and threshold settings are untested, but the exponential
@ -100,13 +134,18 @@ ema_weight = 2/(frame_rate+1)
inductance = 0.001
therm_conduct = 0.001
therm_conduct = 0.01
drain = False
drain_rate = 0.1
# === phase space ===
# heat equation
temp = 30*[0]
new_temp = 30*[0]
# wave equation
charge = 12*[0]
current = 30*[0]
@ -117,11 +156,13 @@ change_threshold = 0.15
def heat_evolution():
for e, f in cyc_edge_adj:
flow = therm_conduct*(current[e] - current[f])
current[e] -= flow
current[f] += flow
flow = therm_conduct*(temp[e] - temp[f])
new_temp[e] -= flow
new_temp[f] += flow
for e in range(30):
if drain:
current[v] *= 1 - drain_rate
new_temp[e] *= 1 - drain_rate
temp[e] = max(new_temp[e], 0)
def wave_evolution():
# use verlet integration, first updating the currents and then using the new
@ -137,6 +178,15 @@ def wave_evolution():
for v in range(12):
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):
new_litness = 1 - exp(-2*i*i)
if abs(new_litness - litness[e]) > change_threshold:
@ -146,71 +196,97 @@ def set_wave_light(e, i):
hit_bridge = False
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():
global drain, mode
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_j:
new_temp[0] += 10
elif event.key == pygame.K_SPACE:
drain = True
elif event.key == pygame.K_f:
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():
global drain, mode
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_j:
charge[0] += 100
charge[11] -= 100
elif event.key == pygame.K_k:
charge[5] += 100
charge[7] -= 100
elif event.key == pygame.K_SPACE:
drain = True
elif event.key == pygame.K_d:
mode = 0
elif event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
drain = False
elif event.type == pygame.QUIT:
quit()
def show_data(screen):
# light updates
global updates, new_updates
updates = ema_weight*new_updates + (1 - ema_weight)*updates
new_updates = 0
text = font.render('updates', True, (255, 255, 255))
screen.blit(text, (20, viewsize))
text = font.render(str(frame_rate * updates), True, (255, 255, 255))
screen.blit(text, (120, viewsize))
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
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))
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))
# 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))
# 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__':
# 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():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_j:
charge[0] += 100
charge[11] -= 100
elif event.key == pygame.K_k:
charge[5] += 100
charge[7] -= 100
elif event.key == pygame.K_SPACE:
drain = True
pygame.draw.aaline(screen, (255, 255, 255), (0, 0), (viewsize, viewsize))
elif event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
drain = False
elif event.type == pygame.QUIT:
quit()
if mode == 0:
handle_heat_events()
elif mode == 1:
handle_wave_events()
# clear screen
screen.blit(background, (0, 0))
# show data
# show data and instructions
show_data(screen)
# show state
for e in range(30):
set_wave_light(e, current[e])
# evolve state
wave_evolution()
##heat_evolution()
# show state and evolve 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):
set_wave_light(e, current[e])
wave_evolution()
# step
pygame.display.flip()