DenSnoychik's picture
Add 2D anime references and Python renderer for Arena
e7b8e7e verified
Raw History Blame Contribute Delete
2.06 kB
"""Example of sharing actual actor motion between the shot and the review."""
import math
def segment(ctx, points, color, width):
ctx.set_source_rgb(*color)
ctx.set_line_width(width)
ctx.set_line_cap(1)
ctx.move_to(*points[0])
for point in points[1:]:
ctx.line_to(*point)
ctx.stroke()
def circle(ctx, x, y, radius, color):
ctx.set_source_rgb(*color)
ctx.arc(x, y, radius, 0, math.tau)
ctx.fill()
def pose(t):
anticipation = math.exp(-((t-.55)/.23)**2)
lift = max(0., min(1., (t-.55)/.9))
lift = lift*lift*(3-2*lift)
settle = max(0., 1-abs(t-1.64)*2.6)
return anticipation, lift, settle
def actor(ctx, t, width, height):
ctx.save()
ctx.translate(width/2, height*.51)
ctx.scale(height/288, height/288)
anticipate, lift, settle = pose(t)
lean = -6*anticipate+10*lift
cloth = (.13,.27,.43)
skin = (.85,.62,.46)
segment(ctx, [(0,23),(lean,72),(lean-3,115)], cloth, 71)
segment(ctx, [(lean-23,46),(lean-45,79),(lean-31,113)], cloth, 19)
shoulder=(lean+24,43)
angle=.86-1.55*lift
elbow=(shoulder[0]+39*math.cos(angle),shoulder[1]+39*math.sin(angle))
wrist=(elbow[0]+32*math.cos(angle-1.05*lift),elbow[1]+32*math.sin(angle-1.05*lift))
segment(ctx,[shoulder,elbow],cloth,19)
segment(ctx,[elbow,wrist],skin,13)
circle(ctx,*wrist,8,skin)
ctx.save()
ctx.translate(lean,-13-2*settle)
ctx.rotate(.12*anticipate-.10*lift)
circle(ctx,0,-5,36,(.12,.14,.18))
circle(ctx,4,4,29,skin)
for x in (-5,14):
blink = math.exp(-((t-1.8)/.08)**2)
segment(ctx,[(x-4,1),(x+4,1)],(.15,.21,.26),max(1,6*(1-blink)))
mouth = 2+3*abs(math.sin(t*19))*settle
circle(ctx,11,17,mouth,(.28,.15,.16))
ctx.restore()
ctx.restore()
def draw_frame(ctx, t, width, height, audio_level=0):
ctx.set_source_rgb(.08,.13,.24)
ctx.paint()
actor(ctx,t,width,height)
REVIEW_ACTORS = {"envoy": actor}
REVIEW_ASSETS = {"envoy": lambda ctx,w,h: actor(ctx,1.25,w,h)}
CANVAS_WIDTH, CANVAS_HEIGHT = 640, 360