web/static/res/js/incmosaic.js
author Edwin Razafimahatratra <edwin@robotalismsoft.com>
Tue, 13 Nov 2012 22:18:07 +0100
changeset 30 6d5b46559bd9
parent 29 c9c75ab3de3e
child 36 6cd5bc3dc7a2
permissions -rw-r--r--
effet mosaic done
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
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    24
	// Time
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    25
	this.startTime;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    26
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    27
	this.noEffectinfo = new IncEffectInfo();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    28
	this.noEffectinfo.color = new IncColor(255, 255, 255, 1)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    29
	this.noEffectinfo.alpha = 1;
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
	// Functions
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
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    35
	this.addPairImages = function(url1, url2)
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
		var urls = new IncPairUrl(url1, url2);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    38
		this.pairUrl.push(urls);
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
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    41
	this.start = function(canvasId, countX, countY)
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
		// Init the canvas objects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    44
		this.init(canvasId);
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
		// Register effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    47
		this.registerEffects();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    48
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    49
		// Count, square`
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    50
		this.countX = countX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    51
		this.countY = (countY === undefined) ? countX: countY;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    52
		this.squareX = Math.floor(this.canvas.width / this.countX);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    53
		this.squareY = Math.floor(this.canvas.height / this.countY);
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 a random pair images
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    56
		this.setRandomPairImages();
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
		// Set random effect on the squares
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    59
		this.setRandomSquareEffect();
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    60
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    61
		// Time
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    62
		this.startTime = new Date().getTime();
23
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
		// Main loop
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    65
		this.loopCallback();
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    66
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    67
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    68
	this.init = function(canvasId)
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
		// Init canvas objects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    71
		this.canvas = document.getElementById(canvasId);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    72
		this.ctx = this.canvas.getContext('2d');
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    73
		this.ctx.fillStyle = "#000000";
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    74
		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
    75
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    76
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    77
	this.registerEffects = function()
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
		// No effect 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    80
		//-----------------------------------
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    81
		//var noEffect = new IncSquareEffect_NoEffet()
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    82
		//var fullEffect0 = new IncFullEffect(0, 0, noEffect);
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
    83
		//this.effects.push(fullEffect0);
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    84
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    85
		// Create semi random effects
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    86
		for (var i = 0; i < 20; ++i) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    87
			var time1 = this.randomInt(3000, 10000);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    88
			var time2 = this.randomInt(3000, 10000);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    89
			var c1 = this.randomInt(0, 128);
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    90
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    91
			var effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    92
			var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    93
			
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    94
			var effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    95
			var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
    96
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    97
			var fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    98
			this.effects.push(fullEffect1);
23
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) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   115
				var fullEffect = this.effects[this.randomInt(0, this.effects.length)].copy();
23
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
		// Get time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   134
		var time = new Date().getTime();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   135
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   136
		if (time < self.startTime + 3000) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   137
			// Draw the first image
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   138
			self.ctx.drawImage(self.pairImages[0], 0, 0);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   139
			requestAnimationFrame(self.loopCallback);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   140
			return;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   141
		}
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   142
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   143
		// Clear canvas
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   144
		//self.ctx.fillStyle = "#000000";
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   145
		//self.ctx.fillRect(0, 0, self.canvas.width, self.canvas.height);	
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   146
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   147
		// Update effects
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   148
		for (var i = 0; i < self.squareEffects.length; ++i) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   149
			
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   150
			// Update
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   151
			var fullEffect = self.squareEffects[i];
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   152
			fullEffect.update(time);
