Try to debug out-of-range index

Seems to be in the `color` tuple in set_light_hsv, but doesn't
show up in debugging.
This commit is contained in:
Aaron Fenyes 2019-09-28 22:16:42 +02:00
parent 7b96b8e974
commit add9bda080
1 changed files with 20 additions and 13 deletions

View File

@ -74,18 +74,16 @@ fullsat = 254
# --- control methods
def set_light_hsv(edge, color):
if b != None:
b.set_light(
edges[edge].light_id,
{
'hue' : color[0]*lasthue,
'bri' : color[2]*fullbright,
'sat' : color[1]*fullsat
}
)
def set_light_hsv(e, color, hit_bridge):
command = {
'hue' : color[0]*lasthue,
'bri' : color[2]*fullbright,
'sat' : color[1]*fullsat
}
if hit_bridge and b != None:
b.set_light(edges[e].light_id, command)
rgb_color = tuple(255*c for c in colorsys.hsv_to_rgb(*color))
pygame.draw.aaline(screen, rgb_color, vertices[vertex_adj[edge][0]], vertices[vertex_adj[edge][1]])
pygame.draw.aaline(screen, rgb_color, vertices[vertex_adj[e][0]], vertices[vertex_adj[e][1]])
# === interaction parameters ===
@ -103,6 +101,9 @@ drain_rate = 0.1
charge = 12*[0]
current = 30*[0]
last_litness = 30*[float("inf")]
change_threshold = 0.05
# === main loop ===
def heat_evolution():
@ -127,6 +128,13 @@ def wave_evolution():
for v in range(12):
charge[v] *= 1 - drain_rate
def set_wave_light(e, i):
litness = 1 - exp(-2*i*i)
hit_bridge = abs(litness - last_litness[e]) > change_threshold
set_light_hsv(e, (0.45 + litness*0.25, 1 - 0.5*litness*litness, litness), hit_bridge)
if hit_bridge:
last_litness[e] = litness
def show_data(screen):
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))
@ -175,8 +183,7 @@ if __name__ == '__main__':
# show state
for e in range(30):
litness = 1 - exp(-2*current[e]*current[e])
set_light_hsv(e, (0.45 + litness*0.25, 1 - 0.5*litness*litness, litness))
set_wave_light(e, current[e])
# evolve state
wave_evolution()