web/static/res/js/incmosaic.js
author ymh <ymh.work@gmail.com>
Tue, 12 Feb 2013 10:54:34 +0100
changeset 134 678b07d351ef
parent 124 8d2376eb825c
permissions -rw-r--r--
Added tag V01.25 for changeset fe9ca5cd905e
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
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
     8
	this.canvasId;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     9
	this.canvas;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    10
	this.ctx;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    11
	this.imageData;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    12
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    13
	/// Images
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
    14
	this.imageUrls = [];
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
    15
	this.listeUrls = [];	// The images list to blend
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    16
	this.pairImages = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    17
	this.imagesLoaded = 0;
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    18
	this.imageLoadedIndex = -1;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    19
	this.imageWidth;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    20
	this.imageHeight;
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    21
	this.postFirstImageCallback;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    22
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    23
	// Effect
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    24
	this.waitStartEffectTime = 3000;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    25
	this.waitStartEffectGo;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    26
	this.effectSpeed;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    27
	this.squareCountX;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    28
	this.squareCountY;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    29
	this.srcSquareWidth;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    30
	this.srcSquareHeight;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    31
	this.squareWidth;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    32
	this.squareHeight;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    33
	this.effects = [];
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    34
	this.squareEffects = [];
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    35
	this.loop;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    36
	this.endEffecFunc;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    37
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    38
	// Time
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    39
	this.startTime;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    40
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    41
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    42
	// Functions
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    43
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    44
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
    45
	this.addImageUrl = function(url)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    46
	{
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
    47
		this.imageUrls.push(url);
23
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
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    50
	this.start = function(canvasId, effectSpeed, squareCountX, squareCountY, loop, waitStartEffectGo, endEffecFunc, postFirstImageCallback)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    51
	{
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    52
		// Canvas ID
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    53
		this.canvasId = canvasId;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    54
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    55
		// Speed
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    56
		this.effectSpeed = 1 / effectSpeed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    57
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    58
		// Set square count
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    59
		this.squareCountX = squareCountX;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    60
		this.squareCountY = (squareCountY === undefined) ? squareCountX: squareCountY;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    61
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    62
		// End effect behavior
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    63
		this.loop = loop;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    64
		this.endEffecFunc = endEffecFunc;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    65
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    66
		// Does the effect wait for go
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    67
		this.waitStartEffectGo = waitStartEffectGo;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    68
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    69
		// callback to call after the load of the first image
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    70
		this.postFirstImageCallback = postFirstImageCallback;
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    71
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    72
		// Init the canvas objects
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
    73
		this.init();
23
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
		// Register effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    76
		this.registerEffects();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    77
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    78
		// Set a new effect transition between 2 images
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    79
		this.setNewEffect();
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    80
										
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    81
		// Main loop
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    82
		this.loopCallback();
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    83
	};
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    84
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    85
	this.setNewEffect = function()
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    86
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    87
		// Set a random pair images
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    88
		this.setRandomPairImages();
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
		// Set random effect on the squares
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    91
		this.setRandomSquareEffect();
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    92
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
    93
		// Time
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
    94
		this.startTime = new Date().getTime();		
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    95
	};
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    96
45
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
    97
	this.UnpauseEffect = function(go)
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
    98
	{
45
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
    99
		this.waitStartEffectGo = !go;
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   100
	};
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   101
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   102
	this.init = function()
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   103
	{
45
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   104
		if (this.canvas === undefined || this.canvas === null) {
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   105
			// Init canvas objects
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   106
			this.canvas = document.getElementById(this.canvasId );
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   107
			this.ctx = this.canvas.getContext('2d');
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   108
			this.ctx.fillStyle = "#000000";
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   109
			this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);			
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   110
		}
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   111
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   112
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   113
	this.registerPostNewCanvasSize = function(newCanvasWidth, newCanvasHeight)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   114
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   115
		// Recalculate the size of the mosaic squares
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   116
		incMosaic.squareWidth = Math.floor(newCanvasWidth / incMosaic.squareCountX);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   117
		incMosaic.squareHeight = Math.floor(newCanvasHeight / incMosaic.squareCountY);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   118
	};
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   119
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   120
	this.fillListUrl = function()
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   121
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   122
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   123
		if (this.waitStartEffectGo) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   124
			// Not Random
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   125
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   126
			for (var i = 0; i < this.imageUrls.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   127
				this.listeUrls.push(this.imageUrls[i]);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   128
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   129
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   130
		} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   131
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   132
			// Random
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   133
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   134
			var urls = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   135
			for (var i = 1; i < this.imageUrls.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   136
				urls.push(this.imageUrls[i]);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   137
			}
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   138
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   139
			// The first images is always the first in this array 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   140
			this.listeUrls.push(this.imageUrls[0]);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   141
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   142
			while (urls.length > 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   143
				var randInd = this.randomInt(0, urls.length);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   144
				this.listeUrls.push(urls[randInd]);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   145
				urls.remove(randInd);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 45
diff changeset
   146
			}
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   147
		}
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   148
	};
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   149
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   150
	this.setRandomPairImages = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   151
	{
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   152
		if (this.listeUrls.length == 0) {
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   153
			this.fillListUrl();
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   154
		}
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   155
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   156
		if (this.pairImages.length == 0) {
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   157
			this.imagesLoaded = 0;
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   158
			this.pairImages.push(this.getImageFromUrl(this.listeUrls[0], 0));
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   159
			this.pairImages.push(this.getImageFromUrl(this.listeUrls[1], 1));
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   160
			this.listeUrls.remove(0);
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   161
		} else {
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   162
			this.imagesLoaded = 1;
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   163
			this.pairImages[0] = this.pairImages[1]; // Swap
124
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 93
diff changeset
   164
			this.pairImages[1] = this.getImageFromUrl(this.listeUrls[0], 999);
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   165
		}
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   166
		this.listeUrls.remove(0);
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   167
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   168
		// Todo preload the next image
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   169
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   170
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   171
	this.setRandomSquareEffect = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   172
	{
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   173
		this.squareEffects.length = 0;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   174
		for (var i = 0; i < this.squareCountX; ++i) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   175
			for (var j = 0; j < this.squareCountY; ++j) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   176
				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
   177
				fullEffect.x = i;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   178
				fullEffect.y = j;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   179
				this.squareEffects.push(fullEffect);				
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
		}
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
		
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   184
	this.loopCallback = function()
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
		var self = incMosaic;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   187
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   188
		if (self.imagesLoaded === 2) {
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   189
			// Redraw
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   190
			self.redraw();
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   191
		} else if (self.imageLoadedIndex === 0) {
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   192
			// Draw first image
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   193
			self.drawFirstImage();
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   194
			self.imageLoadedIndex = -1;
23
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
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   197
		// Loop
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   198
		requestAnimationFrame(self.loopCallback);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   199
	};
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   200
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   201
	this.drawFirstImage = function()
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   202
	{
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   203
		// Draw the first image
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   204
		this.ctx.drawImage(this.pairImages[0], 0, 0, this.srcSquareWidth*this.squareCountX, this.srcSquareHeight*this.squareCountY, 0, 0, this.squareWidth*this.squareCountX, this.squareHeight*this.squareCountY);
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   205
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   206
		if (this.postFirstImageCallback !== null) {
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   207
			this.postFirstImageCallback();
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   208
			this.postFirstImageCallback = null;
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   209
		}
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   210
	};
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   211
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   212
	this.redraw = function()
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   213
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   214
		// Get time
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   215
		var time = new Date().getTime();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   216
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   217
		var timeToWait = (this.startTime + this.waitStartEffectTime)*this.effectSpeed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   218
		if (time < timeToWait || this.waitStartEffectGo) {
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   219
			this.drawFirstImage();
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   220
			return;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   221
		}
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   222
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   223
		// Update effects
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   224
		var effectsContinue = false;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   225
		for (var i = 0; i < this.squareEffects.length; ++i) {			
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   226
			// Update
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   227
			var fullEffect = this.squareEffects[i];
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   228
			effectsContinue = fullEffect.update(time) || effectsContinue;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   229
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   230
			for (var j = 0; j < 2; ++j) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   231
				var effectInfo = fullEffect.effectInfos[j];
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   232
				if (effectInfo !== null) {
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   233
					// Draw square
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   234
					this.drawSquare(fullEffect, this.pairImages[j], effectInfo);	
23
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
			}
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   237
		}
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   238
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   239
		if (!effectsContinue) {
124
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 93
diff changeset
   240
			if (this.endEffecFunc !== undefined && this.endEffecFunc !== null) {
45
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   241
				// Call the end callback
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   242
				var func = this.endEffecFunc;
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   243
				if (!this.loop) {
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   244
					this.endEffecFunc = null;
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   245
				}
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   246
				func();
f7bfdc49982b ecrant choix unique
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 43
diff changeset
   247
			}
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   248
			if (this.loop) {
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   249
				// The effect loop
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   250
				this.setNewEffect();
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   251
			}
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   252
		}	
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   253
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   254
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   255
	this.drawSquare = function(fullEffect, image, effectInfo)
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   256
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   257
		this.ctx.save();
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
		// Global alpha
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   260
		this.ctx.globalAlpha = effectInfo.alpha;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   261
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   262
		// Compute src and dest square position
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   263
		var srcPosX = fullEffect.x * this.srcSquareWidth;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   264
		var srcPosY = fullEffect.y * this.srcSquareHeight;		
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   265
		var destPosX = fullEffect.x * this.squareWidth;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   266
		var destPosY = fullEffect.y * this.squareHeight;		
23
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
		// Draw colored rectangle
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   269
		this.ctx.fillStyle = "rgba(" + effectInfo.color.r + "," + effectInfo.color.v + "," + effectInfo.color.b + "," + effectInfo.color.a + ")";
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   270
		this.ctx.fillRect(destPosX, destPosY, this.squareWidth, this.squareHeight);
23
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
		// Draw image
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   273
		this.ctx.drawImage(image, srcPosX, srcPosY, this.srcSquareWidth, this.srcSquareHeight, destPosX, destPosY, this.squareWidth, this.squareHeight);
23
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
		this.ctx.restore();
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
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   278
	this.registerEffects = function()
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   279
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   280
		var count = 7;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   281
		var color = 64;
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   282
		var speed = this.effectSpeed;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   283
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   284
		// Create semi random effects
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   285
		var range1 = 3000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   286
		var range2 = 5000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   287
		this.registerEffectsTime(count, color, range1, range2);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   288
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   289
		// Create semi random effects
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   290
		range1 = 7000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   291
		range2 = 15000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   292
		this.registerEffectsTime(count, color, range1, range2);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   293
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   294
		// Create semi random effects
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   295
		range1 = 17000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   296
		range2 = 23000 * speed;
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   297
		this.registerEffectsTime(count, color, range1, range2);
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   298
	};
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   299
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   300
	this.registerEffectsTime = function(count, color, range1, range2)
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   301
	{
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   302
		for (var i = 0; i < count; ++i) {
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   303
			var time1 = this.randomInt(range1, range2);
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   304
			var time2 = this.randomInt(range1, range2);
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   305
			var c1 = this.randomInt(0, color);
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   306
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   307
			var effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   308
			var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   309
			
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   310
			var effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   311
			var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   312
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   313
			var fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   314
			this.effects.push(fullEffect1);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   315
		}
42
01415303372e écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 39
diff changeset
   316
	};
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   317
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
	// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   320
	// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   321
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   322
	this.randomInt = function(min, max)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   323
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   324
		return Math.floor(this.randomFloat(min, max));
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
	this.randomFloat = function(min, max)
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
		return Math.random() * (max - min) + min;
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
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   332
	this.getImageFromUrl = function(url, index)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   333
	{
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   334
		var self = incMosaic;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   335
		var image = new Image();
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   336
		var ind = index;
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   337
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   338
		image.onload = function() {
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   339
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   340
			self.imageLoadedIndex = ind;
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   341
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   342
			// When the first image is loaded we can get the image dimention and init the autoresize of the canvas
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   343
			if (self.imagesLoaded === 0) {
93
7c37aaa2a8ae netoyage update du rep static
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   344
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   345
				// Set some image size related vars
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   346
				self.imageWidth = image.width;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   347
				self.imageHeight = image.height;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   348
				self.srcSquareWidth = image.width / self.squareCountX;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   349
				self.srcSquareHeight = image.height / self.squareCountY;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   350
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   351
				// Call the resize object
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   352
				if (incResize !== undefined) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   353
					incResize.resizeElements();
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   354
				}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   355
			}			
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   356
			self.imagesLoaded += 1;
23
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
		image.src = url;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   359
		return image;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   360
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   361
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   362
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   363
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   364
// Effects
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   365
// --------------------------------------------------------------------------------------------------------------------
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
function IncColor(r, v, b, a)
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
	this.r = r;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   370
	this.v = v;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   371
	this.b = b;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   372
	this.a = a;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   373
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   374
	this.copy = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   375
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   376
		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
   377
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   378
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   379
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   380
function IncAnim(value, time)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   381
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   382
	this.value = value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   383
	this.time = time;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   384
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   385
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   386
function IncEffectInfo()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   387
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   388
	this.color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   389
	this.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   390
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   391
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   392
function IncEffectParams(color, colorAnim, alpha, alphaAnim)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   393
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   394
	// Color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   395
	this.color = color;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   396
	this.colorAnim = colorAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   397
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   398
	// Alpha
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   399
	this.alpha = alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   400
	this.alphaAnim = alphaAnim;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   401
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   402
	this.computeColorAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   403
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   404
		return this.computeAnimValue(this.colorAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   405
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   406
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   407
	this.computeAlphaAnimValue = function(elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   408
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   409
		return this.computeAnimValue(this.alphaAnim, elapsedTime, easeFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   410
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   411
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   412
	this.computeAnimValue = function(anim, elapsedTime, easeFunc)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   413
	{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   414
		// Compute color alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   415
		if (elapsedTime < anim.time) {
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   416
			return easeFunc(elapsedTime/anim.time) * anim.value;			
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   417
		}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   418
		return anim.value;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   419
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   420
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   421
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   422
function IncSquareEffect_Alpha(effectParms, tweenColorFunc, tweenAlphaFunc, waitTime)
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   423
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   424
	// Effect parameters
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   425
	this.effectParms = effectParms;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   426
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   427
	// Tween functions
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   428
	this.tweenColorFunc = tweenColorFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   429
	this.tweenAlphaFunc = tweenAlphaFunc;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   430
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   431
	// Time
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   432
	this.waitTime = (waitTime!==undefined) ? waitTime : 0; 
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   433
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   434
	this.update = function(elapsedTime)
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   435
	{
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   436
		var info = new IncEffectInfo();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   437
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   438
		// Compute new color
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   439
		var newColorValue = this.effectParms.computeColorAnimValue(elapsedTime, this.tweenColorFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   440
		info.color = this.effectParms.color.copy();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   441
		info.color.a += newColorValue;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   442
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   443
		// Compute alpha anim
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   444
		var newAlphaValue = this.effectParms.computeAlphaAnimValue(elapsedTime, this.tweenAlphaFunc);
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   445
		info.alpha = this.effectParms.alpha;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   446
		info.alpha += newAlphaValue;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   447
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   448
		return info;
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   449
	};
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   450
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   451
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   452
function IncFullEffect(effect1, effect2, totalTime1, totalTime2)
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   453
{
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   454
	// Position
29
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   455
	this.x = 0;
c9c75ab3de3e avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 23
diff changeset
   456
	this.y = 0;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   457
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   458
	// Effect	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   459
	this.effects = [effect1, effect2];
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   460
	this.effectInfos = [null, null];
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   461
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   462
	// Time
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   463
	this.startTime = [0, 0];	
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   464
	this.totalTime = [totalTime1, totalTime2];	
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   465
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   466
	this.copy = function()
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   467
	{
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   468
		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
   469
	};
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   470
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   471
	this.update = function(time)
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   472
	{
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 30
diff changeset
   473
		if (this.startTime[0] === 0) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   474
			this.startTime[0] = time;
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   475
			this.startTime[1] = time;
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   476
			return true;
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   477
		}
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   478
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   479
		for (var i = 0; i < 2; ++i) {
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   480
			// 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
   481
			var waitTime = this.startTime[i] + this.effects[i].waitTime;
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   482
			var updateEffect = time < this.totalTime[i] + waitTime;
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   483
			if (time > waitTime && updateEffect) {
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   484
				this.effectInfos[i] = this.effects[i].update(time - waitTime);
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   485
			}
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   486
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   487
			if (i == 1 && !updateEffect) {
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   488
				// The effect is done
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   489
				return false;
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   490
			}
30
6d5b46559bd9 effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 29
diff changeset
   491
		}
38
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   492
cdbb56b876c9 mosaic effect loops
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   493
		return true;
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   494
	};	
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   495
}
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   496
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   497
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   498
// Tools
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   499
// --------------------------------------------------------------------------------------------------------------------
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   500
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   501
window.requestAnimationFrame = (function() {              
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   502
	return window.requestAnimationFrame    ||  	// Chromium 
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   503
		window.webkitRequestAnimationFrame ||  	// Webkit
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   504
		window.mozRequestAnimationFrame    || 	// Mozilla Geko
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   505
		window.oRequestAnimationFrame      || 	// Opera Presto
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   506
		window.msRequestAnimationFrame     || 	// IE Trident?
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   507
		function(callback, element){ 			// Fallback function
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   508
		   window.setTimeout(callback, 20);                
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   509
		};    
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   510
})();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   511
39
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   512
Array.prototype.remove = function(from, to) {
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   513
  var rest = this.slice((to || from) + 1 || this.length);
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   514
  this.length = from < 0 ? this.length + from : from;
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   515
  return this.push.apply(this, rest);
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   516
};
6605de5fe0bd mosaic effect done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 38
diff changeset
   517
23
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   518
var incMosaic = new IncMosaic();
45b05706b516 mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   519