import random
import math
import util
import sys
from demoscript import *
sched = SchedulerSingleton_instance() # setup scheduler

joypad1=0

#addMapping(joypad1,0,"taptap")	# map button a 

#addMapping(joypad1,2,"test")	# map button a 
#addMapping(joypad1,3,"test2")	# map button a 

#addMapping(joypad1,2,"butX")	# map button a 
#addMapping(joypad1,0,"logo")	# map button a 
#addMapping(joypad1,1,"noise2")	# map button a 

#addMapping(joypad1,0,"donker1")	# map button a 
#addMapping(joypad1,1,"donker2")	# map button a 

#addMapping(joypad1,0,"curves1")
#addMapping(joypad1,1,"curves2")

#addMapping(joypad1,0,"overobj")
#addMapping(joypad1,0,"logo2")


#test=util.SimpleScene("d:\\demos\\demo\\apending.lzma",nextCamera=["butX"],reset=["butX"],colors=[[0,"donker1"],[1,"donker2"]],curveEvents=[[4,"curves"],[5,"curves"],[6,"curves"],[7,"curves"],[8,"curves"]],cameraOrder=[1,0])
test=util.SimpleScene("d:\\demos\\demo\\apending.lzma",nextCamera=["butX"],reset=["butX"],colors=[[0,"donker1"],[1,"donker2"]],curveEvents=[[4,"curves2"],[5,"curves2"],[6,"curves2"],[7,"curves2"],[8,"curves2"],[10,"curves1"],[11,"curves1"],[12,"curves1"],[13,"curves1"]],cameraOrder=[1,0])

#over=util.SimpleScene("d:\\demos\\demo\\raending.lzma",nextCamera=["butX"],reset=["butX"],colors=[[0,"donker1"],[1,"donker2"]],curveEvents=[[4,"curves2"],[5,"curves2"],[6,"curves2"],[7,"curves2"],[8,"curves2"],[10,"curves1"],[11,"curves1"],[12,"curves1"],[13,"curves1"]],cameraOrder=[1,0])

test2=util.SimpleScene("d:\\demos\\demo\\ding.lzma",nextCamera=["butX"],reset=[],colors=[[0,"test"],[1,"test2"]])
test2.speed=FixedSlider(40000,40000)

test.speed=FixedSlider(300,300)


imgs=[]

imgs.append(util.RandomImage("d:\\demos\\demo\\koru_drinker.tga",xpos=0,xamp=1,yamp=0.1,ypos=-0.8) )

for i in [9,4,9,4,4,9,4]*8:
	imgs.append(util.RandomImage("d:\\demos\\demo\\overlay"+str(i)+".png",xpos=0.7,ypos=0.5,xamp=0.1,yamp=1))
#	imgs.append(util.RandomImage("d:\\demos\\demo\\overlay"+str(4)+".png",xpos=0.7,ypos=0.5,xamp=0.1,yamp=1))
#	imgs.append(util.RandomImage("d:\\demos\\demo\\overlay"+str(7)+".png",xpos=0.7,ypos=0.5,xamp=0.1,yamp=1))

#imgs.append(Image("d:\\demos\\demo\\title.png"))

imgSeq=util.AutoImageSeq(images=imgs)
logoSeq=util.SimpleImageSeq(images=[util.ScrollImage("d:\\demos\\demo\\limp_ninja.tga")],nextImage=["logo"])

logo=Image("d:\\demos\\demo\\title.png")
logo.opacity.setFixPointDamping(1)
logoSeq2=util.SimpleImageSeq(images=[logo],nextImage=["butX"])



class CustomOver(Over):
	def __init__ (self):
		Over.__init__(self)
		self.fillOpacity=FixedSlider(1,1)
		self.red=FixedSlider(0,0)
		self.green=FixedSlider(0,0)
		self.blue=FixedSlider(0,0)

		

	def callback(self):
#		pass
#		self.fillOpacity=FixedSlider(1,1)
#		if getEvent(EC_NOTE_ON,"butB"):
#		self.fillOpacity.setDamping(0.9)
#		self.fillOpacity.setFixPointDamping(0.9)
		if frand(0,1) < 0.5:
			self.fillOpacity.setTargetValue(frand(0,1))



over=CustomOver()

# dist=util.SimpleDistort(event=[[20,"test"]],distVal=0)
dist=util.SimpleBlur(events=["test"])




ripple=util.SimpleRipple()
def truc(self):
  if getEvent(EC_NOTE_ON,"reset"):
     self.amplitude.setTargetValue(frand(-1,1))
     self.waves.setTargetValue(frand(-5,5))
     self.speed.setTargetValue(15)
     self.scrollx.setTargetValue(frand(-1.3,1.3))
     self.scrolly.setTargetValue(frand(-1.3,1.3))

#ripple.callbacks.append(truc)

#motionblur=MotionBlur()
#motionblur.blur=FixedSlider(0.1,0.1)


###test.connectOutput(ripple,"in")

#test.connectOutput(over,"b")
#test2.connectOutput(dist,"in")
#dist.connectOutput(over,"a")






#ripple.connectOutput(motionblur,"in")
blur=util.SimpleBlur(events=["donker1"])
#blur.setAdditive(1)
#motionblur.connectOutput(blur,"in")

sched.schedule(0,16.5,logoSeq,SI_SUPER,0)
sched.schedule(16.5,9.5,logoSeq2,SI_SUPER,0)
sched.schedule(26,156-26.0,imgSeq,SI_SUPER,0)
sched.schedule(156,203.5-156,blur,SI_SUPER,0)

test2.connectOutput(blur,"in")
sched.schedule(3,203.5-2.9,test,SI_A,0)




##############################

playSong("d:\\demos\\demo\\beginn.wma")