More mask-like; playing with patterns

This commit is contained in:
2019-09-18 19:05:06 +01:00
parent 9c4f85f865
commit 34ac536339

View File

@ -2,8 +2,8 @@
from flight.server import FlightServer from flight.server import FlightServer
server = FlightServer.ensure_threaded_instance()
server = FlightServer.ensure_threaded_instance()
#%% #%%
@ -18,9 +18,7 @@ from flight.expressions import *
client = FlightClient() client = FlightClient()
#%% def RoundedRect(x, y, width, height, radius):
def RoundedRectangle(x, y, width, height, radius):
x2 = x + width x2 = x + width
y2 = y + height y2 = y + height
MoveTo(x, y + radius) MoveTo(x, y + radius)
@ -40,55 +38,76 @@ client.activate()
MaskRadius = 500 MaskRadius = 500
EyeSeparation = 175 EyeSeparation = 175
EyeRadius = 120 EyeXRadius = 120
PupilHeight = 50 EyeYRadius = 150
PupilHeight = 30
PupilWidth = 150
EyeOutsideThickness = 50 EyeOutsideThickness = 50
NoseHeight = 300 NoseHeight = 250
NoseWidth = 100 NoseWidth = 130
MouthOffset = 270 NoseUpturn = 25
MouthWidth = 200 MouthOffset = 280
MouthWidth = 180
MouthHeight = 120 MouthHeight = 120
MouthCornerRadius = 40 MouthCornerRadius = 30
LipThickness = 50 LipThickness = 50
TriangleCount = 50 TriangleCount = 30
TriangleHeight = 50 TriangleHeight = 30
TriangleSeparation = 10 TriangleSeparation = 20
OuterTriangleRadius = 450 OuterTriangleRadius = 450
InnerTriangleRadius = 440 InnerTriangleRadius = 430
with Screen('main', width=1920, height=1080) as screen: with Screen('main', width=1920, height=1080) as screen:
with Pattern('beads', width=30, height=30) as beads:
for x in range(3):
for y in range(3):
with Path(tags='odd' if (x + y) % 2 == 1 else 'even',
color='red' if (x + y) % 2 == 1 else 'blue',
x=x * beads.width / 2, y=y * beads.height / 2):
Ellipse(0, 0, beads.width / 5, beads.height / 5)
FillPath()
with Group('mask', x=screen.width/2, y=screen.height/2): with Group('mask', x=screen.width/2, y=screen.height/2):
with Path(id='background', color='#330'): with Group('background'):
Ellipse(x=0, y=0, radiusX=MaskRadius, radiusY=MaskRadius) with Path(tags='outer', color='#330'):
FillPath() Ellipse(x=0, y=0, radiusX=MaskRadius, radiusY=MaskRadius)
FillPath()
with Path(tags='inner', pattern='beads'):
Ellipse(x=0, y=0, radiusX=InnerTriangleRadius, radiusY=InnerTriangleRadius)
FillPath()
with Group('eyes'): with Group('eyes'):
for side, multiplier in [('left', -1), ('right', 1)]: for side, multiplier in [('left', -1), ('right', 1)]:
with Group(tags={'eye', side}, x=multiplier * (EyeSeparation/2 + EyeRadius)): with Group(tags={'eye', side}, x=multiplier * (EyeSeparation/2 + EyeRadius)):
with Path(tags='inside'): with Path(tags='inside', color='#330'):
Ellipse(x=0, y=0, radiusX=EyeRadius, radiusY=EyeRadius) Ellipse(x=0, y=0, radiusX=EyeXRadius, radiusY=EyeYRadius)
FillPath()
with Path(tags='pupil', color='white'): with Path(tags='pupil', color='white'):
Rect(-EyeRadius, -PupilHeight / 2, EyeRadius * 2, PupilHeight) Rect(-PupilWidth / 2, -PupilHeight / 2, PupilWidth, PupilHeight)
FillPath() FillPath()
with Path(tags='outside', lineWidth=EyeOutsideThickness, color='yellow'): with Path(tags='outside', lineWidth=EyeOutsideThickness, color='#072'):
Ellipse(x=0, y=0, radiusX=EyeRadius + EyeOutsideThickness/2, radiusY=EyeRadius + EyeOutsideThickness / 2) Ellipse(x=0, y=0, radiusX=EyeXRadius + EyeOutsideThickness/2, radiusY=EyeYRadius + EyeOutsideThickness / 2)
StrokePath() StrokePath()
with Group('nose', color='yellow'): with Group('nose', color='#fc3'):
for side, multiplier in [('left', -1), ('right', 1)]: for side, multiplier in [('left', -1), ('right', 1)]:
with Path(tags={'nose', side}): with Path(tags={'nose', side}, fader=0.9 + multiplier*.1):
MoveTo(multiplier * NoseWidth / 2, NoseHeight / 2) MoveTo(multiplier * NoseWidth / 2, NoseHeight / 2)
LineTo(0, -NoseHeight / 2) LineTo(0, -NoseHeight / 2)
LineTo(0, NoseHeight / 2) LineTo(0, NoseHeight / 2 - NoseUpturn)
FillPath() FillPath()
with Path(tags='nose bottom', fader=0.5):
MoveTo(-NoseWidth / 2, NoseHeight / 2)
LineTo(0, NoseHeight / 2 - NoseUpturn)
LineTo(NoseWidth / 2, NoseHeight / 2)
FillPath()
with Group('mouth', y=MouthOffset): with Group('mouth', y=MouthOffset):
with Path(tags='inside', color='white'): with Path(tags='inside', color='white'):
RoundedRectangle(-MouthWidth / 2, -MouthHeight / 2, MouthWidth, MouthHeight, MouthCornerRadius) RoundedRect(-MouthWidth / 2, -MouthHeight / 2, MouthWidth, MouthHeight, MouthCornerRadius)
FillPath() FillPath()
with Path(tags='outside', color='yellow', lineWidth=LipThickness): with Path(tags='outside', color='#330', lineWidth=LipThickness):
RoundedRectangle(-(MouthWidth + LipThickness) / 2, -(MouthHeight + LipThickness) / 2, RoundedRect(-(MouthWidth + LipThickness) / 2, -(MouthHeight + LipThickness) / 2,
MouthWidth + LipThickness, MouthHeight + LipThickness, MouthCornerRadius + LipThickness) MouthWidth + LipThickness, MouthHeight + LipThickness, MouthCornerRadius + LipThickness)
StrokePath() StrokePath()
with Group('triangles'): with Group('triangles', color='#fc3'):
with Group('outer', color='yellow'): with Group('outer'):
triangle_width = 2*math.pi * OuterTriangleRadius / TriangleCount - TriangleSeparation triangle_width = 2*math.pi * OuterTriangleRadius / TriangleCount - TriangleSeparation
for i in range(TriangleCount): for i in range(TriangleCount):
with Group(rotate=i / TriangleCount): with Group(rotate=i / TriangleCount):
@ -97,7 +116,7 @@ with Screen('main', width=1920, height=1080) as screen:
LineTo(0, -TriangleHeight) LineTo(0, -TriangleHeight)
LineTo(triangle_width / 2, 0) LineTo(triangle_width / 2, 0)
FillPath() FillPath()
with Group('inner', color='yellow'): with Group('inner'):
triangle_width = 2*math.pi * InnerTriangleRadius / TriangleCount - TriangleSeparation triangle_width = 2*math.pi * InnerTriangleRadius / TriangleCount - TriangleSeparation
for i in range(TriangleCount): for i in range(TriangleCount):
with Group(rotate=i / TriangleCount): with Group(rotate=i / TriangleCount):
@ -119,14 +138,22 @@ with Cue('Q1', name='Spinning triangles') as Q1:
Match('#inner').rotate = -count Match('#inner').rotate = -count
with Cue('Q2', name='Blinking eyes') as Q2: with Cue('Q2', name='Blinking eyes') as Q2:
period = 5 period = 3
duration = 0.5 duration = 0.2
count = t / period count = t / period
cycle = t % period cycle = t % period
offset = beta('Q2.offset')[count] * (period - duration) offset = beta('Q2.offset')[count] * (period - duration)
blink = 1 - when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0) blink = 1 - when((cycle > offset) & (cycle < offset + duration), impulse((cycle - offset) / duration), 0)
Match('.pupil > Rect').y = -PupilHeight / 2 * blink Match('.pupil > Rect').y = -PupilHeight / 2 * blink
Match('.pupil > Rect').height = PupilHeight * blink Match('.pupil > Rect').height = PupilHeight * blink
start('#Q1') with Cue('Q3', name='Nightmare spots') as Q3:
period = 1
count = t / period
Match('#beads .odd').scale = 1.5 * sine(count)
Match('#beads .even').scale = 1.5 * (1 - sine(count))
#%%
client.start('#Q1')