Set up heat/wave mode switch
This commit is contained in:
parent
a52ed7a90e
commit
9dc6098ff3
117
interactions.py
117
interactions.py
@ -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))
|
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
|
||||||
@ -163,13 +197,15 @@ def set_wave_light(e, i):
|
|||||||
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 handle_heat_events():
|
||||||
global drain
|
global drain, mode
|
||||||
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:
|
||||||
new_temp[0] += 10
|
new_temp[0] += 10
|
||||||
elif event.key == pygame.K_SPACE:
|
elif event.key == pygame.K_SPACE:
|
||||||
drain = True
|
drain = True
|
||||||
|
elif event.key == pygame.K_f:
|
||||||
|
mode = 1
|
||||||
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
|
||||||
@ -177,7 +213,7 @@ def handle_heat_events():
|
|||||||
quit()
|
quit()
|
||||||
|
|
||||||
def handle_wave_events():
|
def handle_wave_events():
|
||||||
global drain
|
global drain, mode
|
||||||
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:
|
||||||
@ -188,6 +224,8 @@ 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:
|
||||||
|
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
|
||||||
@ -199,57 +237,56 @@ def show_data(screen):
|
|||||||
global updates, new_updates
|
global updates, new_updates
|
||||||
updates = ema_weight*new_updates + (1 - ema_weight)*updates
|
updates = ema_weight*new_updates + (1 - ema_weight)*updates
|
||||||
new_updates = 0
|
new_updates = 0
|
||||||
text = font.render('updates', True, (255, 255, 255))
|
updates_value = font.render(str(frame_rate * updates), True, (255, 255, 255))
|
||||||
screen.blit(text, (20, viewsize))
|
screen.blit(updates_label, (20, viewsize))
|
||||||
text = font.render(str(frame_rate * updates), True, (255, 255, 255))
|
screen.blit(updates_value, (120, viewsize))
|
||||||
screen.blit(text, (120, viewsize))
|
|
||||||
|
|
||||||
# energy
|
# energy
|
||||||
##energy = 0.5*(sum(q*q for q in charge) + inductance*sum(i*i for i in current))
|
if mode == 0:
|
||||||
energy = sum(temp)
|
energy = sum(temp)
|
||||||
text = font.render('energy', True, (255, 255, 255))
|
elif mode == 1:
|
||||||
screen.blit(text, (20, 30 + viewsize))
|
energy = 0.5*(sum(q*q for q in charge) + inductance*sum(i*i for i in current))
|
||||||
text = font.render(str(energy), True, (255, 255, 255))
|
energy_value = font.render(str(energy), True, (255, 255, 255))
|
||||||
screen.blit(text, (120, 30 + viewsize))
|
screen.blit(energy_label, (20, 30 + viewsize))
|
||||||
|
screen.blit(energy_value, (120, 30 + viewsize))
|
||||||
|
|
||||||
# charge[0]
|
# a position
|
||||||
##text = font.render('charge[0]', True, (255, 255, 255))
|
##position_value = None
|
||||||
text = font.render('temp[0]', True, (255, 255, 255))
|
if mode == 0:
|
||||||
screen.blit(text, (20, 60 + viewsize))
|
position_value = font.render(str(temp[0]), True, (255, 255, 255))
|
||||||
##text = font.render(str(charge[0]), True, (255, 255, 255))
|
elif mode == 1:
|
||||||
text = font.render(str(temp[0]), True, (255, 255, 255))
|
position_value = font.render(str(charge[0]), True, (255, 255, 255))
|
||||||
screen.blit(text, (120, 60 + viewsize))
|
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__':
|
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))
|
|
||||||
text = font.render('press [j] 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:
|
while True:
|
||||||
# handle events
|
# handle events
|
||||||
##handle_wave_events()
|
if mode == 0:
|
||||||
handle_heat_events()
|
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
|
# show data and instructions
|
||||||
show_data(screen)
|
show_data(screen)
|
||||||
|
|
||||||
# show state
|
# show state and evolve state
|
||||||
for e in range(30):
|
if mode == 0:
|
||||||
##set_wave_light(e, current[e])
|
for e in range(30):
|
||||||
set_heat_light(e, temp[e])
|
set_heat_light(e, temp[e])
|
||||||
|
heat_evolution()
|
||||||
# evolve state
|
elif mode == 1:
|
||||||
##wave_evolution()
|
for e in range(30):
|
||||||
heat_evolution()
|
set_wave_light(e, current[e])
|
||||||
|
wave_evolution()
|
||||||
|
|
||||||
# step
|
# step
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
Loading…
Reference in New Issue
Block a user