"""Left TV drawer at (312,154). Only the top of its tilted VHS case is exposed."""
import math
import runpy
from pathlib import Path
from PIL import Image, ImageFilter

def drawer_assets(Art):
    pixeltext=runpy.run_path(str(Path(__file__).resolve().with_name('ExtraArt')))['pixeltext']
    assets=[]
    # Black clamshell, rounded spine and an ivory paper insert under the sleeve.
    case=Art(44,60)
    case.rect((0,0,43,59),'#21242a',2)
    case.rect((2,1,41,58),'#58595b',2)
    case.rect((3,2,40,57),'#1d2529',1)
    case.rect((4,3,40,55),'#f1dfb6',1)
    case.line([(1,4),(1,53)],'#79756b',.8)
    case.line([(5,1),(38,1)],'#a69d8e',.7)
    # Render lettering at sprite supersampling resolution before rotating.
    letters=Image.new('L',case.im.size)
    pixeltext(letters,'HOME',7*3,5*3,scale=4,col=255)
    case.im.paste('#ac1923',(0,0),letters.filter(ImageFilter.MaxFilter(3)))
    tilted=case.im.rotate(13,Image.Resampling.BICUBIC,expand=True)
    tilted=tilted.crop(tilted.getbbox())
    tilted=tilted.resize((round(tilted.width/3),round(tilted.height/3)),Image.Resampling.LANCZOS)
    for frame in range(1,13):
        depth=frame/12
        x=9-3*depth
        y=2+13*depth
        a=Art(93,59)
        a.rect((9,2,86,42),'#674832',2)
        a.rect((11,3,84,37),'#332c28',1)
        a.poly([(11,3),(84,3),(x+75,y+1),(x+1,y+1)],'#513828')
        if frame>3:
            a.poly([(20,4),(33,4),(39,y),(17,y)],'#446954')
            a.line([(27,4),(25,y)],'#ac9468',1.6)
        a.line([(10,3),(x,y+1)],'#cc9f6d',1.5)
        a.line([(85,3),(x+77,y+1)],'#c29766',1.5)
        image=Image.new('RGBA',(93,81))
        image.alpha_composite(a.image(),(0,22))
        if frame>3:
            # Spring up, overshoot slightly and settle. Clip at the near lip
            # before drawing the wooden front; the lower sleeve stays concealed.
            t=(frame-3)/9
            reveal=round(22*math.sin(t*math.pi*.67)/math.sin(math.pi*.67))
            lip=22+round(y)
            image.alpha_composite(tilted.crop((0,0,tilted.width,reveal)),(31,lip-reveal))
        front=Art(93,59)
        front.rect((x+2,y+4,x+79,y+42),'#62452f',2)
        front.rect((x,y,x+77,y+40),'#976b49',2)
        front.line([(x+1,y+1),(x+76,y+1)],'#c3966a',1)
        front.line([(x+2,y+38),(x+75,y+38)],'#815738',1)
        front.line([(x+52,y+8),(x+61,y+8)],'#61472e',2)
        front.line([(x+52,y+7),(x+61,y+7)],'#dec197',1.3)
        image.alpha_composite(front.image(),(0,22))
        assets.append((f'drawer{frame:02}',image))
    a=Art(126,32)
    a.poly([(62,23),(72,30),(74,23)],'#27343a')
    a.rect((0,0,125,24),'#27343a',4)
    a.rect((1,1,124,23),'#fff0cf',3)
    a.poly([(64,22),(71,28),(73,22)],'#fff0cf')
    im=a.image()
    for y,line in [(4,'Merry Christmas'),(14,'ya filthy animal!')]:
        pixeltext(im,line,(126-(len(line)*6-1))//2,y,col='#452c2c')
    assets.append(('drawerspeech',im))
    return assets
