import math from flight.case import * from flight.client import * from flight.expressions import * client = FlightClient() #%% def RoundedRectangle(x, y, width, height, radius): x2 = x + width y2 = y + height MoveTo(x, y + radius) QuadraticCurveTo(x + radius, y, x, y) LineTo(x2 - radius, y) QuadraticCurveTo(x2, y + radius, x2, y) LineTo(x2, y2 - radius) QuadraticCurveTo(x2 - radius, y2, x2, y2) LineTo(x + radius, y2) QuadraticCurveTo(x, y2 - radius, x, y2) ClosePath() #%% client.activate() MaskRadius = 500 EyeSeparation = 175 EyeRadius = 120 PupilHeight = 50 EyeOutsideThickness = 50 NoseHeight = 300 NoseWidth = 100 MouthOffset = 270 MouthWidth = 200 MouthHeight = 120 MouthCornerRadius = 40 LipThickness = 50 TriangleCount = 50 TriangleHeight = 50 TriangleSeparation = 10 OuterTriangleRadius = 450 InnerTriangleRadius = 440 with Screen('main', width=1920, height=1080) as screen: with Group('mask', x=screen.width/2, y=screen.height/2): with Path(id='background', color='#330'): Ellipse(x=0, y=0, radiusX=MaskRadius, radiusY=MaskRadius) FillPath() with Group('eyes'): for side, multiplier in [('left', -1), ('right', 1)]: with Group(tags={'eye', side}, x=multiplier * (EyeSeparation/2 + EyeRadius)): with Path(tags='inside'): Ellipse(x=0, y=0, radiusX=EyeRadius, radiusY=EyeRadius) with Path(tags='pupil', color='white'): Rect(-EyeRadius, -PupilHeight / 2, EyeRadius * 2, PupilHeight) FillPath() with Path(tags='outside', lineWidth=EyeOutsideThickness, color='yellow'): Ellipse(x=0, y=0, radiusX=EyeRadius + EyeOutsideThickness/2, radiusY=EyeRadius + EyeOutsideThickness / 2) StrokePath() with Group('nose', color='yellow'): for side, multiplier in [('left', -1), ('right', 1)]: with Path(tags={'nose', side}): MoveTo(multiplier * NoseWidth / 2, NoseHeight / 2) LineTo(0, -NoseHeight / 2) LineTo(0, NoseHeight / 2) FillPath() with Group('mouth', y=MouthOffset): with Path(tags='inside', color='white'): RoundedRectangle(-MouthWidth / 2, -MouthHeight / 2, MouthWidth, MouthHeight, MouthCornerRadius) FillPath() with Path(tags='outside', color='yellow', lineWidth=LipThickness): RoundedRectangle(-(MouthWidth + LipThickness) / 2, -(MouthHeight + LipThickness) / 2, MouthWidth + LipThickness, MouthHeight + LipThickness, MouthCornerRadius + LipThickness) StrokePath() with Group('triangles'): with Group('outer', color='yellow'): triangle_width = 2*math.pi * OuterTriangleRadius / TriangleCount - TriangleSeparation for i in range(TriangleCount): with Group(rotate=i / TriangleCount): with Path(y=-OuterTriangleRadius, tags='triangle outer'): MoveTo(-triangle_width / 2, 0) LineTo(0, -TriangleHeight) LineTo(triangle_width / 2, 0) FillPath() with Group('inner', color='yellow'): triangle_width = 2*math.pi * InnerTriangleRadius / TriangleCount - TriangleSeparation for i in range(TriangleCount): with Group(rotate=i / TriangleCount): with Path(y=-InnerTriangleRadius, tags='triangle outer'): MoveTo(-triangle_width / 2, 0) LineTo(0, TriangleHeight) LineTo(triangle_width / 2, 0) FillPath() #%% client.activate() with Cue('Q1', name='Spinning triangles') as Q1: period = 20 count = t / period Match('#outer').rotate = count Match('#inner').rotate = -count with Cue('Q2', name='Blinking eyes') as Q2: period = 5 duration = 0.5 count = t / period cycle = t % period offset = beta('Q2.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