web/static/res/js/incmosaic.js
author Edwin Razafimahatratra <edwin@robotalismsoft.com>
Mon, 22 Oct 2012 12:03:53 +0200
changeset 23 45b05706b516
child 29 c9c75ab3de3e
permissions -rw-r--r--
mosaic effect js first test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     1
function IncMosaic()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     2
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     3
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     4
	// Members
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     5
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     6
	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     7
	// Canvas
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     8
	this.canvas;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     9
	this.context;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    10
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    11
	/// Images
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    12
	this.pairUrl = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    13
	this.pairImages = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    14
	this.imagesLoaded = 0;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    15
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    16
	// Effect
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    17
	this.countX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    18
	this.countY;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    19
	this.squareX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    20
	this.squareY;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    21
	this.effects = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    22
	this.squareEffects = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    24
	this.noEffectinfo = new IncEffectInfo();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    25
	this.noEffectinfo.color = new IncColor(255, 255, 255, 1)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    26
	this.noEffectinfo.alpha = 1;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    27
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    28
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    29
	// Functions
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    30
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    31
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    32
	this.addPairImages = function(url1, url2)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    33
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    34
		var urls = new IncPairUrl(url1, url2);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    35
		this.pairUrl.push(urls);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    36
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    37
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    38
	this.start = function(canvasId, countX, countY)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    39
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    40
		// Init the canvas objects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    41
		this.init(canvasId);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    42
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    43
		// Register effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    44
		this.registerEffects();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    45
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    46
		// Count, square`
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    47
		this.countX = countX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    48
		this.countY = (countY === undefined) ? countX: countY;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    49
		this.squareX = Math.floor(this.canvas.width / this.countX);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    50
		this.squareY = Math.floor(this.canvas.height / this.countY);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    51
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    52
		// Set a random pair images
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    53
		this.setRandomPairImages();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    54
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    55
		// Set random effect on the squares
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    56
		this.setRandomSquareEffect();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    57
										
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    58
		// Main loop
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    59
		this.loopCallback();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    60
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    61
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    62
	this.init = function(canvasId)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    63
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    64
		// Init canvas objects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    65
		this.canvas = document.getElementById(canvasId);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    66
		this.ctx = this.canvas.getContext('2d');
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    67
		this.ctx.fillStyle = "#000000";
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    68
		this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    69
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    70
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    71
	this.registerEffects = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    72
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    73
		// No effect 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    74
		//-----------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    75
		var noEffect = new IncSquareEffect_NoEffet()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    76
		var fullEffect0 = new IncFullEffect(0, 0, noEffect);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    77
		this.effects.push(fullEffect0);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    78
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    79
		// Alpha 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    80
		//-----------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    81
		{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    82
			var effectParam1 = new IncEffectParams(new IncColor(255, 255, 255, 0), new IncAnim(1, 5000), 1, new IncAnim(-1, 5000), 8000);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    83
			var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.linear, createjs.Ease.linear);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    84
			var effectParam2 = new IncEffectParams(new IncColor(255, 255, 255, 1), new IncAnim(0, 5000), 0, new IncAnim(1, 5000), 8000);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    85
			var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.linear, createjs.Ease.linear, 2500);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    86
			var fullEffect1 = new IncFullEffect(1, 1, effect2, effect1);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    87
			this.effects.push(fullEffect1);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    88
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    89
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    90
		// Alpha 2
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    91
		//-----------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    92
		{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    93
			var effectParam1 = new IncEffectParams(new IncColor(32, 32, 32, 0), new IncAnim(1, 5000), 1, new IncAnim(-1, 5000), 8000);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    94
			var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.linear, createjs.Ease.linear);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    95
			var effectParam2 = new IncEffectParams(new IncColor(32, 32, 32, 1), new IncAnim(0, 5000), 0, new IncAnim(1, 5000), 8000);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    96
			var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.linear, createjs.Ease.linear, 2500);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    97
			var fullEffect1 = new IncFullEffect(1, 1, effect2, effect1);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    98
			this.effects.push(fullEffect1);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    99
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   100
	}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   101
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   102
	this.setRandomPairImages = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   103
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   104
		this.imagesLoaded = 0;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   105
		var randInd = this.randomInt(0, this.pairUrl.length);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   106
		var pairUrl = this.pairUrl[randInd];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   107
		this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl1));
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   108
		this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl2));
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   109
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   110
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   111
	this.setRandomSquareEffect = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   112
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   113
		for (var i = 0; i < this.countX; ++i) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   114
			for (var j = 0; j < this.countY; ++j) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   115
				var fullEffect = this.effects[this.randomInt(0, this.effects.length)].copy();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   116
				fullEffect.x = i;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   117
				fullEffect.y = j;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   118
				this.squareEffects.push(fullEffect);				
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   119
			}			
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   120
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   121
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   122
		
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   123
	this.loopCallback = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   124
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   125
		var self = incMosaic;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   126
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   127
		if (self.imagesLoaded != 2) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   128
			// Images are not loaded yet
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   129
			requestAnimationFrame(self.loopCallback);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   130
			return;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   131
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   132
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   133
		// Clear canvas
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   134
		self.ctx.fillStyle = "#ffffff";
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   135
		self.ctx.fillStyle = "#000000";
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   136
		self.ctx.fillRect(0, 0, self.canvas.width, self.canvas.height);	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   137
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   138
		// Get time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   139
		var time = new Date().getTime();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   140
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   141
		// Update effect
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   142
		for (var i = 0; i < self.squareEffects.length; ++i) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   143
			var fullEffect = self.squareEffects[i];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   144
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   145
			for (var j = 0; j < 2; ++j) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   146
				var effect = fullEffect.effects[j];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   147
				if (effect !== undefined) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   148
					// Draw square
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   149
					self.drawSquare(fullEffect, self.pairImages[j], effect, time);									
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   150
				}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   151
			}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   152
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   153
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   154
		// Loop
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   155
		requestAnimationFrame(self.loopCallback);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   156
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   157
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   158
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   159
	this.drawSquare = function(fullEffect, image, effect, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   160
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   161
		// Update effect
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   162
		var effectInfo = effect.update(fullEffect, time);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   163
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   164
		if (effectInfo === null) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   165
			return;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   166
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   167
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   168
		// Compute square position
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   169
		var posX = fullEffect.x * this.squareX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   170
		var posY = fullEffect.y * this.squareY;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   171
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   172
		this.ctx.save();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   173
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   174
		// Global alpha
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   175
		this.ctx.globalAlpha = effectInfo.alpha;	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   176
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   177
		// Draw colored rectangle
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   178
		this.ctx.fillStyle = "rgba(" + effectInfo.color.r + "," + effectInfo.color.v + "," + effectInfo.color.b + "," + effectInfo.color.a + ")";
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   179
		this.ctx.fillRect(posX, posY, this.squareX, this.squareY);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   180
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   181
		// Draw image
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   182
		this.ctx.drawImage(image, posX, posY, this.squareX, this.squareY, posX, posY, this.squareX, this.squareY);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   183
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   184
		this.ctx.restore();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   185
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   186
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   187
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   188
	// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   189
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   190
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   191
	this.randomInt = function(min, max)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   192
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   193
		return Math.floor(this.randomFloat(min, max));
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   194
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   195
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   196
	this.randomFloat = function(min, max)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   197
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   198
		return Math.random() * (max - min) + min;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   199
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   200
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   201
	this.getImageFromUrl = function(url)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   202
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   203
		var image = new Image();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   204
		image.onload = function() {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   205
			incMosaic.imagesLoaded += 1;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   206
		};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   207
		image.src = url;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   208
		return image;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   209
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   210
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   211
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   212
function IncPairUrl(url1, url2)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   213
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   214
	this.imageUrl1 = url1;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   215
	this.imageUrl2 = url2;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   216
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   217
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   218
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   219
// Effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   220
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   221
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   222
function IncColor(r, v, b, a)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   223
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   224
	this.r = r;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   225
	this.v = v;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   226
	this.b = b;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   227
	this.a = a;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   228
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   229
	this.copy = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   230
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   231
		return new IncColor(this.r, this.v, this.b, this.a);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   232
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   233
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   234
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   235
function IncAnim(value, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   236
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   237
	this.value = value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   238
	this.time = time;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   239
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   240
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   241
function IncEffectInfo()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   242
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   243
	this.color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   244
	this.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   245
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   246
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   247
function IncEffectParams(color, colorAnim, alpha, alphaAnim, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   248
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   249
	// Color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   250
	this.color = color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   251
	this.colorAnim = colorAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   252
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   253
	// Alpha
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   254
	this.alpha = alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   255
	this.alphaAnim = alphaAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   256
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   257
	// Time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   258
	this.time = time;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   259
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   260
	this.computeColorAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   261
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   262
		return this.computeAnimValue(this.colorAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   263
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   264
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   265
	this.computeAlphaAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   266
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   267
		return this.computeAnimValue(this.alphaAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   268
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   269
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   270
	this.computeAnimValue = function(anim, elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   271
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   272
		// Compute color alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   273
		if (elapsedTime < anim.time) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   274
			return easeFunc(elapsedTime/anim.time) * anim.value;			
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   275
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   276
		return anim.value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   277
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   278
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   279
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   280
function IncSquareEffect_NoEffet()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   281
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   282
	this.update = function(fullEffect, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   283
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   284
		return incMosaic.noEffectinfo;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   285
	}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   286
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   287
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   288
function IncSquareEffect_Alpha(effectParms, tweenColorFunc, tweenAlphaFunc, waitTime)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   289
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   290
	// Effect parameters
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   291
	this.effectParms = effectParms;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   292
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   293
	// Tween functions
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   294
	this.tweenColorFunc = tweenColorFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   295
	this.tweenAlphaFunc = tweenAlphaFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   296
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   297
	// Time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   298
	this.waitTime = (waitTime!==undefined) ? (new Date().getTime() + waitTime) : 0; 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   299
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   300
	this.update = function(fullEffect, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   301
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   302
		if (this.waitTime > time) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   303
			return null;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   304
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   305
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   306
		if (fullEffect.startTime == 0) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   307
			fullEffect.startTime = time;			
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   308
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   309
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   310
		var elapsedTime = time - fullEffect.startTime;		
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   311
		var info = new IncEffectInfo();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   312
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   313
		// Compute new color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   314
		var newColorValue = this.effectParms.computeColorAnimValue(elapsedTime, this.tweenColorFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   315
		info.color = this.effectParms.color.copy();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   316
		info.color.a += newColorValue;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   317
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   318
		// Compute alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   319
		var newAlphaValue = this.effectParms.computeAlphaAnimValue(elapsedTime, this.tweenAlphaFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   320
		info.alpha = this.effectParms.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   321
		info.alpha += newAlphaValue;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   322
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   323
		return info;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   324
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   325
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   326
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   327
function IncFullEffect(x, y, effect1, effect2)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   328
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   329
	// Position
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   330
	this.x = x;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   331
	this.y = y;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   332
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   333
	// Effect	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   334
	this.effects = [effect1, effect2];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   335
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   336
	// Time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   337
	this.startTime = 0;	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   338
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   339
	this.copy = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   340
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   341
		return new IncFullEffect(this.x, this.y, this.effects[0], this.effects.length > 1 ? this.effects[1] : undefined);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   342
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   343
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   344
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   345
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   346
// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   347
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   348
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   349
window.requestAnimationFrame = (function() {              
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   350
	return window.requestAnimationFrame    ||  	// Chromium 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   351
		window.webkitRequestAnimationFrame ||  	// Webkit
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   352
		window.mozRequestAnimationFrame    || 	// Mozilla Geko
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   353
		window.oRequestAnimationFrame      || 	// Opera Presto
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   354
		window.msRequestAnimationFrame     || 	// IE Trident?
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   355
		function(callback, element){ 			// Fallback function
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   356
		   window.setTimeout(callback, 20);                
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   357
		};    
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   358
})();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   359
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   360
var incMosaic = new IncMosaic();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   361