web/static/res/js/incmosaic.js
changeset 42 01415303372e
parent 39 6605de5fe0bd
child 43 21a791340354
equal deleted inserted replaced
41:f2123b4487e9 42:01415303372e
    17 	this.imagesLoaded = 0;
    17 	this.imagesLoaded = 0;
    18 	this.imageWidth;
    18 	this.imageWidth;
    19 	this.imageHeight;
    19 	this.imageHeight;
    20 
    20 
    21 	// Effect
    21 	// Effect
       
    22 	this.waitStartEffectTime = 3000;
       
    23 	this.waitStartEffectGo;
       
    24 	this.effectSpeed;
    22 	this.squareCountX;
    25 	this.squareCountX;
    23 	this.squareCountY;
    26 	this.squareCountY;
    24 	this.srcSquareWidth;
    27 	this.srcSquareWidth;
    25 	this.srcSquareHeight;
    28 	this.srcSquareHeight;
    26 	this.squareWidth;
    29 	this.squareWidth;
    27 	this.squareHeight;
    30 	this.squareHeight;
    28 	this.effects = [];
    31 	this.effects = [];
    29 	this.squareEffects = [];
    32 	this.squareEffects = [];
       
    33 	this.loop;
       
    34 	this.endEffecFunc;
    30 
    35 
    31 	// Time
    36 	// Time
    32 	this.startTime;
    37 	this.startTime;
    33 
    38 
    34 	// --------------------------------------------------------------------------------------------------------------------
    39 	// --------------------------------------------------------------------------------------------------------------------
    38 	this.addImageUrl = function(url)
    43 	this.addImageUrl = function(url)
    39 	{
    44 	{
    40 		this.imageUrls.push(url);
    45 		this.imageUrls.push(url);
    41 	};
    46 	};
    42 
    47 
    43 	this.start = function(canvasId, squareCountX, squareCountY)
    48 	this.start = function(canvasId, effectSpeed, squareCountX, squareCountY, loop, waitStartEffectGo, endEffecFunc)
    44 	{
    49 	{
    45 		// Canvas ID
    50 		// Canvas ID
    46 		this.canvasId = canvasId;
    51 		this.canvasId = canvasId;
       
    52 
       
    53 		// Speed
       
    54 		this.effectSpeed = 1 / effectSpeed;
    47 
    55 
    48 		// Set square count
    56 		// Set square count
    49 		this.squareCountX = squareCountX;
    57 		this.squareCountX = squareCountX;
    50 		this.squareCountY = (squareCountY === undefined) ? squareCountX: squareCountY;
    58 		this.squareCountY = (squareCountY === undefined) ? squareCountX: squareCountY;
    51 
    59 
       
    60 		// End effect behavior
       
    61 		this.loop = loop;
       
    62 		this.endEffecFunc = endEffecFunc;
       
    63 
       
    64 		// Does the effect wait for go
       
    65 		this.waitStartEffectGo = waitStartEffectGo;
       
    66 
    52 		// Init the canvas objects
    67 		// Init the canvas objects
    53 		this.init();
    68 		this.init();
    54 
    69 
    55 		// Register effects
    70 		// Register effects
    56 		this.registerEffects();
    71 		this.registerEffects();
    57 
    72 
    58 		// Set a new effect transition between 2 images
    73 		// Set a new effect transition between 2 images
    59 		this.SetNewEffect();
    74 		this.setNewEffect();
    60 										
    75 										
    61 		// Main loop
    76 		// Main loop
    62 		this.loopCallback();
    77 		this.loopCallback();
    63 	};
    78 	};
    64 
    79 
    65 	this.SetNewEffect = function()
    80 	this.setNewEffect = function()
    66 	{
    81 	{
    67 		// Set a random pair images
    82 		// Set a random pair images
    68 		this.setRandomPairImages();
    83 		this.setRandomPairImages();
    69 
    84 
    70 		// Set random effect on the squares
    85 		// Set random effect on the squares
    71 		this.setRandomSquareEffect();
    86 		this.setRandomSquareEffect();
    72 
    87 
    73 		// Time
    88 		// Time
    74 		this.startTime = new Date().getTime();		
    89 		this.startTime = new Date().getTime();		
    75 	}
    90 	};
       
    91 
       
    92 	this.goEffect = function()
       
    93 	{
       
    94 		this.waitStartEffectGo = false;
       
    95 	};
    76 
    96 
    77 	this.init = function()
    97 	this.init = function()
    78 	{
    98 	{
    79 		// Init canvas objects
    99 		// Init canvas objects
    80 		this.canvas = document.getElementById(this.canvasId );
   100 		this.canvas = document.getElementById(this.canvasId );
   163 	this.redraw = function()
   183 	this.redraw = function()
   164 	{
   184 	{
   165 		// Get time
   185 		// Get time
   166 		var time = new Date().getTime();
   186 		var time = new Date().getTime();
   167 
   187 
   168 		if (time < this.startTime + 3000) {
   188 		var timeToWait = (this.startTime + this.waitStartEffectTime)*this.effectSpeed;
       
   189 		if (time < timeToWait || this.waitStartEffectGo) {
   169 			// Draw the first image
   190 			// Draw the first image
   170 			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);
   191 			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);
   171 			return;
   192 			return;
   172 		}
   193 		}
   173 
   194 
   186 				}
   207 				}
   187 			}
   208 			}
   188 		}
   209 		}
   189 
   210 
   190 		if (!effectsContinue) {
   211 		if (!effectsContinue) {
   191 			console.log("Effect finished !!!!!");
   212 			if (this.loop) {
   192 			this.SetNewEffect();
   213 				// The effect loop
       
   214 				this.setNewEffect();
       
   215 			} else if (this.endEffecFunc != undefined && this.endEffecFunc != null) {
       
   216 				// Call the end callback
       
   217 				this.endEffecFunc();
       
   218 			}
   193 		}	
   219 		}	
   194 	};
   220 	};
   195 
   221 
   196 	this.drawSquare = function(fullEffect, image, effectInfo)
   222 	this.drawSquare = function(fullEffect, image, effectInfo)
   197 	{
   223 	{
   218 
   244 
   219 	this.registerEffects = function()
   245 	this.registerEffects = function()
   220 	{
   246 	{
   221 		var count = 7;
   247 		var count = 7;
   222 		var color = 64;
   248 		var color = 64;
       
   249 		var speed = this.effectSpeed;
   223 
   250 
   224 		// Create semi random effects
   251 		// Create semi random effects
   225 		var range1 = 3000;
   252 		var range1 = 3000 * speed;
   226 		var range2 = 5000;
   253 		var range2 = 5000 * speed;
   227 
   254 		this.registerEffectsTime(count, color, range1, range2);
   228 		var i, time1, time2, effectParam1, effect1, effectParam2, effect2, fullEffect1;
   255 
   229 		for (i = 0; i < count; ++i) {
   256 		// Create semi random effects
   230 			time1 = this.randomInt(range1, range2);
   257 		range1 = 7000 * speed;
   231 			time2 = this.randomInt(range1, range2);
   258 		range2 = 15000 * speed;
   232 			c1 = this.randomInt(0, color);
   259 		this.registerEffectsTime(count, color, range1, range2);
   233 
   260 
   234 			effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
   261 		// Create semi random effects
   235 			effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
   262 		range1 = 17000 * speed;
       
   263 		range2 = 23000 * speed;
       
   264 		this.registerEffectsTime(count, color, range1, range2);
       
   265 	};
       
   266 
       
   267 	this.registerEffectsTime = function(count, color, range1, range2)
       
   268 	{
       
   269 		for (var i = 0; i < count; ++i) {
       
   270 			var time1 = this.randomInt(range1, range2);
       
   271 			var time2 = this.randomInt(range1, range2);
       
   272 			var c1 = this.randomInt(0, color);
       
   273 
       
   274 			var effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
       
   275 			var effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
   236 			
   276 			
   237 			effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
   277 			var effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
   238 			effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
   278 			var effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
   239 
   279 
   240 			fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
   280 			var fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
   241 			this.effects.push(fullEffect1);
   281 			this.effects.push(fullEffect1);
   242 		}
   282 		}
   243 
   283 	};
   244 		// Create semi random effects
       
   245 		range1 = 7000;
       
   246 		range2 = 15000;
       
   247 		for (i = 0; i < count; ++i) {
       
   248 			time1 = this.randomInt(range1, range2);
       
   249 			time2 = this.randomInt(range1, range2);
       
   250 			c1 = this.randomInt(0, color);
       
   251 
       
   252 			effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
       
   253 			effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
       
   254 			
       
   255 			effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
       
   256 			effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
       
   257 
       
   258 			fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
       
   259 			this.effects.push(fullEffect1);
       
   260 		}
       
   261 
       
   262 		// Create semi random effects
       
   263 		range1 = 17000;
       
   264 		range2 = 23000;
       
   265 		for (i = 0; i < count; ++i) {
       
   266 			time1 = this.randomInt(range1, range2);
       
   267 			time2 = this.randomInt(range1, range2);
       
   268 			c1 = this.randomInt(0, color);
       
   269 
       
   270 			effectParam1 = new IncEffectParams(new IncColor(c1, c1, c1, 0), new IncAnim(1, time1), 1, new IncAnim(-1, time1));
       
   271 			effect1 = new IncSquareEffect_Alpha(effectParam1, createjs.Ease.quadOut, createjs.Ease.quadOut);
       
   272 			
       
   273 			effectParam2 = new IncEffectParams(new IncColor(c1, c1, c1, 1), new IncAnim(0, time2), 0, new IncAnim(1, time2));
       
   274 			effect2 = new IncSquareEffect_Alpha(effectParam2, createjs.Ease.quadIn, createjs.Ease.quadIn, time1 / 2.5);
       
   275 
       
   276 			fullEffect1 = new IncFullEffect(effect1, effect2, time1, time2);
       
   277 			this.effects.push(fullEffect1);
       
   278 		}
       
   279 	};	
       
   280 
   284 
   281 	// --------------------------------------------------------------------------------------------------------------------
   285 	// --------------------------------------------------------------------------------------------------------------------
   282 	// Tools
   286 	// Tools
   283 	// --------------------------------------------------------------------------------------------------------------------
   287 	// --------------------------------------------------------------------------------------------------------------------
   284 
   288