diff --git a/interactions.py b/interactions.py index e5c8084..a35830d 100644 --- a/interactions.py +++ b/interactions.py @@ -1,6 +1,8 @@ +#!/usr/bin/python3 + from math import pi, cos, sin, exp -import pygame, colorsys +import phue, pygame, colorsys # === graph data === @@ -12,7 +14,7 @@ vertices = [(viewsize*(1 + shrink*x)/2, viewsize*(1 + shrink*y)/2) for x, y in ] # edges as vertex pairs. FireStar will rest on vertices 6 (A), 5 (B), 7 (C) -edges = [ +vertex_adj = [ (0, 1), (0, 3), (0, 5), (0, 7), (0, 9), (2, 8), (2, 6), (6, 10), (10, 4), (4, 8), (2, 9), (2, 11), (2, 5), @@ -41,6 +43,50 @@ cyc_edge_adj = [ (14, 11), (11, 23), (23, 20), (20, 17), (17, 14) ] +# === pygame setup === + +pygame.init() +screen = pygame.display.set_mode((viewsize, viewsize + 100)) +pygame.display.set_caption('Preview') +font = pygame.font.Font(None, 25) +clock = pygame.time.Clock() + +# === bridge setup and control === + +# --- copied from firestar.py + +b = phue.Bridge('172.18.130.12') +##b = None +Nedges = 30; +edgecode = [None] * Nedges; + +# The edges are numbered as in info/SSDedges.obj; enter the two-letter code for +# the lightstrip inserted through each edge in the block below: + +exec(open("edgecodes.py").read()) + +if b != None: + edges = [ b[code] for code in edgecode ] + +lasthue = 65535 +fullbright = 254 +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 + } + ) + 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]]) + # === interaction parameters === frame_rate = 24 @@ -71,10 +117,10 @@ def wave_evolution(): # use verlet integration, first updating the currents and then using the new # currents to update the charges. for e in range(30): - u, v = edges[e] + u, v = vertex_adj[e] current[e] += inductance*(charge[u] - charge[v]) for e in range(30): - u, v = edges[e] + u, v = vertex_adj[e] charge[u] -= current[e] charge[v] += current[e] if drain: @@ -93,13 +139,6 @@ def show_data(screen): screen.blit(text, (120, 30 + viewsize)) if __name__ == '__main__': - # set up display and clock - pygame.init() - screen = pygame.display.set_mode((viewsize, viewsize + 100)) - pygame.display.set_caption('Preview') - font = pygame.font.Font(None, 25) - clock = pygame.time.Clock() - # set up background background = pygame.Surface(screen.get_size()).convert() background.fill((32, 32, 32)) @@ -137,14 +176,7 @@ if __name__ == '__main__': # show state for e in range(30): litness = 1 - exp(-2*current[e]*current[e]) - color = colorsys.hsv_to_rgb(0.45 + litness*0.25, 1 - 0.5*litness*litness, litness) - ##color = colorsys.hsv_to_rgb(litness*0.167, 1 - 0.5*litness*litness, litness) - pygame.draw.aaline( - screen, - tuple(255*c for c in color), - vertices[edges[e][0]], - vertices[edges[e][1]], - ) + set_light_hsv(e, (0.45 + litness*0.25, 1 - 0.5*litness*litness, litness)) # evolve state wave_evolution()