| author | Edwin Razafimahatratra <edwin@robotalismsoft.com> |
| Sun, 09 Dec 2012 19:59:03 +0100 | |
| changeset 36 | 6cd5bc3dc7a2 |
| parent 30 | 6d5b46559bd9 |
| child 38 | cdbb56b876c9 |
| permissions | -rw-r--r-- |
|
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 | 8 |
this.canvasId; |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
9 |
this.canvas; |
| 36 | 10 |
this.ctx; |
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 |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
14 |
this.pairUrl = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
15 |
this.pairImages = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
16 |
this.imagesLoaded = 0; |
| 36 | 17 |
this.imageWidth; |
18 |
this.imageHeight; |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
19 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
20 |
// Effect |
| 36 | 21 |
this.squareCountX; |
22 |
this.squareCountY; |
|
23 |
this.srcSquareWidth; |
|
24 |
this.srcSquareHeight; |
|
25 |
this.squareWidth; |
|
26 |
this.squareHeight; |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
27 |
this.effects = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
28 |
this.squareEffects = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
29 |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
30 |
// Time |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
31 |
this.startTime; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
32 |
|
|
23
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 |
// Functions |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
35 |
// -------------------------------------------------------------------------------------------------------------------- |
|
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 |
this.addPairImages = function(url1, url2) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
38 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
39 |
var urls = new IncPairUrl(url1, url2); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
40 |
this.pairUrl.push(urls); |
|
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 |
|
| 36 | 43 |
this.start = function(canvasId, squareCountX, squareCountY) |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
44 |
{ |
| 36 | 45 |
// Canvas ID |
46 |
this.canvasId = canvasId; |
|
47 |
||
48 |
// Set square count |
|
49 |
this.squareCountX = squareCountX; |
|
50 |
this.squareCountY = (squareCountY === undefined) ? squareCountX: squareCountY; |
|
51 |
||
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
52 |
// Init the canvas objects |
| 36 | 53 |
this.init(); |
|
23
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 |
// Register effects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
56 |
this.registerEffects(); |
|
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 a random pair images |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
59 |
this.setRandomPairImages(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
60 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
61 |
// Set random effect on the squares |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
62 |
this.setRandomSquareEffect(); |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
63 |
|
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
64 |
// Time |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
65 |
this.startTime = new Date().getTime(); |
|
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 |
// Main loop |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
68 |
this.loopCallback(); |
|
23
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 |
|
| 36 | 71 |
this.init = function() |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
72 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
73 |
// Init canvas objects |
| 36 | 74 |
this.canvas = document.getElementById(this.canvasId ); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
75 |
this.ctx = this.canvas.getContext('2d'); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
76 |
this.ctx.fillStyle = "#000000"; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
77 |
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
|
78 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
79 |
|
| 36 | 80 |
this.registerPreNewCanvasSize = function(newCanvasWidth, newCanvasHeight) |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
81 |
{ |
| 36 | 82 |
//incMosaic.imageData = incMosaic.ctx.getImageData(0, 0, incMosaic.srcSquareWidth*incMosaic.squareCountX, incMosaic.srcSquareHeight*incMosaic.squareCountY); |
83 |
}; |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
84 |
|
| 36 | 85 |
this.registerPostNewCanvasSize = function(newCanvasWidth, newCanvasHeight) |
86 |
{ |
|
87 |
// Recalculate the size of the mosaic squares |
|
88 |
incMosaic.squareWidth = Math.floor(newCanvasWidth / incMosaic.squareCountX); |
|
89 |
incMosaic.squareHeight = Math.floor(newCanvasHeight / incMosaic.squareCountY); |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
90 |
|
| 36 | 91 |
//incMosaic.ctx.fillStyle = "#000000"; |
92 |
//incMosaic.ctx.fillRect(0, 0, incMosaic.srcSquareWidth*incMosaic.squareCountX, incMosaic.srcSquareHeight*incMosaic.squareCountY); |
|
93 |
//incMosaic.ctx.putImageData(incMosaic.imageData, 0, 0); |
|
94 |
}; |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
95 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
96 |
this.setRandomPairImages = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
97 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
98 |
this.imagesLoaded = 0; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
99 |
var randInd = this.randomInt(0, this.pairUrl.length); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
100 |
var pairUrl = this.pairUrl[randInd]; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
101 |
this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl1)); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
102 |
this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl2)); |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
105 |
this.setRandomSquareEffect = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
106 |
{ |
| 36 | 107 |
for (var i = 0; i < this.squareCountX; ++i) { |
108 |
for (var j = 0; j < this.squareCountY; ++j) { |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
109 |
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
|
110 |
fullEffect.x = i; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
111 |
fullEffect.y = j; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
112 |
this.squareEffects.push(fullEffect); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
113 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
114 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
115 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
116 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
117 |
this.loopCallback = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
118 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
119 |
var self = incMosaic; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
120 |
|
| 36 | 121 |
if (self.imagesLoaded == 2) { |
122 |
// Redraw |
|
123 |
self.redraw(); |
|
|
23
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 |
|
| 36 | 126 |
// Loop |
127 |
requestAnimationFrame(self.loopCallback); |
|
128 |
}; |
|
129 |
||
130 |
this.redraw = function() |
|
131 |
{ |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
132 |
// Get time |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
133 |
var time = new Date().getTime(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
134 |
|
| 36 | 135 |
if (time < this.startTime + 3000) { |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
136 |
// Draw the first image |
| 36 | 137 |
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); |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
138 |
return; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
139 |
} |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
140 |
|
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
141 |
// Update effects |
| 36 | 142 |
for (var i = 0; i < this.squareEffects.length; ++i) { |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
143 |
// Update |
| 36 | 144 |
var fullEffect = this.squareEffects[i]; |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
145 |
fullEffect.update(time); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
146 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
147 |
for (var j = 0; j < 2; ++j) { |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
148 |
var effectInfo = fullEffect.effectInfos[j]; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
149 |
if (effectInfo !== null) { |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
150 |
// Draw square |
| 36 | 151 |
this.drawSquare(fullEffect, this.pairImages[j], effectInfo); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
152 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
153 |
} |
| 36 | 154 |
} |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
155 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
156 |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
157 |
this.drawSquare = function(fullEffect, image, effectInfo) |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
158 |
{ |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
159 |
this.ctx.save(); |
|
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 |
// Global alpha |
| 36 | 162 |
this.ctx.globalAlpha = effectInfo.alpha; |
163 |
||
164 |
// Compute src and dest square position |
|
165 |
var srcPosX = fullEffect.x * this.srcSquareWidth; |
|
166 |
var srcPosY = fullEffect.y * this.srcSquareHeight; |
|
167 |
var destPosX = fullEffect.x * this.squareWidth; |
|
168 |
var destPosY = fullEffect.y * this.squareHeight; |
|
|
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 |
// Draw colored rectangle |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
171 |
this.ctx.fillStyle = "rgba(" + effectInfo.color.r + "," + effectInfo.color.v + "," + effectInfo.color.b + "," + effectInfo.color.a + ")"; |
| 36 | 172 |
this.ctx.fillRect(destPosX, destPosY, this.squareWidth, this.squareHeight); |
|
23
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 |
// Draw image |
| 36 | 175 |
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
|
176 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
177 |
this.ctx.restore(); |
|
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 |
|
| 36 | 180 |
this.registerEffects = function() |
181 |
{ |
|
182 |
var count = 7; |
|
183 |
var color = 64; |
|
184 |
||
185 |
// Create semi random effects |
|
186 |
var range1 = 3000; |
|
187 |
var range2 = 7000; |
|
188 |
||
189 |
var i, time1, time2, effectParam1, effect1, effectParam2, effect2, fullEffect1; |
|
190 |
for (i = 0; i < count; ++i) { |
|
191 |
time1 = this.randomInt(range1, range2); |
|
192 |
time2 = this.randomInt(range1, range2); |
|
193 |
c1 = this.randomInt(0, color); |
|
194 |
||
195 |
effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1)); |
|
196 |
effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut); |
|
197 |
|
|
198 |
effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2)); |
|
199 |
effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5); |
|
200 |
||
201 |
fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2); |
|
202 |
this.effects.push(fullEffect1); |
|
203 |
} |
|
204 |
||
205 |
// Create semi random effects |
|
206 |
range1 = 10000; |
|
207 |
range2 = 25000; |
|
208 |
for (i = 0; i < count; ++i) { |
|
209 |
time1 = this.randomInt(range1, range2); |
|
210 |
time2 = this.randomInt(range1, range2); |
|
211 |
c1 = this.randomInt(0, color); |
|
212 |
||
213 |
effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1)); |
|
214 |
effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut); |
|
215 |
|
|
216 |
effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2)); |
|
217 |
effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5); |
|
218 |
||
219 |
fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2); |
|
220 |
this.effects.push(fullEffect1); |
|
221 |
} |
|
222 |
||
223 |
// Create semi random effects |
|
224 |
range1 = 25000; |
|
225 |
range2 = 30000; |
|
226 |
for (i = 0; i < count; ++i) { |
|
227 |
time1 = this.randomInt(range1, range2); |
|
228 |
time2 = this.randomInt(range1, range2); |
|
229 |
c1 = this.randomInt(0, color); |
|
230 |
||
231 |
effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1)); |
|
232 |
effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut); |
|
233 |
|
|
234 |
effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2)); |
|
235 |
effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5); |
|
236 |
||
237 |
fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2); |
|
238 |
this.effects.push(fullEffect1); |
|
239 |
} |
|
240 |
}; |
|
241 |
||
|
23
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 |
// Tools |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
246 |
this.randomInt = function(min, max) |
|
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 |
return Math.floor(this.randomFloat(min, max)); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
249 |
}; |
|
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 |
this.randomFloat = function(min, max) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
252 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
253 |
return Math.random() * (max - min) + min; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
256 |
this.getImageFromUrl = function(url) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
257 |
{ |
| 36 | 258 |
var self = incMosaic; |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
259 |
var image = new Image(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
260 |
image.onload = function() { |
| 36 | 261 |
// When the first image is loaded we can get the image dimention and init the autoresize of the canvas |
262 |
if (self.imagesLoaded === 0) { |
|
263 |
// Set some image size related vars |
|
264 |
self.imageWidth = image.width; |
|
265 |
self.imageHeight = image.height; |
|
266 |
self.srcSquareWidth = image.width / self.squareCountX; |
|
267 |
self.srcSquareHeight = image.height / self.squareCountY; |
|
268 |
||
269 |
// Call the resize object |
|
270 |
if (incResize !== undefined) { |
|
271 |
incResize.resizeElements(); |
|
272 |
} |
|
273 |
} |
|
274 |
self.imagesLoaded += 1; |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
275 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
276 |
image.src = url; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
277 |
return image; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
278 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
279 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
280 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
281 |
function IncPairUrl(url1, url2) |
|
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 |
this.imageUrl1 = url1; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
284 |
this.imageUrl2 = url2; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
285 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
286 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
287 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
288 |
// Effects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
289 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
290 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
291 |
function IncColor(r, v, b, a) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
292 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
293 |
this.r = r; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
294 |
this.v = v; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
295 |
this.b = b; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
296 |
this.a = a; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
297 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
298 |
this.copy = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
299 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
300 |
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
|
301 |
}; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
304 |
function IncAnim(value, time) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
305 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
306 |
this.value = value; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
307 |
this.time = time; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
308 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
309 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
310 |
function IncEffectInfo() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
311 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
312 |
this.color; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
313 |
this.alpha; |
|
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 |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
316 |
function IncEffectParams(color, colorAnim, alpha, alphaAnim) |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
317 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
318 |
// Color |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
319 |
this.color = color; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
320 |
this.colorAnim = colorAnim; |
|
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 |
// Alpha |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
323 |
this.alpha = alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
324 |
this.alphaAnim = alphaAnim; |
|
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 |
this.computeColorAnimValue = function(elapsedTime, easeFunc) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
327 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
328 |
return this.computeAnimValue(this.colorAnim, elapsedTime, easeFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
329 |
}; |
|
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.computeAlphaAnimValue = function(elapsedTime, easeFunc) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
332 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
333 |
return this.computeAnimValue(this.alphaAnim, elapsedTime, easeFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
334 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
335 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
336 |
this.computeAnimValue = function(anim, elapsedTime, easeFunc) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
337 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
338 |
// Compute color alpha anim |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
339 |
if (elapsedTime < anim.time) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
340 |
return easeFunc(elapsedTime/anim.time) * anim.value; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
341 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
342 |
return anim.value; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
343 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
344 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
345 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
346 |
function IncSquareEffect_Alpha(effectParms, tweenColorFunc, tweenAlphaFunc, waitTime) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
347 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
348 |
// Effect parameters |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
349 |
this.effectParms = effectParms; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
350 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
351 |
// Tween functions |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
352 |
this.tweenColorFunc = tweenColorFunc; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
353 |
this.tweenAlphaFunc = tweenAlphaFunc; |
|
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 |
// Time |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
356 |
this.waitTime = (waitTime!==undefined) ? waitTime : 0; |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
357 |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
358 |
this.update = function(elapsedTime) |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
359 |
{ |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
360 |
var info = new IncEffectInfo(); |
|
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 |
// Compute new color |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
363 |
var newColorValue = this.effectParms.computeColorAnimValue(elapsedTime, this.tweenColorFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
364 |
info.color = this.effectParms.color.copy(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
365 |
info.color.a += newColorValue; |
|
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 |
// Compute alpha anim |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
368 |
var newAlphaValue = this.effectParms.computeAlphaAnimValue(elapsedTime, this.tweenAlphaFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
369 |
info.alpha = this.effectParms.alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
370 |
info.alpha += newAlphaValue; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
371 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
372 |
return info; |
|
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 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
375 |
|
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
376 |
function IncFullEffect(effect1, effect2, totalTime1, totalTime2) |
|
23
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 |
// Position |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
379 |
this.x = 0; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
380 |
this.y = 0; |
|
23
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 |
// Effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
383 |
this.effects = [effect1, effect2]; |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
384 |
this.effectInfos = [null, null]; |
|
23
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 |
// Time |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
387 |
this.startTime = [0, 0]; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
388 |
this.totalTime = [totalTime1, totalTime2]; |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
389 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
390 |
this.copy = function() |
|
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 |
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
|
393 |
}; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
394 |
|
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
395 |
this.update = function(time) |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
396 |
{ |
| 36 | 397 |
if (this.startTime[0] === 0) { |
|
30
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
398 |
this.startTime[0] = time; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
399 |
this.startTime[1] = time; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
400 |
return; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
401 |
} |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
402 |
|
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
403 |
for (var i = 0; i < 2; ++i) { |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
404 |
// 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
|
405 |
var waitTime = this.startTime[i] + this.effects[i].waitTime; |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
406 |
if (time > waitTime && time < this.totalTime[i] + waitTime) { |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
407 |
this.effectInfos[i] = this.effects[i].update(time - waitTime); |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
408 |
} |
|
6d5b46559bd9
effet mosaic done
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
29
diff
changeset
|
409 |
} |
|
23
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 |
|
|
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 |
// Tools |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
415 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
416 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
417 |
window.requestAnimationFrame = (function() { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
418 |
return window.requestAnimationFrame || // Chromium |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
419 |
window.webkitRequestAnimationFrame || // Webkit |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
420 |
window.mozRequestAnimationFrame || // Mozilla Geko |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
421 |
window.oRequestAnimationFrame || // Opera Presto |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
422 |
window.msRequestAnimationFrame || // IE Trident? |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
423 |
function(callback, element){ // Fallback function |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
424 |
window.setTimeout(callback, 20); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
425 |
}; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
428 |
var incMosaic = new IncMosaic(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
429 |