From 0a95017dee0d93b2ce78b4bf39d9d99ec91889b2 Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Sun, 22 Sep 2019 09:42:30 +0100 Subject: [PATCH] Reorg --- constants.py | 43 ++++++++++++++ cues.py | 138 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 159 +-------------------------------------------------- 3 files changed, 184 insertions(+), 156 deletions(-) create mode 100644 constants.py create mode 100644 cues.py diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..e906579 --- /dev/null +++ b/constants.py @@ -0,0 +1,43 @@ + +from flight.color import Color + + +MaskOuterRadius = 460 +MaskInnerRadius = 400 +BeadSeparation = 15 +BeadRadius = 5 +EyeSeparation = 160 +EyeXRadius = 140 +EyeYRadius = 160 +ThirdEyeOffset = 260 +ThirdEyeXRadius = 200 +ThirdEyeYRadius = 150 +PupilHeight = 25 +PupilWidth = 150 +EyeRimThickness = 50 +EyelinerThickness = 5 +NoseHeight = 240 +NoseWidth = 130 +NoseBottom = 25 +MouthOffset = 285 +MouthWidth = 180 +MouthHeight = 230 +TongueHeight = 180 +MouthCornerRadius = 20 +LipThickness = 50 +TriangleCount = 30 +TriangleWidth = 60 +TriangleHeight = 40 +TriangleRadius = 430 + +MaskColor = Color.hsv(0.09, 0.8, 0.25) +DarkMaskColor = MaskColor * 0.25 +TriangleColor = Color.hsv(0.11, 0.8, 1) +HoleColor = Color.white(1) +EyelinerColor = Color.green(0.5) +OddBeadColor = Color.red(1) +EvenBeadColor = Color.white(0) + + +server = FlightServer.ensure_threaded_instance() +client = FlightClient('http://192.168.178.32:8888') diff --git a/cues.py b/cues.py new file mode 100644 index 0000000..d84ed05 --- /dev/null +++ b/cues.py @@ -0,0 +1,138 @@ +#%% + +import math +import random + +from flight.case import * +from flight.color import Color +from flight.client import * +from flight.expressions import * +from flight.expressions import Expression +from flight.server import FlightServer + +from constants import * + + +#%% + +client.activate() + +with Cue('Q01', name='Mask', fadeIn=5, fadeOut=5): + Match('#mask').fader = 1 + +with Cue('Q02', name='Rotating mask', fadeIn=1, fadeOut=2): + period = 11 + count = t / period + Match('#master_mask').rotate = count % 1 * f + +with Cue('Q03', name='Multiple masks'): + period = 3 + scale = 1 / (1 + (t / period) // 1) + Match('#mask').scale = scale + Match('#mask Rect').width = container.width / scale + Match('#mask Rect').height = container.height / scale + +with Cue('Q04', name='Blinking eyes') as Q2: + period = 3 + duration = 0.2 + count = t / period + cycle = t % period + offset = beta('Q04.offset')[count] * (period - duration) + blink = 1 - when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0) + Match('.pupil > Rect').y = -PupilHeight / 2 * blink + Match('.pupil > Rect').height = PupilHeight * blink + +with Cue('Q05', name='Talking'): + period = 0.5 + duration = 0.1 + 0.2 * beta('Q04.duration')[count] + count = t / period + cycle = t % period + offset = beta('Q05.offset')[count] * (period - duration) + wag = when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0) + height = uniform('Q05.height')[count] * (TongueHeight - MouthCornerRadius * 2) + Match('.tongue > RoundedRect').height = TongueHeight - height * wag + +with Cue('Q06', name='Emoji'): + emoji = ['đŸ˜ŗ', '🎁', '🎉', '🤗', '💃', '🍰', '😉', '😸', '🐄', '🍆', 'â¤ī¸', 'â­ī¸', '😎', + '🛑', '✋', 'â€đŸƒâ€â™€ī¸', 'âœˆī¸', 'â˜šī¸', '🤕', 'đŸ˜ĸ', 'đŸ‘ē', 'đŸ’ĩ', '💰', '🤑'] + period = 0.5 + count = t / period + character = choose(uniform('Q06')[count], emoji) + Match('#symbol Text').text = character + +with Cue('Q07', name='Helmet', fadeIn=1, fadeOut=1): + Match('#helmet').fader = 1 + +with Cue('Q11', name='Rainbow triangles', fadeIn=1, fadeOut=1): + period = 5 + count = t / period + color = hsv(count + i / n, 1, 1) + Match('.triangle .left').color = color + Match('.triangle .right').color = color * 0.9 + +with Cue('Q12', name='Rotating triangles') as Q1: + period = 9 / maximum(f, 1e-6) + count = t / period + Match('#triangles').rotate = count + +with Cue('Q13', name='Spinning triangles', fadeIn=1, fadeOut=1): + period = 5 + count = t / period + scale = 2*sine((count + i / n) * 5) + Match('.triangle').rotate = count + Match('.triangle').scale = 1 + scale + Match('.triangle').y = -TriangleRadius - TriangleHeight * scale + +with Cue('Q14', name='Nightmare spots') as Q3: + period = 1 + count = t / period + Match('.bead.odd').scale = 2 * sine(count) + Match('.bead.even').scale = 2 * (1 - sine(count)) + +with Cue('Q21', name='Twinkling stars', fadeIn=1, fadeOut=1): + period = 1 + phase = uniform('Q21.phase')[i] + count = gt / period + phase + Match('#stars').fader = 1 + with Match('.star') as m: + m.x = (uniform('Q21.x', i)[count] - 0.5) * screen.width + m.y = (uniform('Q21.y', i)[count] - 0.5) * screen.height + Match('.star').scale = uniform('Q21.scale', i)[count] + Match('.star .fill').color = white(sine(count)) + +with Cue('Q22', name='Bouncing stars', fadeIn=1, fadeOut=1): + period = 1 + phase = uniform('Q21.phase')[i] + count = gt / period + phase + Match('#stars').fader = 1 + with Match('.star') as m: + m.x = (uniform('Q21.x', i)[count] - 0.5) * screen.width + m.y = (uniform('Q21.y', i)[count] - 0.5) * screen.height + m.rotate = count / 5 + m.scale = bounce(count) * 25 + Match('.star .outline').color = hsv(uniform('Q22.hue', i)[count], 1, bounce(count)) + +with Cue('Q23', name='Thin stars', fadeIn=1, fadeOut=1): + period = 9 + beta('Q23.period')[i] * 2 + phase = uniform('Q23.phase')[i] + count = t / period + phase + hue = quad(count, uniform('Q23.hue', i)[count], uniform('Q23.hue', i)[count + 1]) + Match('#stars').fader = 1 + with Match('.star') as m: + m.lineWidth = sine(count) / 10 + m.scale = 50 + m.x = (uniform('Q23.x')[i] - 0.5) * screen.width + m.y = (uniform('Q23.y')[i] - 0.5) * screen.height + m.rotate = count / 10 + Match('.star .outline').color = hsv(hue, 0.8, 1) + +with Cue('Q24', name='Rushing stars', fadeIn=1, fadeOut=1): + period = 3 + phase = uniform('Q21.phase')[i] + count = gt / period + phase + Match('#stars').fader = 1 + with Match('.star') as m: + m.x = (uniform('Q24.x', i)[count] - 0.5) * screen.width * 2 * (count % 1) + m.y = (uniform('Q24.y', i)[count] - 0.5) * screen.height * 2 * (count % 1) + m.color = white(sine(count)) + m.scale = count % 1 diff --git a/setup.py b/setup.py index ec9e897..d5a868c 100644 --- a/setup.py +++ b/setup.py @@ -10,52 +10,13 @@ from flight.expressions import * from flight.expressions import Expression from flight.server import FlightServer - -server = FlightServer.ensure_threaded_instance() -client = FlightClient() #('http://192.168.178.32:8888') +from constants import * #%% client.activate() -MaskOuterRadius = 460 -MaskInnerRadius = 400 -BeadSeparation = 15 -BeadRadius = 5 -EyeSeparation = 160 -EyeXRadius = 140 -EyeYRadius = 160 -ThirdEyeOffset = 260 -ThirdEyeXRadius = 200 -ThirdEyeYRadius = 150 -PupilHeight = 25 -PupilWidth = 150 -EyeRimThickness = 50 -EyelinerThickness = 5 -NoseHeight = 240 -NoseWidth = 130 -NoseBottom = 25 -MouthOffset = 285 -MouthWidth = 180 -MouthHeight = 230 -TongueHeight = 180 -MouthCornerRadius = 20 -LipThickness = 50 -TriangleCount = 30 -TriangleWidth = 60 -TriangleHeight = 40 -TriangleRadius = 430 - -MaskColor = Color.hsv(0.09, 0.8, 0.25) -DarkMaskColor = MaskColor * 0.25 -TriangleColor = Color.hsv(0.11, 0.8, 1) -HoleColor = Color.white(1) -EyelinerColor = Color.green(0.5) -OddBeadColor = Color.red(1) -EvenBeadColor = Color.white(0) - - def SplitTriangle(width, height, bottom=0, color=TriangleColor, **kwargs): with Group(**kwargs): for side, multiplier in [('left', -1), ('right', 1)]: @@ -160,9 +121,9 @@ with Screen('main', width=1920, height=1080) as screen: with Path(id='symbol', x=0, y=-ThirdEyeOffset): Ellipse(0, 0, radiusX=ThirdEyeXRadius - EyeRimThickness, radiusY=ThirdEyeYRadius - EyeRimThickness) Text(font='120px NotoColorEmoji, NotoEmoji, emoji', textAlign='center', textBaseline='middle', color=HoleColor) - with Group('stars', composite='lighter', fader=0): + with Group('stars', composite='lighter', x=screen.width / 2, y=screen.height / 2, fader=0): for j in range(100): - with Group(x=screen.width / 2, y=screen.height / 2, tags='star', lineWidth=2): + with Group(tags='star', lineWidth=2): with Path(tags='fill'): Star(10) FillPath() @@ -172,117 +133,3 @@ with Screen('main', width=1920, height=1080) as screen: with Path(id='mask', pattern='mask_pattern', fader=0): Rect(0, 0, container.width, container.height) FillPath() - - -#%% - -client.activate() - -with Cue('Q01', name='Mask', fadeIn=5, fadeOut=5): - Match('#mask').fader = 1 - -with Cue('Q02', name='Rotating mask', fadeIn=1, fadeOut=2): - period = 11 - count = t / period - Match('#master_mask').rotate = count % 1 * f - -with Cue('Q03', name='Multiple masks'): - period = 3 - scale = 1 / (1 + (t / period) // 1) - Match('#mask').scale = scale - Match('#mask Rect').width = container.width / scale - Match('#mask Rect').height = container.height / scale - -with Cue('Q04', name='Blinking eyes') as Q2: - period = 3 - duration = 0.2 - count = t / period - cycle = t % period - offset = beta('Q04.offset')[count] * (period - duration) - blink = 1 - when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0) - Match('.pupil > Rect').y = -PupilHeight / 2 * blink - Match('.pupil > Rect').height = PupilHeight * blink - -with Cue('Q05', name='Talking'): - period = 0.5 - duration = 0.1 + 0.2 * beta('Q04.duration')[count] - count = t / period - cycle = t % period - offset = beta('Q05.offset')[count] * (period - duration) - wag = when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0) - height = uniform('Q05.height')[count] * (TongueHeight - MouthCornerRadius * 2) - Match('.tongue > RoundedRect').height = TongueHeight - height * wag - -with Cue('Q06', name='Emoji'): - emoji = ['đŸ˜ŗ', '🎁', '🎉', '🤗', '💃', '🍰', '😉', '😸', '🐄', '🍆', 'â¤ī¸', 'â­ī¸', '😎', - '🛑', '✋', 'â€đŸƒâ€â™€ī¸', 'âœˆī¸', 'â˜šī¸', '🤕', 'đŸ˜ĸ', 'đŸ‘ē', 'đŸ’ĩ', '💰', '🤑'] - period = 0.5 - count = t / period - character = choose(uniform('Q06')[count], emoji) - Match('#symbol Text').text = character - -with Cue('Q07', name='Helmet', fadeIn=1, fadeOut=1): - Match('#helmet').fader = 1 - -with Cue('Q11', name='Rainbow triangles', fadeIn=1, fadeOut=1): - period = 5 - count = t / period - color = hsv(count + i / n, 1, 1) - Match('.triangle .left').color = color - Match('.triangle .right').color = color * 0.9 - -with Cue('Q12', name='Rotating triangles') as Q1: - period = 9 / maximum(f, 1e-6) - count = t / period - Match('#triangles').rotate = count - -with Cue('Q13', name='Spinning triangles', fadeIn=1, fadeOut=1): - period = 5 - count = t / period - scale = 2*sine((count + i / n) * 5) - Match('.triangle').rotate = count - Match('.triangle').scale = 1 + scale - Match('.triangle').y = -TriangleRadius - TriangleHeight * scale - -with Cue('Q14', name='Nightmare spots') as Q3: - period = 1 - count = t / period - Match('.bead.odd').scale = 2 * sine(count) - Match('.bead.even').scale = 2 * (1 - sine(count)) - -with Cue('Q21', name='Twinkling stars', fadeIn=1, fadeOut=1): - period = 1 - phase = uniform('Q21.phase')[i] - count = gt / period + phase - Match('#stars').fader = 1 - with Match('.star') as m: - m.x = uniform('Q21.x', i)[count] * screen.width - m.y = uniform('Q21.y', i)[count] * screen.height - Match('.star').scale = uniform('Q21.scale', i)[count] - Match('.star .fill').color = white(sine(count)) - -with Cue('Q22', name='Bouncing stars', fadeIn=1, fadeOut=1): - period = 1 - phase = uniform('Q21.phase')[i] - count = gt / period + phase - Match('#stars').fader = 1 - with Match('.star') as m: - m.x = uniform('Q21.x', i)[count] * screen.width - m.y = uniform('Q21.y', i)[count] * screen.height - m.rotate = count / 5 - m.scale = bounce(count) * 25 - Match('.star .outline').color = hsv(uniform('Q22.hue', i)[count], 1, bounce(count)) - -with Cue('Q23', name='Thin stars', fadeIn=1, fadeOut=1): - period = 9 + beta('Q23.period')[i] * 2 - phase = uniform('Q23.phase')[i] - count = t / period + phase - hue = quad(count, uniform('Q23.hue', i)[count], uniform('Q23.hue', i)[count + 1]) - Match('#stars').fader = 1 - with Match('.star') as m: - m.lineWidth = sine(count) / 10 - m.scale = 50 - m.x = uniform('Q23.x')[i] * screen.width - m.y = uniform('Q23.y')[i] * screen.height - m.rotate = count / 10 - Match('.star .outline').color = hsv(hue, 0.8, 1)