/*
Fixlists:
0:40 tekstit, curvejen värit
0:58 curvet ylös ja gridi piiloon
1:00 - kiväärit ilmestymään myöhemmin

*/
var posScalar=1.5;
var yposScalar=1.0;
var sValue1 = 1.0;
var sValue2 = 1.0;
var cubeNumber = 0;
var beat = .5;
var tick= beat/4;
var pattern = 8*beat;
var snareValue = Math.floor(Math.random()*4);
var effectType = Math.floor(Math.random()*5);
var texnumber = 0;
var frontLayer;
var activeBgEffect;
var direction;
var activeVoice=10;
var shiftBeat = false;
var shiftHat = false;
var shiftBass = false;
var shiftSnare = false;
prevTime=0.0;
var currentTime;
var beatTimer = 2*pattern;
var globalHat = 0.0;
var bassTimer = 2*pattern;
var hatTimer = 2*pattern;
var voiceTimer = 2*pattern;
var hatTimes = [];
var kickTimes = [];
var snareTimes = [];
var bassTimes = [];
var voiceTimes = [];
var timeCounter;
var kickReader = 0;
var snareReader = 0;
var hihatReader = 0;
var bassReader = 0;
var voiceReader = 0;
var textype = Math.floor(Math.random()*4);

var voiceSelectorReader = 0;
var voiceSelector = [];
var kickSelectorReader = 0;
var kickSelector = [];
var snareSelectorReader = 0;
var snareSelector = [];
var hihatSelectorReader = 0;
var hihatSelector = [];
var bassSelectorReader = 0;
var bassSelector = [];
var endTime = 90;
var bassObject = [Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1),Math.floor(Math.random()*10+1)];
var bassEffectType = 0;
var bassEffectCounter = 0;
var fourValueValues = 0;
var bassOrBeat = 1;
var fourRandomPos = [];
var objects = ["data/possu.obj", "data/heppa.obj", "data/piikki.obj","data/cube2.obj","data/pyssy.obj","data/threecubes.obj"]
var bassFlash = ["data/bassflash.png","data/bassflash2.png","data/bassflash3.png"]
var randomObj1 = Math.floor(Math.random()*objects.length);
var randomObj2 = Math.floor(Math.random()*objects.length);
var randomPosX;
var randomPosY;
var randomScales;


	
var snareRandomizer;
var kickRandomizer;
var bassRandomizer;
var hihatRandomizer;

var playSnare = false;
var playKick = false;
var playBass = false;
var playHat = false;

var gl = new WebGL2RenderingContext(); //enable WebGL 2 partial support




var particleMesh = void null;

var fftImage = new Image();
	
	function additive(animation) {
		glPushMatrix();     
		gl.enable(gl.BLEND);
		gl.blendFunc(gl.ONE, gl.ONE);
	    glPopMatrix();
	}

function xor(animation)
{
//	gl.enable(GL_COLOR_LOGIC_OP);
//	gl.logicOp(GL_INVERT);
			gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE_MINUS_DST_COLOR, gl.ONE_MINUS_SRC_COLOR);
//gl.blendFunc(gl.ONE_MINUS_SRC_COLOR,gl.ZERO)
}

	function normal(animation) {
		glPushMatrix();     
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glFrontFace(GL_CW);  
		gl.enable(gl.BLEND);
	  gl.blendFunc(gl.ONE, gl.ONE);

	   glPopMatrix();
	}
	
	function blendAdd(animation) {
		gl.enable(gl.DEPTH_TEST);
		gl.depthMask(false);
		gl.enable(gl.BLEND);
		
//		gl.blendFunc(gl.ONE, gl.ONE);
		gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
	}

	function blendNormal(animation) {
		gl.enable(gl.BLEND);
		gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
	}

function clamp(animation)
{

}

Demo.prototype.init = function()
{


	this.loader.addAnimation([{
         "start": 0, "duration": 15,"layer": 12
        ,"image": "white.png"
			
		,"scale":[{"uniform3d":posScalar*100.0}]
		,"color":[{"r":0,"g":0,"b":0,"a":255}]
		  }]);
	
	


    var start = 0;
    var duration = 160*20;
    var layer = 1; 


	
	//fbot
//	this.createFBO(0,20000,"fbo20k");
//	this.createFBO(20003,30000,"fbo30k");
	this.createFBO(0,40000,"fbo40k");
	this.createFBO(40005,50000,"fbo50k");
	this.createFBO(50005,60000,"fbo60k");

   		this.loader.addAnimation ([
		{
		 "start": 0, "duration": 95
		,"image": ["white.png"]
		,"layer": 55
		,"scale":[{"x":posScalar*10,"y":posScalar*10}]
				,"position":[{"x":posScalar*640,"y":posScalar*(720+380)}
		,{"duration":4.5,"y":posScalar*720}]
		}]);
this.loader.addAnimation ([
		{
		 "start": 0, "duration": 95
		,"image": ["white.png"]
		,"layer": 55
		,"scale":[{"x":posScalar*10,"y":posScalar*10}]
				,"position":[{"x":posScalar*640,"y":posScalar*-380}
		,{"duration":4.5,"y":posScalar*0}]
		}]);		

this.loader.addAnimation ([
		{
		 "start": 0, "duration": 5
		,"image": ["0.png"]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*1.0,"y":posScalar*1.0}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 511
}]);
	
