Skip to content
d4vidiPublic

About

WebGL playground for 2D fragment-shader experiments

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

visual-fx

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.

Install

This package lives in a yarn workspace as @wix/visual-fx-web.

yarn add @wix/visual-fx-web

Usage — scanBarEffect

import {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 resume

DOM layout

The 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

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 to bgSourceEl as a CSS filter.
  • comp.layers — three blend layers painted over bgSourceEl via mix-blend-mode. L1/L2 are vertical gradients (top / bottom colors); L3 is a solid fill. mode: 0=darken, 1=luminosity, 2=difference.
  • ember — {enabled, speed, height, isWhite} for the ASCII-ember halo. Set enabled: false to render the bar alone.
  • bar — {speed, solid, fade, spread} for the gradient bar itself. speed is in CSS px/sec; solid and fade are CSS px; spread is a unitless horizontal scale.

Contributing

See CONTRIBUTING.md for the playground app, project layout, and library build instructions.

About

WebGL playground for 2D fragment-shader experiments

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages