#!/usr/bin/python2.3

import SWF
import Image

swf = SWF.create(version=6, bbox=(0,0,512,512), fps=25)

swf.tags += SWF.BackgroundColor(0,0,0)

peppers = Image.open("lena.png");
peppers.load()
peppers = peppers.convert("RGBA")
width = peppers.size[0]
height = peppers.size[1]
peppers = peppers.im

stream = SWF.VideoStream(width=width, height=height, frames=200)

startframe = stream.addFrame(peppers,quant=15)
swf.tags += startframe
swf.tags += SWF.PlaceObject(stream, depth=1, ratio=0)
swf.tags += SWF.ShowFrame()

line = [0]*stream.xblocks()
map = [line]*stream.yblocks()

import random
width = stream.xblocks()
height = stream.yblocks()

for y in xrange(0,height):
    line = [0]*stream.xblocks()
    for x in xrange(0,width):
        mx = -x+stream.xblocks()/2
        my = -y+stream.yblocks()/2
        if(mx>=0): mx=mx+1
        if(my>=0): my=my+1
        line[x] = (mx+my*1j)
    map[y] = line

for i in xrange(1,100):

    dist = stream.addDistortionFrame(map)
    swf.tags += dist
    swf.tags += SWF.MoveObject(stream, depth=1, ratio=i)

    swf.tags += SWF.ShowFrame()

swf.save("zoom.swf")