this.loader.addAnimation ([
		{
		 "start": 110, "duration": 5
		,"image": ["jml.png"]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*1.0,"y":posScalar*1.0}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 111
}]);	

this.loader.addAnimation ([
		{
		 "start": 115, "duration": 5
		,"image": ["minus1.png"]
		,"color":[{"r":"{return 255*Math.random(getSceneTimeFromStart())}","g":"{return 255*Math.random(getSceneTimeFromStart())}",b:"{return 255*Math.random(getSceneTimeFromStart())}"}]
		,"scale":[{"x":posScalar*1.5,"y":posScalar*1.5}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 211
}]);	

		
for(var i=0;i<5*60;i++)
{

this.loader.addAnimation ([
		{
		 "start": 115+i*.017*.5, "duration": .0167*3
		,"image": ["minimal_circle.png"]
		,"color":[{"r":Math.random()*255,"g":Math.random()*255,b:Math.random()*255}
			 ,{"duration":.25*pattern,"r":Math.random()*255,"g":Math.random()*255,b:Math.random()*255}]
		,"scale":[{"uniform3d":posScalar*1.5*Math.random()}
		,{"duration":.25*pattern,"uniform3d":0.75*Math.random()}]
		,"position":[{"x":posScalar*(630+Math.random()*20),"y":posScalar*(350+Math.random()*20)}]
		,"layer": 111
}]);	


}

	this.flash(5,0);
 	this.scene1(5);
	this.number(5,1,0);
	
	this.flash(15,0);
 	this.scene2(15);
	this.number(15,2,0);
	
	this.flash(25,0);
	this.scene4(25);	
	this.number(25,3,0);
	
	this.flash(35,0);
	this.scene8(35);
	this.number(35,4,255);
	
	this.flash(45,0);
	this.scene5(45);
	this.number(45,5,255);
	
	this.flash(55,0);
	this.scene6(55);
	this.number(55,6,0);
	
	this.flash(65,0);
	this.scene9(65);
	this.number(65,7,255);
	
	this.flash(75,0);
	this.scene7(75);
	this.number(75,8);
	
	this.flash(85,0);
	this.scene3(85);
	this.number(85,9,0);
	
this.flash(95,0);
	this.scene10(95);
	
	this.flash(105,255);
	
	this.loader.addAnimation ([
	{
		 "start": 0, "duration": 8888
		,"image": ["fbo40k.color.fbo", "fft0"]
		,"layer": 40105
	//	,"shader":{"name":["fftdistort.fs"]}
	}]);
		
	this.loader.addAnimation ([
	{
		 "start": 0, "duration": 8888
		,"image": ["fbo50k.color.fbo","2dlut.png"]
		,"layer": 50105



		 ,"shader":{
	         "name":"lut.fs",
	         "variable":[
			{"name":"lut","type":"int","value":[1]}
	          ]
	        }
		
	}]);
	
		this.loader.addAnimation ([
		{
		 "start": 0, "duration": 8888
		,"image": ["fbo60k.color.fbo"]
		,"layer": 60105
	
		,"shader":{"name":["hackglow.fs"]}
		//,"shader":{"name":["edge.fs"]}
		}]);



}

Demo.prototype.createFBO = function (startLayer, endLayer, name)
{
	   	this.loader.addAnimation ([
	{
	"start": 0, "duration": 99999
	,"layer": startLayer
	,"fbo":{"name":name,"action":"begin","storeDepth":true}
	}
	]);
	
	this.loader.addAnimation ([
	{
	"start": 0, "duration": 99999
	,"layer": endLayer,"fbo":{"name":name,"action":"unbind"}
	}
	]);
	
}

Demo.prototype.scene1 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.125,"y":posScalar*0.125}]
		,"position":[{"x":posScalar*340,"y":posScalar*360}]
		,"layer": 105
		}]);
	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.125,"y":posScalar*0.125}]
		,"position":[{"x":posScalar*540,"y":posScalar*360}]
		,"layer": 105
		}]);

	   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.125,"y":posScalar*0.125}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 105
		}]);

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.125,"y":posScalar*0.125}]
		,"position":[{"x":posScalar*940,"y":posScalar*560}
		,{"duration":9.8,"y":posScalar*360}]
		,"layer": 105
		}]);		
		
}

