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:
parent
7b96b8e974
commit
add9bda080
@ -74,18 +74,16 @@ fullsat = 254
|
|||||||
|
|
||||||
# --- control methods
|
# --- control methods
|
||||||
|
|
||||||
def set_light_hsv(edge, color):
|
def set_light_hsv(e, color, hit_bridge):
|
||||||
if b != None:
|
command = {
|
||||||
b.set_light(
|
'hue' : color[0]*lasthue,
|
||||||
edges[edge].light_id,
|
'bri' : color[2]*fullbright,
|
||||||
{
|
'sat' : color[1]*fullsat
|
||||||
'hue' : color[0]*lasthue,
|
}
|
||||||
'bri' : color[2]*fullbright,
|
if hit_bridge and b != None:
|
||||||
'sat' : color[1]*fullsat
|
b.set_light(edges[e].light_id, command)
|
||||||
}
|
|
||||||
)
|
|
||||||
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[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 ===
|
# === interaction parameters ===
|
||||||
|
|
||||||
@ -103,6 +101,9 @@ drain_rate = 0.1
|
|||||||
charge = 12*[0]
|
charge = 12*[0]
|
||||||
current = 30*[0]
|
current = 30*[0]
|
||||||
|
|
||||||
|
last_litness = 30*[float("inf")]
|
||||||
|
change_threshold = 0.05
|
||||||
|
|
||||||
# === main loop ===
|
# === main loop ===
|
||||||
|
|
||||||
def heat_evolution():
|
def heat_evolution():
|
||||||
@ -127,6 +128,13 @@ 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_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):
|
def show_data(screen):
|
||||||
energy = 0.5*(sum(q*q for q in charge) + inductance*sum(i*i for i in current))
|
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))
|
text = font.render('energy', True, (255, 255, 255))
|
||||||
@ -175,8 +183,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# show state
|
# show state
|
||||||
for e in range(30):
|
for e in range(30):
|
||||||
litness = 1 - exp(-2*current[e]*current[e])
|
set_wave_light(e, current[e])
|
||||||
set_light_hsv(e, (0.45 + litness*0.25, 1 - 0.5*litness*litness, litness))
|
|
||||||
|
|
||||||
# evolve state
|
# evolve state
|
||||||
wave_evolution()
|
wave_evolution()
|
||||||
|
Loading…
Reference in New Issue
Block a user