Set up heat/wave mode switch
This commit is contained in:
parent
a52ed7a90e
commit
9dc6098ff3
107
interactions.py
107
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))
|
||||
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
|
||||
@ -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)
|
||||
|
||||
def handle_heat_events():
|
||||
global drain
|
||||
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
|
||||
@ -177,7 +213,7 @@ def handle_heat_events():
|
||||
quit()
|
||||
|
||||
def handle_wave_events():
|
||||
global drain
|
||||
global drain, mode
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_j:
|
||||
@ -188,6 +224,8 @@ def handle_wave_events():
|
||||
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
|
||||
@ -199,57 +237,56 @@ def show_data(screen):
|
||||
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))
|
||||
if mode == 0:
|
||||
energy = sum(temp)
|
||||
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))
|
||||
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))
|
||||
text = font.render('temp[0]', True, (255, 255, 255))
|
||||
screen.blit(text, (20, 60 + viewsize))
|
||||
##text = font.render(str(charge[0]), True, (255, 255, 255))
|
||||
text = font.render(str(temp[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))
|
||||
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:
|
||||
# handle events
|
||||
##handle_wave_events()
|
||||
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
|
||||
# show state and evolve state
|
||||
if mode == 0:
|
||||
for e in range(30):
|
||||
##set_wave_light(e, current[e])
|
||||
set_heat_light(e, temp[e])
|
||||
|
||||
# evolve state
|
||||
##wave_evolution()
|
||||
heat_evolution()
|
||||
elif mode == 1:
|
||||
for e in range(30):
|
||||
set_wave_light(e, current[e])
|
||||
wave_evolution()
|
||||
|
||||
# step
|
||||
pygame.display.flip()
|
||||
|
Loading…
Reference in New Issue
Block a user