A library of visual effects for the web. Each effect is exported as a small
wrapper with a create(canvas, opts) API that mounts it onto a <canvas>
element and returns start() / stop() controls.
Currently shipping:
scanBarEffect— a rising white gradient bar with an ASCII-ember halo, layered over a CSS-styled background.
This package lives in a yarn workspace as @wix/visual-fx-web.
yarn add @wix/visual-fx-webimport {scanBarEffect} from '@wix/visual-fx-web';
const canvas = document.querySelector('#stage canvas');
const bg = document.querySelector('#stage .bg'); // optional
const params = {
comp: {
recolor: {sat: 1, bri: 1, con: 1},
layers: [
{top: [255, 80, 0], bottom: [0, 0, 0], mode: 0, opacity: 0.6, on: true},
{top: [255, 255, 255], bottom: [0, 0, 0], mode: 1, opacity: 0.3, on: true},
{fill: [20, 0, 40], mode: 2, opacity: 0.2, on: false},
],
},
ember: {enabled: true, speed: 1.0, height: 0.25, isWhite: false},
bar: {speed: 120, solid: 6, fade: 40, spread: 1.0},
};
const scanBar = scanBarEffect.create(canvas, {
bgSourceEl: bg, // optional — element to receive recoloring + blending CSS
params, // live references; mutate to change the effect on the fly
});
scanBar.start(); // begin animation
// ...
scanBar.stop(); // pause; call start() again to resumeThe effect expects the canvas and (optional) background element to share a CSS grid cell so they stack:
<div class="stage">
<div class="bg"><!-- your styled background: image, color, etc. --></div>
<canvas></canvas>
</div>
<style>
.stage { display: grid; overflow: hidden; }
.stage > * { grid-area: 1 / 1; }
</style>Pass the .bg element as bgSourceEl to opt into the CSS recoloring +
blending layers. Pass null for canvas-only mode.
params is a plain object the host owns and the effect reads by reference
each frame, so mutating fields (e.g. from sliders) takes effect on the next
paint.
comp.recolor—{sat, bri, con}applied tobgSourceElas a CSSfilter.comp.layers— three blend layers painted overbgSourceElviamix-blend-mode. L1/L2 are vertical gradients (top/bottomcolors); L3 is a solidfill.mode: 0=darken, 1=luminosity, 2=difference.ember—{enabled, speed, height, isWhite}for the ASCII-ember halo. Setenabled: falseto render the bar alone.bar—{speed, solid, fade, spread}for the gradient bar itself.speedis in CSS px/sec;solidandfadeare CSS px;spreadis a unitless horizontal scale.
See CONTRIBUTING.md for the playground app, project layout, and library build instructions.