How to use onFinished method in qawolf

Best JavaScript code snippet using qawolf

VisualEffects.js

Source:VisualEffects.js Github

copy

Full Screen

1/**2 * @module Match3 */4(function(namespace, M) {5 /**6 * @class Particle7 * @namespace visual8 * @constructor9 * @param {Vector2d} origin10 * @param {Vector2d} destination11 * @param {float} width12 * @param {float} height13 * @param {String} fillStyle14 */15 function Particle(origin, destination, width, height, fillStyle) {16 this.angle = 0;17 this._rotationSpeed = 0.1;18 this.speed = 0.05;19 this.vanishRate = 0.005;20 this.alpha = 1;21 this.setPath(origin, destination);22 this.setWidth(width);23 this.setHeight(height);24 }25 /**26 * @method setWidth27 * @param {float} width28 */29 Particle.prototype.setWidth = function(width) {30 this._halfWidth = width / 2;31 };32 /**33 * @method setHeight34 * @param {float} height35 */36 Particle.prototype.setHeight = function(height) {37 this._halfHeight = height / 2;38 };39 /**40 * @method setPath41 * @param {Object} origin Object containing origin x and y coordinates42 * @param {Object} destination Object containing destination x and y coordinates43 */44 Particle.prototype.setPath = function(origin, destination) {45 this._x = origin.x;46 this._y = origin.y;47 this.direction = M.math2d.getVector2d(origin, destination);48 };49 /**50 * Updates the particle51 * @method onLoop52 * @protected53 */54 Particle.prototype.onLoop = function() {55 this.alpha -= this.vanishRate;56 this.angle += this._rotationSpeed;57 this._x += this.speed * this.direction.x;58 this._y += this.speed * this.direction.y;59 };60 /**61 * Renders the particle62 * @method onRender63 */64 Particle.prototype.onRender = function(context, canvas, cameraX, cameraY) {65 if ( this.alpha >= 0 ) {66 context.save();67 context.globalAlpha = this.alpha;68 context.translate(this._x - cameraX, this._y - cameraY);69 context.rotate(this.angle);70 context.fillStyle = this.fillStyle;71 context.fillRect(-this._halfWidth, -this._halfHeight, this._halfWidth, this._halfHeight);72 context.restore();73 }74 };75 /**76 * Sets the zIndex of this object77 * @method setZIndex78 * @param {int} value the zIndex79 */80 Particle.prototype.setZIndex = function (value) {81 this._zIndex = value;82 };83 /**84 * Returns whether this object is visible and is inside the given viewport85 *86 * @method isVisible87 * @param {float} cameraX0 the left coordinate of the camera88 * @param {float} cameraY0 the top coordinate of the camera89 * @param {float} cameraX1 the right coordinate of the viewport90 * @param {float} cameraY1 the bottom coordinate of the viewport91 * @return {Boolean}92 */93 Particle.prototype.isVisible = function(cameraX0, cameraY0, cameraX1, cameraY1) {94 if ( this.alpha <= 0 ) {95 return false;96 }97 var camera = M.camera;98 if (this._y + this._halfHeight < cameraY0) return false;99 if (this._y - this._halfHeight > cameraY1) return false;100 if (this._x + this._halfWidth < cameraX0) return false;101 if (this._x - this._halfWidth > cameraX1) return false;102 return true;103 };104 /*105 * Creates linear particles and returns them as in array106 * @param amount of particles107 * @param departure x108 * @param departure y109 * @param direction in which the particles will move110 * @param min width of the particles111 * @param min height of the particles112 * @param max width of the particles113 * @param max height of the particles114 * @param min speed of the particles115 * @param max speed of the particles116 * @param color of the particles - if not provided an explosion color will be applied117 */118 function createLinearParticles(amount, origin, direction, minWidth, minHeight, maxWidth, maxHeight, minSpeed, maxSpeed, color, vanishRate, maxVanishRate) {119 var lib = M.Math2d;120 var particles = [];121 for ( var i = 0; i < amount; i++) {122 var particle = new Particle(origin, { x: origin.x + direction.x * 5, y: origin.y + direction.y * 5});123 particle.setWidth(lib.randomInt(minWidth, maxWidth));124 particle.setHeight(lib.randomInt(minHeight, maxHeight));125 if ( ! color ) {126 switch ( lib.randomInt(0,2) ) {127 case 0:128 particle.color = "rgb(255, 128, 0)";129 break;130 case 1:131 particle.color = "rgb(255, 180, 0)";132 break;133 case 2:134 particle.color = "rgb(255, 80, 0)";135 }136 } else {137 particle.color = color[lib.randomInt(0, color.length - 1)];138 }139 if ( maxVanishRate ) {140 particle.vanishRate = lib.randomFloat( vanishRate, maxVanishRate );141 } else if ( vanishRate ) {142 particle.vanishRate = vanishRate;143 }144 particle.speed = lib.randomFloat(minSpeed, maxSpeed);145 particles.push(particle);146 }147 return particles;148 }149 /**150 * @class RadialParticleEmitter151 * @constructor152 * @namespace visual153 * @constructor154 * @param {int} amount amount of particles155 * @param {Array} color array of Strings with posible colors156 * @param {float} minWidth min width of the particles157 * @param {float} minHeight min height of the particles158 * @param {float} maxWidth max width of the particles159 * @param {float} maxHeight max height of the particles160 * @param {float} minSpeed min speed of the particles161 * @param {float} maxSpeed max speed of the particles162 * @param {float} vanishRate if not provided will default to 0.01 @see particle.vanishRate163 */164 function RadialParticleEmitter(amount, color, minWidth, minHeight, maxWidth, maxHeight, minSpeed, maxSpeed, vanishRate) {165 if ( ! this.minAngle ) this.minAngle = 0;166 if ( ! this.maxAngle ) this.maxAngle = 6.28;167 this.amount = amount;168 this.color = color;169 this.minWidth = minWidth || 1;170 this.minHeight = minHeight || 1;171 this.maxWidth = maxWidth || 3;172 this.maxHeight = maxHeight || 3;173 this.minSpeed = minSpeed || 0.01;174 this.maxSpeed = maxSpeed || 0.1;175 this.vanishRate = vanishRate;176 }177 RadialParticleEmitter.prototype.onLoop = function() {178 if ( !this.children ) return;179 var i = 0, l = this.children.length, notVisible = 0, currentParticle;180 for ( ; i < l; i++ ) {181 currentParticle = this.children[i];182 if ( currentParticle.alpha <= 0 ) {183 notVisible++;184 } else {185 currentParticle.onLoop();186 }187 }188 if ( notVisible == l ) {189 this.children = null;190 } else {191 // this.notifyChange();192 }193 };194 RadialParticleEmitter.prototype.onRender = function () {195 };196 RadialParticleEmitter.prototype.isVisible = function() {197 return true;198 };199 RadialParticleEmitter.prototype.setZIndex = function (value) {200 this._zIndex = value;201 // this.notifyChange();202 // this.notifyZIndexChange();203 };204 /**205 * Creates particles that will move from the center to another part of a circle206 * @method create207 * @param {int} x the x center at where to create the particles208 * @param {int} y the y center at where to create the particles209 */210 RadialParticleEmitter.prototype.create = function(x, y) {211 var rnd = M.random;212 this.children = new Array();213 for ( var i = 0; i < this.amount; i++) {214 /* t E [0, 2 * PI] */215 var t = rnd.decimal(this.minAngle, this.maxAngle),216 /* Radius */217 r = 50,218 origin = new Object(),219 destination = new Object(),220 particle;221 origin.x = x;222 origin.y = y;223 destination.x = x + r * Math.cos(t);224 destination.y = y + r * Math.sin(t);225 particle = new Particle(origin, destination);226 particle.setWidth(rnd.integer(this.minWidth, this.maxWidth));227 particle.setHeight(rnd.integer(this.minHeight, this.maxHeight));228 if ( !this.color ) {229 switch ( rnd.integer(0,2) ) {230 case 0:231 particle.fillStyle = "rgb(255, 128, 0)";232 break;233 case 1:234 particle.fillStyle = "rgb(255, 180, 0)";235 break;236 default:237 particle.fillStyle = "rgb(255, 80, 0)";238 }239 } else {240 particle.fillStyle = this.color[rnd.integer(0, color.length - 1)];241 }242 if ( this.vanishRate ) {243 particle.vanishRate = this.vanishRate;244 }245 particle.speed = rnd.decimal(this.minSpeed, this.maxSpeed);246 this.children.push(particle);247 }248 };249 /**250 * @class LinearParticleEmitter251 * @constructor252 * @namespace visual253 * @constructor254 * @param {int} particleAmount255 * @param {String} color256 * @param {float} [minWidth]257 * @param {float} [minHeight]258 * @param {float} [maxWidth]259 * @param {float} [maxHeight]260 * @param {float} [minSpeed]261 * @param {float} [maxSpeed]262 * @param {float} [vanishRate]263 */264 function LinearParticleEmitter(amount, color, minWidth, minHeight, maxWidth, maxHeight, minSpeed, maxSpeed, vanishRate) {265 this.origin = origin;266 this.direction = direction;267 this.particles = createLinearParticles(particleAmount, origin, direction, minWidth || 4, minHeight || 4, maxWidth || 8, maxHeight || 8, minSpeed || 0.01, maxSpeed || 0.4, color, vanishRate || M.Math2d.randomFloat(0.01, 0.03));268 this.visibleParticles = this.particles.length;269 }270 /**271 * Creates particles that will move from a point to another in a cone272 * @method create273 * @param {int} x the x center at where to create the particles274 * @param {int} y the y center at where to create the particles275 */276 LinearParticleEmitter.prototype.create = function(from, to) {277 278 };279 LinearParticleEmitter.prototype.onLoop = function(p) {280 if ( this.visible ) {281 var currentParticle;282 for ( var i = 0; i < this.particles.length; i++ ) {283 currentParticle = this.particles[i];284 currentParticle.onLoop(p);285 if ( ! currentParticle.isVisible() ) {286 if ( this.loop ) {287 currentParticle.setPath(this.origin, { x: this.origin.x + this.direction.x * 5, y: this.origin.y + this.direction.y * 5});288 currentParticle.rotation = 0;289 currentParticle.alpha = 1;290 currentParticle.angle = 0;291 currentParticle.vanishRate = M.Math2d.randomFloat(0.05, 0.2);292 currentParticle.speed = M.Math2d.randomFloat(0.005, 0.5);293 } else {294 this.visibleParticles--;295 }296 }297 298 }299 if ( this.visibleParticles < 1 ) {300 M.remove(this);301 }302 }303 };304 /**305 * Applies a Tint on the provided game object306 * @class Tint307 * @constructor308 * @deprecated309 * @param {renderers.Renderizable} owner object to apply the tint310 * @param {String} fillStyle tint color311 * @param {int} duration duration in milliseconds312 */313 function Tint(properties) {314 this.operation = "source-atop";315 this.startTime = 0;316 M.applyProperties( this, properties, ["fillStyle"] );317 }318 Tint.prototype.render = function( context, width, height ) {319 if ( this.isVisible() ) {320 context.globalCompositeOperation = this.operation;321 context.fillStyle = this.fillStyle;322 context.fillRect( 0, 0, width, height );323 }324 };325 Tint.prototype.show = function() {326 this.startTime = M.getTimeInMillis();327 };328 Tint.prototype.isVisible = function() {329 return this.showAlways || M.getTimeInMillis() - this.startTime < this.duration330 };331 /**332 * Creates a FadeIn object to be applied to the given renderers.Renderizable.333 * Fade the object in when the onLoop method is called334 * @class FadeIn335 * @constructor336 * @extends GameObject337 * @param {renderers.Renderizable} object object to apply the tint338 * @param {int} seconds fade in duration in seconds339 * @param {Function} [onFinished] function to execute on animation finish340 */341 function FadeIn(object, seconds, onFinished) {342 if ( seconds == undefined ) seconds = 1;343 /* Rate is 1 because we must go from 0 to 1 in the given amount of seconds */344 this.rate = 1 / ( seconds * M.getAverageFps() );345 this.object = object;346 this.onFinished = onFinished;347 }348 FadeIn.prototype.initialize = function() {349 this.object.setAlpha(0);350 this.onLoop = this.run;351 return true;352 };353 FadeIn.prototype.run = function() {354 var newAlpha = this.object.getAlpha() + this.rate;355 356 if ( newAlpha < 1 ) {357 this.object.setAlpha( newAlpha );358 } else {359 this.object.setAlpha( 1 );360 if ( this.onFinished ) this.onFinished.apply( this.object );361 return false;362 }363 return true;364 };365 FadeIn.prototype.onLoop = FadeIn.prototype.initialize;366 /**367 * Creates a FadeOut object to be applied to the given renderers.Renderizable.368 * Fade the object out when the onLoop method is called369 * @class FadeOut370 * @constructor371 * @extends GameObject372 * @param {renderers.Renderizable} object object to apply the tint373 * @param {int} seconds fade out duration in seconds374 * @param {Function} [onFinished] function to execute on animation finish375 */376 function FadeOut(object, seconds, onFinished) {377 if ( seconds == undefined ) seconds = 1;378 /* Rate is 1 because we must go from 0 to 1 in the given amount of seconds */379 this.rate = 1 / ( seconds * M.getAverageFps() );380 this.object = object;381 this.onFinished = onFinished;382 }383 FadeOut.prototype.initialize = function() {384 this.object.setAlpha(1);385 this.onLoop = this.run;386 return true;387 };388 FadeOut.prototype.run = function() {389 var newAlpha = this.object.getAlpha() - this.rate;390 if ( newAlpha > 0 ) {391 this.object.setAlpha( newAlpha );392 } else {393 this.object.setAlpha( 0 );394 if ( this.onFinished ) this.onFinished.apply( this.object );395 return false;396 }397 return true;398 };399 FadeOut.prototype.onLoop = FadeOut.prototype.initialize;400 /**401 * Creates a Wait object to be applied to the given renderers.Renderizable.402 * Wait is used for chained effects403 * @class Wait404 * @constructor405 * @extends GameObject406 * @param {renderers.Renderizable} object object to apply the tint407 * @param {int} seconds fade out duration in seconds408 * @param {Function} [onFinished] function to execute on animation finish409 */410 function Wait(object, seconds, onFinished) {411 if ( seconds == undefined ) seconds = 1;412 this.seconds = seconds;413 this.object = object;414 this.timer = 0;415 this.onFinished = onFinished;416 }417 Wait.prototype.initialize = function(p) {418 this.timer = new M.TimeCounter(this.seconds * 1000);419 this.onLoop = this.run;420 };421 Wait.prototype.run = function() {422 if ( this.timer.elapsed() ) {423 if ( this.onFinished ) this.onFinished.apply( this.object );424 return false;425 }426 return true;427 };428 Wait.prototype.onLoop = Wait.prototype.initialize;429 /**430 * Creates ContinouseFade object to be applied to the given renderers.Renderizable.431 * Continously fades in and out the object432 * @class ContinousFade433 * @constructor434 * @extends GameObject435 * @param {renderers.Renderizable} object the object to apply the effect to436 * @param {int} seconds fade in and out duration in seconds437 * @param {Boolean} fadeOut value that determines if effect will start as a fade out. Default starts fading in438 * @param {int} min minumum alpha value439 * @param {int} max maximum alpha value440 */441 function ContinousFade(object, seconds, fadeOut, min, max) {442 443 if ( seconds == undefined ) seconds = 1;444 /* Rate is 1 because we must go from 0 to 1 in the given amount of seconds */445 this.rate = 1 / ( seconds * M.getAverageFps() );446 this.object = object;447 448 this.min = min || 0;449 this.max = max || 1;450 object.setAlpha( 1 );451 452 this.onFinished = this.changeFade;453 454 if ( fadeOut ) {455 this.onLoop = this.fadeOut;456 } else {457 this.onLoop = this.fadeIn;458 }459 460 }461 462 ContinousFade.prototype.fadeIn = function(p) {463 var newAlpha = this.object._alpha + this.rate;464 465 if ( newAlpha < this.max ) {466 this.object.setAlpha( newAlpha );467 } else {468 this.object.setAlpha( this.max );469 this.onLoop = this.fadeOut;470 }471 return true;472 };473 474 ContinousFade.prototype.fadeOut = function() {475 476 var newAlpha = this.object._alpha - this.rate;477 if ( newAlpha > this.min ) {478 this.object.setAlpha( newAlpha );479 } else {480 this.object.setAlpha( this.min );481 this.onLoop = this.fadeIn;482 }483 return true;484 485 };486 /**487 * Creates Move object to be applied to the given renderers.Renderizable.488 * Moves the object closer to the destination when the onLoop method is called489 *490 * @class FadeOut491 * @constructor492 * @extends GameObject493 * @param {renderers.Renderizable} object the object to apply the effect to494 * @param {int} x destination x495 * @param {int} y destination y496 * @param {int} seconds duration of the animation in seconds497 * @param {Function} onFinished function to execute once the animation is finished498 */499 function Move( object, x, y, seconds, onFinished ) {500 this.object = object;501 this._x = x;502 this._y = y;503 if ( seconds == undefined ) seconds = 1;504 505 this.onFinished = onFinished;506 var lib = M.Math2d,507 frames = seconds * M.getAverageFps(),508 coorsFrom = new lib.Vector2d(object._x, object._y),509 coordsTo = new lib.Vector2d(x, y);510 this.speed = lib.getDistance( coorsFrom, coordsTo ) / frames;511 this.direction = M.Math2d.getNormalized( M.Math2d.getVector2d( coorsFrom, coordsTo ) );512 }513 Move.prototype.onLoop = function(p) {514 var moveX = Math.abs( this._x - this.object._x ) > this.speed,515 moveY = Math.abs( this._y - this.object._y ) > this.speed;516 517 if ( moveX ) this.object.offsetX(this.direction.x * this.speed);518 if ( moveY ) this.object.offsetY(this.direction.y * this.speed);519 if ( ! moveX && ! moveY ) {520 this.object.setLocation(this._x, this._y);521 if ( this.onFinished ) this.onFinished.apply( this.object );522 return false;523 }524 return true;525 };526 /**527 * Creates a ScaleUp object to be applied to the given renderers.Renderizable.528 * Scales the object up when the onLoop method is called529 *530 * @class ScaleUp531 * @constructor532 * @extends GameObject533 * @param {renderers.Renderizable} object the object to apply the effect to534 * @param {int} x destination x535 * @param {int} y destination y536 * @param {int} seconds duration of the effect537 * @param {Function} onFinished function to execute once the animation is finished538 */539 function ScaleUp( object, x, y, seconds, onFinished ) {540 var frames = seconds * M.getAverageFps();541 if ( ! object._scale ) {542 object._scale = { x: 1, y: 1 };543 }544 this.speedX = Math.abs( object._scale.x - x ) / frames;545 this.speedY = Math.abs( object._scale.y - y ) / frames;546 this.object = object;547 this._x = x;548 this._y = y;549 this.onFinished = onFinished;550 }551 ScaleUp.prototype.onLoop = function(p) {552 if ( this.object._scale.x < this._x ) {553 this.object._scale.x += this.speedX;554 // this.notifyChange();555 }556 if ( this.object._scale.y < this._y ) {557 this.object._scale.y += this.speedY;558 // this.notifyChange();559 }560 if ( this.object._scale.x >= this._x && this.object._scale.y >= this._y ) {561 if ( this.onFinished ) this.onFinished.apply( this.object );562 return false;563 }564 return true;565 };566 567 /**568 * Creates a ScaleDown object to be applied to the given renderers.Renderizable.569 * Scales the object down when the onLoop method is called570 *571 * @class ScaleDown572 * @constructor573 * @param {renderers.Renderizable} object the object to apply the effect to574 * @param {int} x destination x575 * @param {int} y destination y576 * @param {int} seconds duration of the effect577 * @param {Function} onFinished function to execute once the animation is finished578 */579 function ScaleDown( object, x, y, seconds, onFinished ) {580 var frames = seconds * M.getAverageFps();581 if ( ! object._scale ) {582 object._scale = { x: 1, y: 1 };583 }584 this.speedX = Math.abs( object._scale.x - x ) / frames;585 this.speedY = Math.abs( object._scale.y - y ) / frames;586 this.object = object;587 this._x = x;588 this._y = y;589 this.onFinished = onFinished;590 }591 ScaleDown.prototype.onLoop = function(p) {592 if ( this.object._scale.x > this._x ) {593 this.object._scale.x -= this.speedX;594 }595 if ( this.object._scale.y > this._y ) {596 this.object._scale.y -= this.speedY;597 }598 if ( this.object._scale.x <= this._x && this.object._scale.y <= this._y ) {599 if ( this.onFinished ) this.onFinished.apply( this.object );600 return false;601 }602 return true;603 };604 /**605 * Creates a Twinkle object to be applied to the given renderers.Renderizable.606 * Twinkles the object when the onLoop method is called607 *608 * @class Twinkle609 * @constructor610 * @param {renderers.Renderizable} object the object to apply the effect to611 * @param {int} times times to twinkle612 * @param {int} duration duration in milliseconds of the effect613 * @param {Function} onFinished function to execute once the animation is finished614 */615 function Twinkle(object, times, duration, onFinished) {616 this.object = object;617 if ( times == undefined ) {618 this.times = 6;619 } else {620 this.times = times * 2;621 }622 if ( duration == undefined ) {623 this.duration = 250;624 } else {625 this.duration = duration;626 }627 this.lastTime = 0;628 this.onFinished = onFinished;629 }630 Twinkle.prototype.onLoop = function(p) {631 if ( M.getTimeInMillis() - this.lastTime >= this.duration ) {632 if ( this.times-- ) {633 if ( this.object._alpha == 1 ) {634 this.object.setAlpha( 0 );635 } else {636 this.object.setAlpha( 1 );637 }638 } else {639 this.object.setAlpha( undefined );640 if ( this.onFinished ) this.onFinished.apply( this.object );641 return false;642 }643 this.lastTime = M.getTimeInMillis();644 }645 return true;646 };647 /**648 * Creates a Rotate object to be applied to the given renderers.Renderizable.649 * Rotates the object when the onLoop method is called650 *651 * @class Rotate652 * @constructor653 * @extends GameObject654 * @param {renderers.Renderizable} object the object to apply the effect to655 * @param {float} angle angle to rotate the object to656 * @param {int} seconds duration in seconds of the effect657 * @param {Function} onFinished function to execute once the animation is finished658 */659 function Rotate( object, angle, seconds, onFinished ) {660 if ( ! seconds ) seconds = 1;661 662 this.frames = seconds * M.getAverageFps();663 if ( ! object._rotation ) {664 object._rotation = 0;665 }666 this.object = object;667 this.angle = angle;668 this.onFinished = onFinished;669 this._rotation = ( this.angle - object._rotation ) / this.frames;670 }671 Rotate.prototype.onLoop = function(p) {672 if ( this.frames-- ) {673 this.object.offsetRotation(this._rotation);674 } else {675 if ( this.onFinished ) this.onFinished.apply( this.object );676 return false;677 }678 return true;679 };680 /**681 * Fades an object in682 *683 * Usage example:684 *685 * fadeIn( object, seconds, onFinished );686 *687 */688 function fadeIn( object, seconds, onFinished ) {689 return new Animation( new FadeIn( object, seconds, onFinished ) ).play();690 }691 /**692 * Fades an object out693 *694 * Usage example:695 *696 * fadeOut( object, seconds, onFinished );697 *698 */699 function fadeOut( object, seconds, onFinished ) {700 return new Animation( new FadeOut( object, seconds, onFinished ) ).play();701 }702 703 /**704 * Fades an object out705 *706 * Usage example:707 *708 * fadeOut( object, seconds, onFinished );709 *710 */711 function continousFade( object, seconds, fadeOutFirst ) {712 return new Animation( new ContinousFade( object, seconds, fadeOutFirst ) ).play();713 }714 /**715 * Moves an object from a position to the other in a certain amout of time716 *717 * Usage example:718 *719 * move( object, x, y, seconds, acceleration, decceleration, onFinished );720 *721 */722 function move( object, x, y, seconds, onFinished ) {723 return new Animation( new Move( object, x, y, seconds, onFinished ) ).play();724 }725 /**726 * Scales an object from its current scale value to the one provided.727 *728 * Usage example:729 *730 * scaleUp( object, x, y, seconds, onFinished );731 *732 */733 function scaleUp( object, x, y, seconds, onFinished ) {734 return new Animation( new ScaleUp( object, x, y, seconds, onFinished ) ).play();735 }736 /**737 * Scales an object from its current scale value to the one provided.738 *739 * Usage example:740 *741 * scaleDown( object, x, y, seconds, onFinished );742 *743 */744 function scaleDown( object, x, y, seconds, onFinished ) {745 return new Animation( new ScaleDown( object, x, y, seconds, onFinished ) ).play();746 }747 /**748 * Makes an object twinkle an amount of times during certain time749 *750 * Usage example:751 *752 * twinkle( objectToApply, timesToTwinkle, durationInMilliseconds, onFinished );753 *754 */755 function twinkle( object, times, duration, onFinished ) {756 return new Animation( new Twinkle( object, times, duration, onFinished ) ).play();757 }758 /**759 * Rotates an object to the specified angle in seconds760 *761 * Usage example:762 *763 * rotate( objectToApply, angle, seconds, onFinished );764 *765 */766 function rotate( object, angle, seconds, onFinished ) {767 return new Animation( new Rotate( object, angle, seconds, onFinished ) ).play();768 }769 /**770 * @deprecated771 * Shakes the canvas for the specified duration of seconds772 */773 function shakeCanvas( duration ) {774 if ( ! M.canvas.shaking ) {775 M.canvas.shaking = true;776 M.canvas.style.position = "relative";777 M.push({778 779 startTime: M.getGameTime(),780 duration: duration || 1,781 onLoop: function(p) {782 if ( M.getGameTime() - this.startTime < this.duration ) {783 p.canvas.style.left = p.M.randomSign() + "px";784 p.canvas.style.top = p.M.randomSign() + "px";785 } else {786 p.canvas.style.left = "0px";787 p.canvas.style.top = "0px";788 p.M.remove( this );789 p.canvas.shaking = false;790 }791 }792 }, "shake");793 }794 }795 /**796 * @class visual797 */798 namespace.visual = {799 Particle: Particle,800 LinearParticleEmitter: LinearParticleEmitter,801 RadialParticleEmitter: RadialParticleEmitter,802 Tint: Tint,803 Move: Move,804 FadeIn: FadeIn,805 FadeOut: FadeOut,806 ContinousFade: ContinousFade,807 ScaleUp: ScaleUp,808 ScaleDown: ScaleDown,809 Rotate: Rotate,810 Twinkle: Twinkle,811 Wait: Wait812 };...

Full Screen

Full Screen

constants.ts

Source:constants.ts Github

copy

Full Screen

1import {2 Easing,3 runOnJS,4 withSpring,5 withTiming,6 interpolate,7} from 'react-native-reanimated';8import type { AnimatedConfiguration } from './types';9const BaseDuration = 250;10export const SpringConfiguration = {11 mass: 1,12 damping: 60,13 velocity: 0,14 stiffness: 280,15 overshootClamping: false,16 restSpeedThreshold: 0.001,17 restDisplacementThreshold: 0.001,18};19export const FadeConfiguration: AnimatedConfiguration = {20 style: (progress) => {21 'worklet';22 return { opacity: progress.value };23 },24 present: (progress, onFinished) => {25 progress.value = withTiming(26 1,27 { duration: BaseDuration, easing: Easing.ease },28 (isFinished) => {29 if (isFinished) {30 runOnJS(onFinished)();31 }32 }33 );34 },35 dismiss: (progress, onFinished) => {36 progress.value = withTiming(37 0,38 { duration: BaseDuration, easing: Easing.ease },39 () => {40 runOnJS(onFinished)();41 }42 );43 },44};45export const ScaleConfiguration: AnimatedConfiguration = {46 style: (progress) => {47 'worklet';48 return { transform: [{ scale: progress.value }] };49 },50 present: (progress, onFinished) => {51 progress.value = withSpring(1, SpringConfiguration, (isFinished) => {52 if (isFinished) {53 runOnJS(onFinished)();54 }55 });56 },57 dismiss: (progress, onFinished) => {58 progress.value = withTiming(59 0,60 { duration: BaseDuration, easing: Easing.ease },61 (isFinished) => {62 if (isFinished) {63 runOnJS(onFinished)();64 }65 }66 );67 },68};69export const SlideUpAnimation: AnimatedConfiguration = {70 style: (progress, extraInfo) => {71 'worklet';72 const { height, offsetY } = extraInfo.layout.value;73 return {74 opacity: interpolate(progress.value, [0, 1], [0, 1]),75 transform: [76 {77 translateY: interpolate(progress.value, [0, 1], [height, offsetY]),78 },79 ],80 };81 },82 present: (progress, onFinished) => {83 progress.value = withSpring(1, SpringConfiguration, (isFinished) => {84 if (isFinished) {85 runOnJS(onFinished)();86 }87 });88 },89 dismiss: (progress, onFinished) => {90 progress.value = withTiming(91 0,92 { duration: BaseDuration, easing: Easing.ease },93 (isFinished) => {94 if (isFinished) {95 runOnJS(onFinished)();96 }97 }98 );99 },100};101export const SlideDownConfiguration: AnimatedConfiguration = {102 style: (progress, extraInfo) => {103 'worklet';104 const { height, offsetY } = extraInfo.layout.value;105 //106 return {107 opacity: interpolate(progress.value, [0, 1], [0, 1]),108 transform: [109 {110 translateY: interpolate(progress.value, [0, 1], [-height, -offsetY]),111 },112 ],113 };114 },115 present: (progress, onFinished) => {116 progress.value = withSpring(1, SpringConfiguration, (isFinished) => {117 if (isFinished) {118 runOnJS(onFinished)();119 }120 });121 },122 dismiss: (progress, onFinished) => {123 progress.value = withTiming(124 0,125 { duration: BaseDuration, easing: Easing.ease },126 (isFinished) => {127 if (isFinished) {128 runOnJS(onFinished)();129 }130 }131 );132 },133};134export const SlideFromLeftConfiguration: AnimatedConfiguration = {135 style: (progress, extraInfo) => {136 'worklet';137 const { width, offsetX } = extraInfo.layout.value;138 return {139 opacity: interpolate(progress.value, [0, 1], [0, 1]),140 transform: [141 {142 translateX: interpolate(progress.value, [0, 1], [-width, -offsetX]),143 },144 ],145 };146 },147 present: (progress, onFinished) => {148 progress.value = withSpring(1, SpringConfiguration, (isFinished) => {149 if (isFinished) {150 runOnJS(onFinished)();151 }152 });153 },154 dismiss: (progress, onFinished) => {155 progress.value = withTiming(156 0,157 { duration: BaseDuration, easing: Easing.ease },158 (isFinished) => {159 if (isFinished) {160 runOnJS(onFinished)();161 }162 }163 );164 },165};166export const SlideFromRightConfiguration: AnimatedConfiguration = {167 style: (progress, extraInfo) => {168 'worklet';169 const { width, offsetX } = extraInfo.layout.value;170 return {171 opacity: interpolate(progress.value, [0, 1], [0, 1]),172 transform: [173 {174 translateX: interpolate(progress.value, [0, 1], [width, offsetX]),175 },176 ],177 };178 },179 present: (progress, onFinished) => {180 progress.value = withSpring(1, SpringConfiguration, (isFinished) => {181 if (isFinished) {182 runOnJS(onFinished)();183 }184 });185 },186 dismiss: (progress, onFinished) => {187 progress.value = withTiming(188 0,189 { duration: BaseDuration, easing: Easing.ease },190 (isFinished) => {191 if (isFinished) {192 runOnJS(onFinished)();193 }194 }195 );196 },197};198export const NoneConfiguration: AnimatedConfiguration = {199 style: (_) => {200 'worklet';201 return {};202 },203 present: (_, onFinished) => {204 runOnJS(onFinished)();205 },206 dismiss: (_, onFinished) => {207 runOnJS(onFinished)();208 },...

Full Screen

Full Screen

Progress.js

Source:Progress.js Github

copy

Full Screen

...31 if (data.data.task_status == 1) {32 $('#progress-wrap>div.taskmsg').text("任务已完成");33 $("#progress-wrap").stopTime('progress');34 if (typeof onFinished == 'function') {35 onFinished('success');36 }37 if (data.data.task_status == 2) {38 $('#progress-wrap>div.taskmsg').text(39 "任务出错:" + data.data.text);40 $("#progress-wrap").stopTime('progress');41 if (typeof onFinished == 'function') {42 onFinished('error');43 }44 }45 }46 } else {47 $("#progress-wrap").stopTime('progress');48 alert(data.message);49 }50 },51 error : function() {52 $("#progress-wrap").stopTime('progress');53 if (typeof onFinished == 'function') {54 onFinished('error');55 }56 }57 });58 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await qawolf.stopVideos();8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onFinished } = require('qawolf');2const { test, expect } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.fill('input[name="q"]', 'Hello World');5 await page.press('input[name="q"]', 'Enter');6 await onFinished(page);7});8npm ERR! 404 You should bug the author to publish it (or use the name yourself!)9npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onFinished } = require("qawolf");2const { createServer } = require("http");3const server = createServer((req, res) => {4 if (req.url === "/") {5 res.writeHead(200, { "Content-Type": "text/html" });6 res.end("Hello World");7 } else if (req.url === "/test") {8 res.writeHead(200, { "Content-Type": "text/html" });9 res.end("Test");10 }11});12server.listen(8080, () => {13 console.log("Server is running on port 8080");14});15onFinished(server, () => {16 console.log("Server has stopped");17});18const { onFinished } = require("qawolf");19const { createServer } = require("http");20const server = createServer((req, res) => {21 if (req.url === "/") {22 res.writeHead(200, { "Content-Type": "text/html" });23 res.end("Hello World");24 } else if (req.url === "/test") {25 res.writeHead(200, { "Content-Type": "text/html" });26 res.end("Test");27 }28});29server.listen(8080, () => {30 console.log("Server is running on port 8080");31});32onFinished(server, () => {33 console.log("Server has stopped");34});35const { onFinished } = require("qawolf");36const { createServer } = require("http");37const server = createServer((req, res) => {38 if (req.url === "/") {39 res.writeHead(200, { "Content-Type": "text/html" });40 res.end("Hello World");41 } else if (req.url === "/test") {42 res.writeHead(200, { "Content-Type": "text/html" });43 res.end("Test");44 }45});46server.listen(8080, () => {47 console.log("Server is running on port 8080");48});49onFinished(server, () => {50 console.log("Server has stopped");51});52const { onFinished } = require("qawolf");53const { createServer } = require("http");54const server = createServer((req, res) => {55 if (req.url === "/") {56 res.writeHead(200, { "Content-Type": "

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onFinished } = require("qawolf");2(async () => {3 const context = await qawolf.createContext();4 const page = await context.newPage();5 await page.type("#lst-ib", "Hello world!");6 await page.click("input[type='submit']");7 await page.waitForSelector("h1");8 await page.click("button[title='Search']");9 await page.waitForSelector("h1");10 await page.click("button[title='Search']");11 await page.waitForSelector("h1");12 await page.click("button[title='Search']");13 await page.waitForSelector("h1");14 await page.click("button[title='Search']");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onFinished } = require("qawolf");2onFinished(async () => {3 console.log("test finished");4});5onFailed(async () => {6 console.log("test failed");7});8onPassed(async () => {9 console.log("test passed");10});11onFailed(async () => {12 console.log("test failed");13});14onPassed(async () => {15 console.log("test passed");16});17onFailed(async () => {18 console.log("test failed");19});20onPassed(async () => {21 console.log("test passed");22});23onFailed(async () => {24 console.log("test failed");25});26onPassed(async () => {27 console.log("test passed");28});29onFailed(async () => {30 console.log("test failed");31});32onPassed(async () => {33 console.log("test passed");34});35onFailed(async () => {36 console.log("test failed");37});38onPassed(async () => {39 console.log("test passed");40});41onFailed(async () => {42 console.log("test failed");43});44onPassed(async () => {45 console.log("test passed");46});47onFailed(async () => {48 console.log("test failed");49});50onPassed(async () => {51 console.log("test passed");52});53onFailed(async () => {54 console.log("test failed");55});56onPassed(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onFinished } = require("qawolf");2const { chromium } = require("playwright-chromium");3const { startServer } = require("qawolf");4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const server = await startServer({ port: 3000 });9 await onFinished(page, "test", { server });10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { join } = require('path');2const { readFileSync, writeFileSync } = require('fs');3const { onFinished } = require('qawolf');4const test = require('./test');5describe('test', () => {6 let browser;7 beforeAll(async () => {8 browser = await qawolf.launch();9 });10 afterAll(async () => {11 await browser.close();12 });13 it('test', async () => {14 const context = await browser.newContext();15 const page = await context.newPage();16 await onFinished(page, async () => {17 const screenshot = await page.screenshot();18 writeFileSync(join(__dirname, 'test.png'), screenshot);19 });20 await test(page);21 });22});23const { join } = require('path');24const { readFileSync, writeFileSync } = require('fs');25const { save } = require('qawolf');26const test = require('./test');27describe('test', () => {28 let browser;29 beforeAll(async () => {30 browser = await qawolf.launch();31 });32 afterAll(async () => {33 await browser.close();34 });35 it('test', async () => {36 const context = await browser.newContext();37 const page = await context.newPage();38 await test(page);39 await save(page, join(__dirname, 'test.png'));40 });41});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful