#!/usr/bin/python2.3

import SWF
import Image

SWF.verbose(0)

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

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

peppers = Image.open("peppers.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()

(s,d) = (0,1)

for i in xrange(1,200):
    for y in xrange(0,height):
        line = [0]*stream.xblocks()
        for x in xrange(0,width):
            b1 = random.randint(0,100)
            b2 = random.randint(0,100)
            r = i/10
            mx = (b1%(r*2+1))-r
            my = (b2%(r*2+1))-r
            line[x] = (mx+my*1j)
        map[y] = line

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

    swf.tags += SWF.ShowFrame()

swf.save("distort1.swf")