Demo.prototype.scene2 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_10lines.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.5,"y":posScalar*0.5}]
		,"position":[{"x":posScalar*411,"y":posScalar*360}
		,{"duration":9.9,"x":posScalar*640}]
		,"layer": 105
		}]);
	
	   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_10lines2.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.5,"y":posScalar*0.5}]
		,"position":[{"x":posScalar*769,"y":posScalar*360}
		,{"duration":9.9,"x":posScalar*640}]
			,"layer": 105
		}]);
		
}

Demo.prototype.scene3 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_outlinecube.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		 ,"angle":[{"degreesZ":-90}
		,{"duration":9.8,"degreesZ":0}]
		,"layer": 105
		}]);
	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_outlinecube.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
	 ,"angle":[{"degreesZ":-45}
		,{"duration":9.8,"degreesZ":0}]
		,"layer": 105
		}]);
		
		   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_outlinecube.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
	 ,"angle":[{"degreesZ":90}
		,{"duration":9.8,"degreesZ":0}]
		,"layer": 105
		}]);
		
		   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_outlinecube.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		 ,"angle":[{"degreesZ":45}
		,{"duration":9.8,"degreesZ":0}]
		,"layer": 105
		}]);
}

Demo.prototype.scene4 = function (start)
{


   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.2,"y":posScalar*0.2}]
		,"position":[{"x":posScalar*337.6,"y":posScalar*257.6}
		,{"duration":9.9,"x":posScalar*537.6}]
		,"layer": 105
		}]);	
		
		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.2,"y":posScalar*0.2}]
		,"position":[{"x":posScalar*742.4,"y":posScalar*57.6}
		,{"duration":9.9,"y":posScalar*257.6}]
		,"layer": 105
		}]);
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.2,"y":posScalar*0.2}]
		,"position":[{"x":posScalar*537.6,"y":posScalar*662.4}
		,{"duration":9.9,"y":posScalar*462.4}]
		,"layer": 105
		}]);	
		
		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":0,"g":0,b:"0"}]
		,"scale":[{"x":posScalar*0.2,"y":posScalar*0.2}]
		,"position":[{"x":posScalar*942.4,"y":posScalar*462.4}
		,{"duration":9.9,"x":posScalar*742.4}]
		,"layer": 105
		}]);
		
}

Demo.prototype.scene5 = function (start)
{


	   this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "{xor(animation);}"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*940,"y":posScalar*360}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*360}]
		,"layer": 111
		}]);	

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.137,"y":posScalar*0.137}]
		,"position":[{"x":posScalar*340,"y":posScalar*360}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*360}]
		,"layer": 112
		}]);	
	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*640,"y":posScalar*160}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*160}]
		,"layer": 111
		}]);	

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.137,"y":posScalar*0.137}]
		,"position":[{"x":posScalar*640,"y":posScalar*160}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*160}]
		,"layer": 112
		}]);	

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*640,"y":posScalar*560}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*560}]
		,"layer": 111
		}]);	

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.137,"y":posScalar*0.137}]
		,"position":[{"x":posScalar*640,"y":posScalar*560}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*560}]
		,"layer": 112
		}]);	
		
		
		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "blendNormal(animation);"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
}

Demo.prototype.scene6 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_90triangle.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.25,"y":posScalar*0.25}]
		,"position":[{"x":posScalar*510,"y":posScalar*230}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*360}]
		,"angle":[{"degreesZ":90}]
		,"layer": 105
		}]);	
	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_90triangle.png"]
		,"color":[{"r":0,"g":0,b:0}]
		,"scale":[{"x":posScalar*0.25,"y":posScalar*0.25}]
		,"position":[{"x":posScalar*770,"y":posScalar*490}
		,{"duration":9.8,"x":posScalar*640,"y":posScalar*360}]
		,"angle":[{"degreesZ":-90}]
		,"layer": 105
		}]);		
}

Demo.prototype.scene7 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "{xor(animation);}"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
	   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*640,"y":posScalar*360},
		{"duration":9.8,"x":posScalar*340,"y":posScalar*360}]
		,"layer": 107
		}]);	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*640,"y":posScalar*360},
		{"duration":9.8,"x":posScalar*940,"y":posScalar*360}]
		,"layer": 108
		}]);
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.15,"y":posScalar*0.15}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 109
		}]);	
		
		   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "blendNormal(animation);"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.45,"y":posScalar*0.45}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
		
}

