Add thresholding to reduce light update frequency
It's not very effective, and Glen says things look fine without, so I'll abandon this branch for now.
This commit is contained in:
parent
add9bda080
commit
963d68196e
@ -55,8 +55,8 @@ clock = pygame.time.Clock()
|
|||||||
|
|
||||||
# --- copied from firestar.py
|
# --- copied from firestar.py
|
||||||
|
|
||||||
b = phue.Bridge('172.18.130.12')
|
##b = phue.Bridge('172.18.130.12')
|
||||||
##b = None
|
b = None
|
||||||
Nedges = 30;
|
Nedges = 30;
|
||||||
edgecode = [None] * Nedges;
|
edgecode = [None] * Nedges;
|
||||||
|
|
||||||
@ -72,7 +72,9 @@ lasthue = 65535
|
|||||||
fullbright = 254
|
fullbright = 254
|
||||||
fullsat = 254
|
fullsat = 254
|
||||||
|
|
||||||
# --- control methods
|
# --- control methods and diagnostics
|
||||||
|
|
||||||
|
updates = 0
|
||||||
|
|
||||||
def set_light_hsv(e, color, hit_bridge):
|
def set_light_hsv(e, color, hit_bridge):
|
||||||
command = {
|
command = {
|
||||||
@ -80,8 +82,11 @@ def set_light_hsv(e, color, hit_bridge):
|
|||||||
'bri' : color[2]*fullbright,
|
'bri' : color[2]*fullbright,
|
||||||
'sat' : color[1]*fullsat
|
'sat' : color[1]*fullsat
|
||||||
}
|
}
|
||||||
if hit_bridge and b != None:
|
if hit_bridge:
|
||||||
|
if b != None:
|
||||||
b.set_light(edges[e].light_id, command)
|
b.set_light(edges[e].light_id, command)
|
||||||
|
global updates
|
||||||
|
updates += 1
|
||||||
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]])
|
||||||
|
|
||||||
@ -101,7 +106,7 @@ drain_rate = 0.1
|
|||||||
charge = 12*[0]
|
charge = 12*[0]
|
||||||
current = 30*[0]
|
current = 30*[0]
|
||||||
|
|
||||||
last_litness = 30*[float("inf")]
|
litness = 30*[float("inf")]
|
||||||
change_threshold = 0.05
|
change_threshold = 0.05
|
||||||
|
|
||||||
# === main loop ===
|
# === main loop ===
|
||||||
@ -129,23 +134,34 @@ def wave_evolution():
|
|||||||
charge[v] *= 1 - drain_rate
|
charge[v] *= 1 - drain_rate
|
||||||
|
|
||||||
def set_wave_light(e, i):
|
def set_wave_light(e, i):
|
||||||
litness = 1 - exp(-2*i*i)
|
new_litness = 1 - exp(-2*i*i)
|
||||||
hit_bridge = abs(litness - last_litness[e]) > change_threshold
|
if abs(new_litness - litness[e]) > change_threshold:
|
||||||
set_light_hsv(e, (0.45 + litness*0.25, 1 - 0.5*litness*litness, litness), hit_bridge)
|
hit_bridge = True
|
||||||
if hit_bridge:
|
litness[e] = new_litness
|
||||||
last_litness[e] = litness
|
else:
|
||||||
|
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 show_data(screen):
|
def show_data(screen):
|
||||||
|
# light updates
|
||||||
|
text = font.render('updates', True, (255, 255, 255))
|
||||||
|
screen.blit(text, (20, viewsize))
|
||||||
|
text = font.render(str(updates), True, (255, 255, 255))
|
||||||
|
screen.blit(text, (120, viewsize))
|
||||||
|
|
||||||
|
# energy
|
||||||
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))
|
||||||
screen.blit(text, (20, viewsize))
|
|
||||||
text = font.render(str(energy), True, (255, 255, 255))
|
|
||||||
screen.blit(text, (120, viewsize))
|
|
||||||
text = font.render('charge[0]', True, (255, 255, 255))
|
|
||||||
screen.blit(text, (20, 30 + viewsize))
|
screen.blit(text, (20, 30 + viewsize))
|
||||||
text = font.render(str(charge[0]), True, (255, 255, 255))
|
text = font.render(str(energy), True, (255, 255, 255))
|
||||||
screen.blit(text, (120, 30 + viewsize))
|
screen.blit(text, (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))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# set up background
|
# set up background
|
||||||
background = pygame.Surface(screen.get_size()).convert()
|
background = pygame.Surface(screen.get_size()).convert()
|
||||||
|
Loading…
Reference in New Issue
Block a user