from PIL import Image, ImageDraw
import math

# Canvas size
width, height = 1200, 700
img = Image.new('RGB', (width, height), color='#1a1a2e')
draw = ImageDraw.Draw(img)

# Draw gradient background
for y in range(height):
    ratio = y / height
    r = int(26 + ratio * 20)
    g = int(26 + ratio * 10)
    b = int(46 + ratio * 30)
    draw.line([(0, y), (width, y)], fill=(r, g, b))

def draw_kil_domino(x, y, angle, scale=1.0):
    """Draw a domino with Swedish 'kil' (wedge spike) bottom shape"""
    w, h = 35 * scale, 80 * scale
    spike_h = 20 * scale  # The kil/wedge spike height
    
    # Rotation helper
    def rot(px, py, cx, cy, a):
        a = math.radians(a)
        cos_a, sin_a = math.cos(a), math.sin(a)
        dx, dy = px - cx, py - cy
        return (cx + dx * cos_a - dy * sin_a, 
                cy + dx * sin_a + dy * cos_a)
    
    # Points for the domino body (top rectangle part)
    points_body = [
        (-w/2, -h), (w/2, -h), (w/2, 0), (-w/2, 0)
    ]
    
    # Points for the 'kil' (spike) base - triangular wedge
    points_kil = [
        (-w/2, 0), (w/2, 0),  # top of spike
        (0, spike_h),          # point of spike (kil)
    ]
    
    # Rotate and translate points
    body_pts = [rot(px + x, py + y, x, y, angle) for px, py in points_body]
    kil_pts = [rot(px + x, py + y, x, y, angle) for px, py in points_kil]
    
    # Draw shadow
    shadow_pts = [(px + 3, py + 3) for px, py in body_pts + kil_pts]
    
    # Draw domino body with gradient
    for i in range(len(body_pts)):
        p1 = body_pts[i]
        p2 = body_pts[(i + 1) % len(body_pts)]
        draw.line([p1, p2], fill='#8B7355', width=2)
    
    draw.polygon(body_pts, fill='#C4A77D', outline='#8B7355')
    
    # Draw the 'kil' spike (wedge shape)
    draw.polygon(kil_pts, fill='#A08060', outline='#6B5344')
    
    # Draw pip dots (face numbers)
    cx, cy = rot(x, y - h/2, x, y, angle)
    pip_size = 4 * scale
    pips = [(0, -h/3), (0, 0), (0, h/3)]
    for py, px in pips:
        px, py = rot(x + px * scale, y + py * scale, x, y, angle)
        draw.ellipse([px-pip_size, py-pip_size, px+pip_size, py+pip_size], fill='#2d2d2d')

# Draw chain reaction of falling dominoes with kil bases
start_x = 100
start_y = 550

num_dominoes = 15
spacing = 75

for i in range(num_dominoes):
    x = start_x + i * spacing
    
    # Domino is falling progressively - last ones fully fallen
    if i < num_dominoes - 3:
        # Standing with slight wobble
        angle = -5 + i * 2
        y = start_y
    elif i < num_dominoes - 1:
        # Mid-fall
        angle = -30 - (i - num_dominoes + 3) * 20
        y = start_y + (i - num_dominoes + 3) * 10
    else:
        # Recently toppled - almost flat
        angle = -70
        y = start_y + 25
    
    draw_kil_domino(x, y, angle, scale=1.2)

# Draw the "SECRET" revealed in the falling path
draw.text((width//2 - 100, 150), "SECRET", font=None, fill='#FFD700')

# Draw glowing revelation effect
for i in range(5):
    glow_color = (255, 215, 0, 150 - i * 30)
    draw.text((width//2 - 100 + i*2, 148 + i*2), "SECRET", fill=(255, 215, 0))

# Draw sparkle particles
import random
random.seed(42)
for _ in range(30):
    px = random.randint(500, 1100)
    py = random.randint(100, 400)
    size = random.randint(2, 5)
    color = random.choice(['#FFD700', '#FF6B6B', '#4ECDC4', '#A855F7'])
    draw.ellipse([px-size, py-size, px+size, py+size], fill=color)

# Arrow showing chain reaction direction
arrow_y = 620
draw.line([(150, arrow_y), (1050, arrow_y)], fill='#666', width=3)
draw.polygon([(1050, arrow_y), (1030, arrow_y-10), (1030, arrow_y+10)], fill='#666')

img.save('domino_kil_effect.png')
print("Saved: domino_kil_effect.png")
