"""Original full-size Christmas-night Santa and pre-rendered magic sparkles.
Drawn with the project Art primitives; no downloaded artwork or samples.
"""
import math
import random

def night_assets(Art):
    assets=[];groups={}
    def group(name,images):
        groups[name]=len(assets)
        assets.extend((name+str(i),im) for i,im in enumerate(images))
    def santa(kind,p):
        a=Art(100,164)
        stride=math.sin(p*math.tau/12)*9 if kind=='walk' else 0
        bend=math.sin(p*math.pi/11)*14 if kind=='gift' else 0
        front=.42 if kind in ('walk','gift') else .42+.58*min(1,p/7) if kind=='turn' else 1
        cx=40+6*front;hy=26+bend
        # Sack behind the shoulder, with stitched fabric, drawstring and ties.
        a.ellipse((57,47+bend,95,125),'#75533b')
        a.ellipse((61,49+bend,92,115),'#987148')
        for x in (68,79,88):a.arc((x-7,57+bend,x+6,111),260,75,'#b08a58',1)
        a.line([(62,56+bend),(66,41+bend),(73,39+bend),(80,46+bend)],'#c4a16b',2)
        a.line([(69,44+bend),(84,48+bend)],'#d8b578',2)
        for x in (70,76):a.line([(x,45+bend),(x+3,57+bend)],'#c4a16b',1)
        # Separated boots and trouser legs keep a stable ground anchor.
        for x,dx in ((31,stride),(59,-stride)):
            a.rect((x+dx-6,126,x+dx+8,155),'#a42c37',4)
            a.rect((x+dx-12,148,x+dx+10,161),'#302d33',4)
            a.line([(x+dx-10,159),(x+dx+8,159)],'#655b55',1)
        a.ellipse((18,65+bend,74,138),'#ab303b')
        a.ellipse((22,61+bend,70,132),'#ce424b')
        a.arc((24,74+bend,64,123),310,80,'#e06060',2)
        a.rect((22,126,72,137),'#e9ddc5',4)
        for x in range(25,72,5):a.ellipse((x-2,126,x+3,136),'#f4e8d1')
        a.rect((21,106,73,115),'#36343a',2)
        a.rect((41,104,54,118),'#dfba67',2);a.rect((44,107,51,114),'#39343a')
        a.line([(47,74+bend),(47,103)],'#ebdbc1',4)
        for y in (84,96):a.ellipse((45,y,49,y+4),'#c7a351')
        # Profile becomes a front-facing smiling face before the wink.
        a.ellipse((cx-17,hy+3,cx+17,hy+40),'#dfab82')
        a.ellipse((cx-20,hy+21,cx+20,hy+60),'#e6dcc8')
        a.ellipse((cx-15,hy+23,cx+16,hy+57),'#f5ead5')
        for x in (-10,-2,6,12):a.arc((cx+x-4,hy+32,cx+x+6,hy+53),15,130,'#d7cfbd',.8)
        a.ellipse((cx-13,hy+11,cx+13,hy+33),'#ecc099')
        eye1=cx-10;eye2=cx-1+7*front
        a.line([(eye1-3,hy+15),(eye1+2,hy+14)],'#f0e5d0',2)
        a.line([(eye2-2,hy+14),(eye2+3,hy+15)],'#f0e5d0',2)
        if kind=='wink' and 1<=p<=4:
            a.arc((eye2-3,hy+18,eye2+4,hy+22),5,165,'#493a33',1.3)
        else:a.ellipse((eye2-1,hy+18,eye2+2,hy+21),'#36333b')
        # Both open eyes remain visible in the three-quarter walking/delivery pose.
        a.ellipse((eye1-1,hy+18,eye1+2,hy+21),'#36333b')
        a.ellipse((cx-13,hy+24,cx-6,hy+29),'#d78f7c')
        a.ellipse((cx+6,hy+24,cx+12,hy+29),'#d78f7c')
        nx=cx-9*(1-front)
        a.ellipse((nx-4,hy+22,nx+5,hy+29),'#d9967d')
        a.arc((cx-6,hy+28,cx+7,hy+37),12,167,'#91483d',1.4)
        a.ellipse((cx-11,hy+28,cx,hy+33),'#fff0d8');a.ellipse((cx,hy+28,cx+11,hy+33),'#fff0d8')
        a.poly([(cx-20,hy+7),(cx-9,hy-21),(cx+8,hy-18),(cx+22,hy-4),(cx+29,hy+5),(cx+18,hy+8),(cx+11,hy-3)],'#bd3441')
        a.line([(cx-12,hy-16),(cx+3,hy-13),(cx+17,hy-3)],'#de555b',2)
        a.rect((cx-20,hy+3,cx+18,hy+12),'#f0e6d1',3)
        a.ellipse((cx+23,hy+1,cx+34,hy+13),'#f5ead5')
        # Left sleeve, cuff and hand: deliver gifts, then raise a finger to nose.
        handx=19;handy=105+stride*.5
        if kind=='gift':
            u=max(0,min(1,(p-2)/6));handx=72-50*u;handy=75+53*u
        if kind=='touch':
            u=min(1,p/8);handx=19+(nx-19)*u;handy=105+(hy+27-105)*u
        a.line([(24,76+bend),(14,91+bend),(handx,handy-4)],'#b7323e',12)
        a.line([(handx-4,handy-3),(handx+4,handy-3)],'#f0e5cf',5)
        a.ellipse((handx-4,handy-2,handx+4,handy+6),'#e8b990')
        if kind=='touch' and p>=6:a.line([(handx+1,handy+2),(nx,hy+25)],'#ecc09b',2.5)
        if kind=='gift' and 3<=p<=8:
            a.rect((handx-10,handy+4,handx+8,handy+17),'#4d8f88',1)
            a.rect((handx-3,handy+4,handx,handy+17),'#e7c477')
            a.line([(handx-9,handy+9),(handx+7,handy+9)],'#e7c477',2)
        return a.image()
    group('nightwalk',[santa('walk',i) for i in range(12)])
    group('nightgift',[santa('gift',i) for i in range(12)])
    group('nightturn',[santa('turn',i) for i in range(8)])
    group('nightwink',[santa('wink',i) for i in range(6)])
    group('nighttouch',[santa('touch',i) for i in range(12)])
    rng=random.Random(26332)
    stars=[(rng.uniform(0,math.tau),rng.uniform(12,74),rng.uniform(0,110),rng.uniform(1,4)) for _ in range(54)]
    frames=[]
    for frame in range(20):
        a=Art(200,200);u=frame/19
        if 2<=frame<=9:
            for k in range(9):
                angle=k*math.tau/9;r=12+25*u
                x=100+math.cos(angle)*(15+35*u);y=79+math.sin(angle)*(35+45*u)
                a.ellipse((x-r,y-r,x+r,y+r),(215,204,231,max(0,220-frame*8)))
        for j,(angle,speed,height,size) in enumerate(stars):
            x=100+math.cos(angle)*speed*u;y=130-height+math.sin(angle)*speed*u-20*u
            r=size*math.sin(math.pi*min(1,u+.06))
            colour=('#ffe9a8','#e7c5ff','#aee8ef','#fff5dc')[j%4]
            if r>.3:
                a.poly([(x-r,y),(x-.25*r,y-.25*r),(x,y-r*1.7),(x+.25*r,y-.25*r),(x+r,y),(x+.25*r,y+.25*r),(x,y+r*1.7),(x-.25*r,y+.25*r)],colour)
        frames.append(a.image())
    group('nightmagic',frames)
    return assets,groups