Demo.prototype.scene8 = function (start)
{

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "{xor(animation);}"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
	   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_intersection_2.png"]
				,"runFunction": "{xor(animation);}"
		 ,"angle":[{"degreesZ":-45}
		,{"duration":9.8,"degreesZ":0}]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.56,"y":posScalar*0.56}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 117
		}]);	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_intersection_1.png"]
				,"runFunction": "{xor(animation);}"
		 ,"angle":[{"degreesZ":45}
		,{"duration":9.8,"degreesZ":0}]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.56,"y":posScalar*0.56}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 116
		}]);
		
   		
		

		
		
}

Demo.prototype.scene9 = function (start)
{
var angleadjuster=180;
var angleadjuster2=270;
var scalar=1.2;
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "{xor(animation);}"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.23,"y":posScalar*0.23}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 109
		}]);	
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cornercube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*(0.25*scalar),"y":posScalar*(0.25*scalar)}]
		,"position":[{"x":posScalar*(640-128*scalar),"y":posScalar*360}]
		,"layer": 107
		,"angle":[{"degreesZ":0+angleadjuster}
		,{"duration":9.8,"degreesZ":angleadjuster2}]
		}]);

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cornercube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.25*scalar,"y":posScalar*0.25*scalar}]
		,"position":[{"x":posScalar*(640+128*scalar),"y":posScalar*360}]
		,"layer": 107
						,"angle":[{"degreesZ":180+angleadjuster}
		,{"duration":9.8,"degreesZ":180+angleadjuster2}]
		}]);

   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cornercube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*(0.25*scalar),"y":posScalar*(0.25*scalar)}]
		,"position":[{"x":(posScalar*640),"y":posScalar*(360+128*scalar)}]
		,"layer": 107
						,"angle":[{"degreesZ":90+angleadjuster}
		,{"duration":9.8,"degreesZ":90+angleadjuster2}]
		}]);
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cornercube.png"]

		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*(0.25*scalar),"y":posScalar*(0.25*scalar)}]
		,"position":[{"x":posScalar*640,"y":posScalar*(360-128*scalar)}]
		,"layer": 107
						,"angle":[{"degreesZ":270+angleadjuster}
		,{"duration":9.8,"degreesZ":270+angleadjuster2}]
		}]);		
}

Demo.prototype.scene10 = function (start)
{
	   this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube2.png"]
		,"runFunction": "{xor(animation);}"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.05,"y":posScalar*0.05}
		,{"duration":9.8,"x":posScalar*0.4,"y":posScalar*.4}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 111
		}]);	
		
   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": ["minimal_cube.png"]
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*1.3,"y":posScalar*1.3}
		,{"duration":9.8,"x":posScalar*0.4,"y":posScalar*.4}]
		,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"layer": 107

		}]);
		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
			,"image": ["minimal_cube2.png"]
	,"runFunction": "blendNormal(animation);"
		,"color":[{"r":255,"g":255,b:255}]
		,"scale":[{"x":posScalar*0.0,"y":posScalar*0.0}]
		,"position":[{"x":posScalar*740,"y":posScalar*360}]
		,"layer": 1
		}]);	
		
	this.number(95,10);

  
		
}

Demo.prototype.number = function (start,number,color)
{

		
	   		this.loader.addAnimation ([
		{
		 "start": start, "duration": 10
		,"image": [number+".png"]
		,"color":[{"r":color,"g":color,b:color}]
		,"scale":[{"x":posScalar*.5,"y":posScalar*.5}]
		,"position":[{"x":posScalar*1180,"y":posScalar*620}]
		,"layer": 511
		}]);

}

Demo.prototype.flash = function (start,color)
{
	
   		this.loader.addAnimation([{
         "start": start, "duration": 10,"layer": 99999
        ,"image": "white.png"
		,"scale":[{"uniform3d":posScalar*200.0}]
			,"position":[{"x":posScalar*640,"y":posScalar*360}]
		,"color":[{"r":color,"g":color,"b":color,"a":255}
		,{"duration":.6,"a":0}]
		 }]);
}	  
function minMax(arr)
{
	
	var bigIndex= arr.indexOf(arr.reduce(function(a, b) {return Math.max(a, b);}, 0));
	var smallIndex= arr.indexOf(arr.reduce(function(a, b) {return Math.min(a, b);}, 1));
		

	arr[bigIndex]=1.0;
	arr[smallIndex]=0.0;
	
	return arr;

}
function slowTime()
{

if (getSceneTimeFromStart()	> prevTime+.04)
	{
		prevTime=getSceneTimeFromStart();
		return getSceneTimeFromStart();
	}
	else
	return prevTime;

}