23
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
			for (var j = 0; j < 2; ++j) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   155
				var effectInfo = fullEffect.effectInfos[j];
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   156
				if (effectInfo !== null) {
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   157
					// Draw square
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   158
					self.drawSquare(fullEffect, self.pairImages[j], effectInfo);	
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   159
				}
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
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   162
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   163
		// Loop
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   164
		requestAnimationFrame(self.loopCallback);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   165
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   166
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   167
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   168
	this.drawSquare = function(fullEffect, image, effectInfo)
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   169
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   170
		// Compute square position
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   171
		var posX = fullEffect.x * this.squareX;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   172
		var posY = fullEffect.y * this.squareY;
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
		this.ctx.save();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   175
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   176
		// Global alpha
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   177
		this.ctx.globalAlpha = effectInfo.alpha;	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   178
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   179
		// Draw colored rectangle
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   180
		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
   181
		this.ctx.fillRect(posX, posY, this.squareX, this.squareY);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   182
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   183
		// Draw image
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   184
		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
   185
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   186
		this.ctx.restore();
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
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
	// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   191
	// --------------------------------------------------------------------------------------------------------------------
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
	this.randomInt = function(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
		return Math.floor(this.randomFloat(min, max));
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   196
	};
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
	this.randomFloat = function(min, max)
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
		return Math.random() * (max - min) + min;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   201
	};
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
	this.getImageFromUrl = function(url)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   204
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   205
		var image = new Image();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   206
		image.onload = function() {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   207
			incMosaic.imagesLoaded += 1;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   208
		};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   209
		image.src = url;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   210
		return image;
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
}
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
function IncPairUrl(url1, url2)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   215
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   216
	this.imageUrl1 = url1;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   217
	this.imageUrl2 = url2;
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
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
// Effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   222
// --------------------------------------------------------------------------------------------------------------------
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
function IncColor(r, v, b, a)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   225
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   226
	this.r = r;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   227
	this.v = v;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   228
	this.b = b;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   229
	this.a = a;
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
	this.copy = function()
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
		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
   234
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   235
}
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
function IncAnim(value, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   238
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   239
	this.value = value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   240
	this.time = time;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   241
}
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
function IncEffectInfo()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   244
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   245
	this.color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   246
	this.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   247
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   248
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   249
function IncEffectParams(color, colorAnim, alpha, alphaAnim)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   250
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   251
	// Color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   252
	this.color = color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   253
	this.colorAnim = colorAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   254
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   255
	// Alpha
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   256
	this.alpha = alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   257
	this.alphaAnim = alphaAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   258
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   259
	this.computeColorAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   260
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   261
		return this.computeAnimValue(this.colorAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   262
	};
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
	this.computeAlphaAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   265
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   266
		return this.computeAnimValue(this.alphaAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   267
	};
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
	this.computeAnimValue = function(anim, elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   270
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   271
		// Compute color alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   272
		if (elapsedTime < anim.time) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   273
			return easeFunc(elapsedTime/anim.time) * anim.value;			
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   274
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   275
		return anim.value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   276
	};	
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
function IncSquareEffect_NoEffet()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   280
{
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   281
	this.update = function(time)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   282
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   283
		return incMosaic.noEffectinfo;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   284
	}
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
function IncSquareEffect_Alpha(effectParms, tweenColorFunc, tweenAlphaFunc, waitTime)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   288
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   289
	// Effect parameters
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   290
	this.effectParms = effectParms;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   291
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   292
	// Tween functions
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   293
	this.tweenColorFunc = tweenColorFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   294
	this.tweenAlphaFunc = tweenAlphaFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   295
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   296
	// Time
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   297
	this.waitTime = (waitTime!==undefined) ? waitTime : 0; 
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   298
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   299
	this.update = function(elapsedTime)
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   300
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   301
		var info = new IncEffectInfo();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   302
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   303
		// Compute new color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   304
		var newColorValue = this.effectParms.computeColorAnimValue(elapsedTime, this.tweenColorFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   305
		info.color = this.effectParms.color.copy();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   306
		info.color.a += newColorValue;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   307
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   308
		// Compute alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   309
		var newAlphaValue = this.effectParms.computeAlphaAnimValue(elapsedTime, this.tweenAlphaFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   310
		info.alpha = this.effectParms.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   311
		info.alpha += newAlphaValue;
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
		return info;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   314
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   315
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   316
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   317
function IncFullEffect(effect1, effect2, totalTime1, totalTime2)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   318
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   319
	// Position
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   320
	this.x = 0;
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   321
	this.y = 0;
23
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
	// Effect	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   324
	this.effects = [effect1, effect2];
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   325
	this.effectInfos = [null, null];
23
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
	// Time
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   328
	this.startTime = [0, 0];	
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   329
	this.totalTime = [totalTime1, totalTime2];	
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   330
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   331
	this.copy = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   332
	{
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   333
		return new IncFullEffect(this.effects[0], this.effects[1], this.totalTime[0], this.totalTime[1]);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   334
	};
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   335
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   336
	this.update = function(time)
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   337
	{
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   338
		if (this.startTime[0] == 0) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   339
			this.startTime[0] = time;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   340
			this.startTime[1] = time;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   341
			return;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   342
		}
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   343
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   344
		for (var i = 0; i < 2; ++i) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   345
			// If we are in the good time range we update the effect
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   346
			var waitTime = this.startTime[i] + this.effects[i].waitTime;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   347
			if (time > waitTime && time < this.totalTime[i] + waitTime) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   348
				this.effectInfos[i] = this.effects[i].update(time - waitTime);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   349
			}
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   350
		}
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   351
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   352
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   353
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   354
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   355
// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   356
// --------------------------------------------------------------------------------------------------------------------
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
window.requestAnimationFrame = (function() {              
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   359
	return window.requestAnimationFrame    ||  	// Chromium 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   360
		window.webkitRequestAnimationFrame ||  	// Webkit
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   361
		window.mozRequestAnimationFrame    || 	// Mozilla Geko
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   362
		window.oRequestAnimationFrame      || 	// Opera Presto
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   363
		window.msRequestAnimationFrame     || 	// IE Trident?
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   364
		function(callback, element){ 			// Fallback function
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   365
		   window.setTimeout(callback, 20);                
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   366
		};    
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   367
})();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   368
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   369
var incMosaic = new IncMosaic();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   370