| author | Edwin Razafimahatratra <edwin@robotalismsoft.com> |
| Tue, 13 Nov 2012 17:59:26 +0100 | |
| changeset 29 | c9c75ab3de3e |
| parent 23 | 45b05706b516 |
| child 30 | 6d5b46559bd9 |
| 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 |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
8 |
this.canvas; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
9 |
this.context; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
10 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
11 |
/// Images |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
12 |
this.pairUrl = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
13 |
this.pairImages = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
14 |
this.imagesLoaded = 0; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
15 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
16 |
// Effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
17 |
this.countX; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
18 |
this.countY; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
19 |
this.squareX; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
20 |
this.squareY; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
21 |
this.effects = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
22 |
this.squareEffects = []; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
23 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
24 |
this.noEffectinfo = new IncEffectInfo(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
25 |
this.noEffectinfo.color = new IncColor(255, 255, 255, 1) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
26 |
this.noEffectinfo.alpha = 1; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
27 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
28 |
// Debug |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
29 |
this.lastTime; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
30 |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
31 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
32 |
// Functions |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
33 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
34 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
35 |
this.addPairImages = function(url1, url2) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
36 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
37 |
var urls = new IncPairUrl(url1, url2); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
38 |
this.pairUrl.push(urls); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
39 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
40 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
41 |
this.start = function(canvasId, countX, countY) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
42 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
43 |
// Init the canvas objects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
44 |
this.init(canvasId); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
45 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
46 |
// Register effects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
47 |
this.registerEffects(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
48 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
49 |
// Count, square` |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
50 |
this.countX = countX; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
51 |
this.countY = (countY === undefined) ? countX: countY; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
52 |
this.squareX = Math.floor(this.canvas.width / this.countX); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
53 |
this.squareY = Math.floor(this.canvas.height / this.countY); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
54 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
55 |
// Set a random pair images |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
56 |
this.setRandomPairImages(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
57 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
58 |
// Set random effect on the squares |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
59 |
this.setRandomSquareEffect(); |
|
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 |
// Main loop |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
62 |
this.loopCallback2(); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
63 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
64 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
65 |
this.init = function(canvasId) |
|
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 |
// Init canvas objects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
68 |
this.canvas = document.getElementById(canvasId); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
69 |
this.ctx = this.canvas.getContext('2d'); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
70 |
this.ctx.fillStyle = "#000000"; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
71 |
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
|
72 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
73 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
74 |
this.registerEffects = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
75 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
76 |
// No effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
77 |
//----------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
78 |
var noEffect = new IncSquareEffect_NoEffet() |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
79 |
var fullEffect0 = new IncFullEffect(noEffect); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
80 |
//this.effects.push(fullEffect0); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
81 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
82 |
// Alpha |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
83 |
//----------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
84 |
{ |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
85 |
var effectParam1 = new IncEffectParams(new IncColor(255, 255, 255, 0), new IncAnim(1, 5000), 1, new IncAnim(-1, 5000), 5000); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
86 |
var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadInOut, createjs.Ease.quadInOut); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
87 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
88 |
var effectParam2 = new IncEffectParams(new IncColor(255, 255, 255, 1), new IncAnim(0, 5000), 0, new IncAnim(1, 7000), 8000); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
89 |
var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadInOut, createjs.Ease.quadInOut, 5000); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
90 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
91 |
this.effects.push(new IncFullEffect(effect1, effect2)); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
92 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
93 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
94 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
95 |
this.setRandomPairImages = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
96 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
97 |
this.imagesLoaded = 0; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
98 |
var randInd = this.randomInt(0, this.pairUrl.length); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
99 |
var pairUrl = this.pairUrl[randInd]; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
100 |
this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl1)); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
101 |
this.pairImages.push(this.getImageFromUrl(pairUrl.imageUrl2)); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
102 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
103 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
104 |
this.setRandomSquareEffect = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
105 |
{ |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
106 |
/* |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
107 |
for (var i = 0; i < this.countX; ++i) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
108 |
for (var j = 0; j < this.countY; ++j) { |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
109 |
//var fullEffect = this.effects[this.randomInt(0, this.effects.length)].copy(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
110 |
var fullEffect = this.effects[0].copy(); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
111 |
fullEffect.x = i; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
112 |
fullEffect.y = j; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
113 |
this.squareEffects.push(fullEffect); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
114 |
} |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
115 |
}*/ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
116 |
{ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
117 |
var e1 = this.effects[0].copy(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
118 |
e1.x = 2; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
119 |
e1.y = 1; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
120 |
this.squareEffects.push(e1); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
121 |
} |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
122 |
/* |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
123 |
{ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
124 |
var e1 = this.effects[1].copy(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
125 |
e1.x = 3; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
126 |
e1.y = 0; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
127 |
this.squareEffects.push(e1); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
128 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
129 |
{ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
130 |
var e1 = this.effects[2].copy(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
131 |
e1.x = 2; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
132 |
e1.y = 1; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
133 |
this.squareEffects.push(e1); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
134 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
135 |
*/ |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
136 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
137 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
138 |
this.loopCallback = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
139 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
140 |
var self = incMosaic; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
141 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
142 |
if (self.imagesLoaded != 2) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
143 |
// Images are not loaded yet |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
144 |
requestAnimationFrame(self.loopCallback); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
145 |
return; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
148 |
// Clear canvas |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
149 |
self.ctx.fillStyle = "#ffffff"; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
150 |
self.ctx.fillStyle = "#000000"; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
151 |
self.ctx.fillRect(0, 0, self.canvas.width, self.canvas.height); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
152 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
153 |
// Get time |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
154 |
var time = new Date().getTime(); |
|
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 |
// Update effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
157 |
for (var i = 0; i < self.squareEffects.length; ++i) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
158 |
var fullEffect = self.squareEffects[i]; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
159 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
160 |
for (var j = 0; j < 2; ++j) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
161 |
var effect = fullEffect.effects[j]; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
162 |
if (effect !== undefined) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
163 |
// Draw square |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
164 |
self.drawSquare(fullEffect, self.pairImages[j], effect, time); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
165 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
166 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
167 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
168 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
169 |
//console.log(time - this.lastTime); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
170 |
this.lastTime = time; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
171 |
|
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
172 |
// Loop |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
173 |
requestAnimationFrame(self.loopCallback); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
174 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
175 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
176 |
this.loopCallback2 = function() |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
177 |
{ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
178 |
var self = incMosaic; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
179 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
180 |
if (self.imagesLoaded != 2) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
181 |
// Images are not loaded yet |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
182 |
requestAnimationFrame(self.loopCallback2); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
183 |
return; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
184 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
185 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
186 |
// Clear canvas |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
187 |
self.ctx.fillStyle = "#ffffff"; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
188 |
self.ctx.fillStyle = "#000000"; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
189 |
self.ctx.fillRect(0, 0, self.canvas.width, self.canvas.height); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
190 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
191 |
// Get time |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
192 |
var time = new Date().getTime(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
193 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
194 |
// Update effect |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
195 |
for (var i = 0; i < self.squareEffects.length; ++i) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
196 |
// Draw square |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
197 |
var fullEffect = self.squareEffects[i]; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
198 |
self.drawSquare2(fullEffect, time); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
199 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
200 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
201 |
//console.log(time - this.lastTime); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
202 |
this.lastTime = time; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
203 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
204 |
// Loop |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
205 |
requestAnimationFrame(self.loopCallback2); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
206 |
}; |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
207 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
208 |
this.drawSquare = function(fullEffect, image, effect, time) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
209 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
210 |
// Update effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
211 |
var effectInfo = effect.update(fullEffect, time); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
212 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
213 |
if (effectInfo === null) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
214 |
return; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
215 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
216 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
217 |
// Compute square position |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
218 |
var posX = fullEffect.x * this.squareX; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
219 |
var posY = fullEffect.y * this.squareY; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
220 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
221 |
this.ctx.save(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
222 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
223 |
// Global alpha |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
224 |
this.ctx.globalAlpha = effectInfo.alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
225 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
226 |
// Draw colored rectangle |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
227 |
this.ctx.fillStyle = "rgba(" + effectInfo.color.r + "," + effectInfo.color.v + "," + effectInfo.color.b + "," + effectInfo.color.a + ")"; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
228 |
this.ctx.fillRect(posX, posY, this.squareX, this.squareY); |
|
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 |
// Draw image |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
231 |
this.ctx.drawImage(image, posX, posY, this.squareX, this.squareY, posX, posY, this.squareX, this.squareY); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
232 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
233 |
this.ctx.restore(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
234 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
235 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
236 |
this.drawSquare2 = function(fullEffect, time) |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
237 |
{ |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
238 |
// Update effect |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
239 |
var effectInfo1 = fullEffect.effects[0].update(fullEffect, time); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
240 |
var effectInfo2 = (fullEffect.effects[1] !== undefined) ? fullEffect.effects[1].update(fullEffect, time) : null; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
241 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
242 |
// Compute square position |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
243 |
var posX = fullEffect.x * this.squareX; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
244 |
var posY = fullEffect.y * this.squareY; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
245 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
246 |
this.ctx.save(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
247 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
248 |
if (effectInfo1 !== null) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
249 |
this.ctx.globalAlpha = effectInfo1.alpha; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
250 |
this.ctx.drawImage(this.pairImages[0], posX, posY, this.squareX, this.squareY, posX, posY, this.squareX, this.squareY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
251 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
252 |
if (effectInfo2 !== null) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
253 |
var image1 = this.ctx.getImageData(posX, posY, this.squareX, this.squareY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
254 |
var imageData1 = image1.data; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
255 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
256 |
this.ctx.globalAlpha = effectInfo2.alpha; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
257 |
this.ctx.drawImage(this.pairImages[1], posX, posY, this.squareX, this.squareY, posX, posY, this.squareX, this.squareY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
258 |
var image2 = this.ctx.getImageData(posX, posY, this.squareX, this.squareY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
259 |
var imageData2 = image2.data; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
260 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
261 |
var pixels = 4 * this.squareX * this.squareY; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
262 |
while (pixels--) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
263 |
imageData1[pixels] = imageData1[pixels] * 0.5 + imageData2[pixels] * 0.5; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
264 |
//imageData1[pixels] = imageData1[pixels] * effectInfo1.alpha + imageData2[pixels] * effectInfo1.alpha;; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
265 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
266 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
267 |
this.ctx.putImageData(image1, posX, posY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
268 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
269 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
270 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
271 |
} else if (effectInfo2 !== null) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
272 |
console.log(effectInfo2.alpha); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
273 |
this.ctx.globalAlpha = effectInfo2.alpha; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
274 |
this.ctx.drawImage(this.pairImages[1], posX, posY, this.squareX, this.squareY, posX, posY, this.squareX, this.squareY); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
275 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
276 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
277 |
this.ctx.restore(); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
278 |
}; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
279 |
|
|
23
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 |
// Tools |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
284 |
this.randomInt = function(min, max) |
|
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 |
return Math.floor(this.randomFloat(min, max)); |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
289 |
this.randomFloat = function(min, max) |
|
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 |
return Math.random() * (max - min) + min; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
294 |
this.getImageFromUrl = function(url) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
295 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
296 |
var image = new Image(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
297 |
image.onload = function() { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
298 |
incMosaic.imagesLoaded += 1; |
|
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 |
image.src = url; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
301 |
return image; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
305 |
function IncPairUrl(url1, url2) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
306 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
307 |
this.imageUrl1 = url1; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
308 |
this.imageUrl2 = url2; |
|
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 |
|
|
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 |
// Effects |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
313 |
// -------------------------------------------------------------------------------------------------------------------- |
|
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 |
function IncColor(r, v, b, a) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
316 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
317 |
this.r = r; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
318 |
this.v = v; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
319 |
this.b = b; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
320 |
this.a = a; |
|
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.copy = function() |
|
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 new IncColor(this.r, this.v, this.b, this.a); |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
328 |
function IncAnim(value, time) |
|
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 |
this.value = value; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
331 |
this.time = time; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
334 |
function IncEffectInfo() |
|
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.color; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
337 |
this.alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
338 |
} |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
339 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
340 |
function IncEffectParams(color, colorAnim, alpha, alphaAnim, time) |
|
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 |
// Color |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
343 |
this.color = color; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
344 |
this.colorAnim = colorAnim; |
|
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 |
// Alpha |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
347 |
this.alpha = alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
348 |
this.alphaAnim = alphaAnim; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
349 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
350 |
// Time |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
351 |
this.time = time; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
352 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
353 |
this.computeColorAnimValue = function(elapsedTime, easeFunc) |
|
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 |
return this.computeAnimValue(this.colorAnim, elapsedTime, easeFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
356 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
357 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
358 |
this.computeAlphaAnimValue = function(elapsedTime, easeFunc) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
359 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
360 |
return this.computeAnimValue(this.alphaAnim, elapsedTime, easeFunc); |
|
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 |
this.computeAnimValue = function(anim, elapsedTime, easeFunc) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
364 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
365 |
// Compute color alpha anim |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
366 |
if (elapsedTime < anim.time) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
367 |
return easeFunc(elapsedTime/anim.time) * anim.value; |
|
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 |
return anim.value; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
370 |
}; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
373 |
function IncSquareEffect_NoEffet() |
|
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 |
this.update = function(fullEffect, time) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
376 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
377 |
return incMosaic.noEffectinfo; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
381 |
function IncSquareEffect_Alpha(effectParms, tweenColorFunc, tweenAlphaFunc, waitTime) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
382 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
383 |
// Effect parameters |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
384 |
this.effectParms = effectParms; |
|
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 |
// Tween functions |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
387 |
this.tweenColorFunc = tweenColorFunc; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
388 |
this.tweenAlphaFunc = tweenAlphaFunc; |
|
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 |
// Time |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
391 |
this.waitTime = (waitTime!==undefined) ? (new Date().getTime() + waitTime) : 0; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
392 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
393 |
this.update = function(fullEffect, time) |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
394 |
{ |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
395 |
if (this.waitTime > time) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
396 |
return null; |
|
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 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
399 |
if (fullEffect.startTime == 0) { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
400 |
fullEffect.startTime = time; |
|
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 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
403 |
if ((time - fullEffect.startTime) > this.effectParms.time) { |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
404 |
return null; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
405 |
} |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
406 |
|
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
407 |
var elapsedTime = this.waitTime ? (time - fullEffect.waitTime) : (time - fullEffect.startTime); |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
408 |
console.log(elapsedTime); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
409 |
var info = new IncEffectInfo(); |
|
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 |
// Compute new color |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
412 |
var newColorValue = this.effectParms.computeColorAnimValue(elapsedTime, this.tweenColorFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
413 |
info.color = this.effectParms.color.copy(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
414 |
info.color.a += newColorValue; |
|
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 |
// Compute alpha anim |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
417 |
var newAlphaValue = this.effectParms.computeAlphaAnimValue(elapsedTime, this.tweenAlphaFunc); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
418 |
info.alpha = this.effectParms.alpha; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
419 |
info.alpha += newAlphaValue; |
|
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 |
return info; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
422 |
}; |
|
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 |
|
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
425 |
function IncFullEffect(effect1, effect2) |
|
23
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 |
// Position |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
428 |
this.x = 0; |
|
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
429 |
this.y = 0; |
|
23
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 |
// Effect |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
432 |
this.effects = [effect1, effect2]; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
433 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
434 |
// Time |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
435 |
this.startTime = 0; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
436 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
437 |
this.copy = function() |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
438 |
{ |
|
29
c9c75ab3de3e
avance sur l'effet mosaic
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
23
diff
changeset
|
439 |
return new IncFullEffect(this.effects[0], this.effects[1]); |
|
23
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
440 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
441 |
} |
|
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 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
444 |
// Tools |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
445 |
// -------------------------------------------------------------------------------------------------------------------- |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
446 |
|
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
447 |
window.requestAnimationFrame = (function() { |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
448 |
return window.requestAnimationFrame || // Chromium |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
449 |
window.webkitRequestAnimationFrame || // Webkit |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
450 |
window.mozRequestAnimationFrame || // Mozilla Geko |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
451 |
window.oRequestAnimationFrame || // Opera Presto |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
452 |
window.msRequestAnimationFrame || // IE Trident? |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
453 |
function(callback, element){ // Fallback function |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
454 |
window.setTimeout(callback, 20); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
455 |
}; |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
456 |
})(); |
|
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 |
var incMosaic = new IncMosaic(); |
|
45b05706b516
mosaic effect js first test
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff
changeset
|
459 |