MCPcopy Index your code
hub / github.com/codrops/RainEffect / flash

Function flash

src/index.js:274–305  ·  view source on GitHub ↗
(baseBg,baseFg,flashBg,flashFg)

Source from the content-addressed store, hash-verified

272}
273
274function flash(baseBg,baseFg,flashBg,flashFg){
275 let flashValue={v:0};
276 function transitionFlash(to,t=0.025){
277 return new Promise((resolve,reject)=>{
278 TweenLite.to(flashValue,t,{
279 v:to,
280 ease:Quint.easeOut,
281 onUpdate:()=>{
282 generateTextures(baseFg,baseBg);
283 generateTextures(flashFg,flashBg,flashValue.v);
284 renderer.updateTextures();
285 },
286 onComplete:()=>{
287 resolve();
288 }
289 });
290 });
291 }
292
293 let lastFlash=transitionFlash(1);
294 times(random(2,7),(i)=>{
295 lastFlash=lastFlash.then(()=>{
296 return transitionFlash(random(0.1,1))
297 })
298 })
299 lastFlash=lastFlash.then(()=>{
300 return transitionFlash(1,0.1);
301 }).then(()=>{
302 transitionFlash(0,0.25);
303 });
304
305}
306function generateTextures(fg,bg,alpha=1){
307 textureFgCtx.globalAlpha=alpha;
308 textureFgCtx.drawImage(fg,0,0,textureFgSize.width,textureFgSize.height);

Callers 1

setupFlashFunction · 0.70

Calls 3

randomFunction · 0.90
transitionFlashFunction · 0.70
timesFunction · 0.70

Tested by

no test coverage detected