Return a color contained in a vec3.
Should be between 0 and 360
Should be between 0 and 100
Should be between 0 and 100
source: https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
Return a color contained in a vec3.
Should be between 0 and 1
Should be between 0 and 1
Should be between 0 and 1
Return a color contained in a vec3.
Should be between 0 and 255
Should be between 0 and 255
Should be between 0 and 255
Return a color with transparency contained in a vec4.
Should be between 0 and 1
Should be between 0 and 1
Should be between 0 and 1
Should be between 0 and 1
Return a color with transparency contained in a vec4.
Should be between 0 and 255
Should be between 0 and 255
Should be between 0 and 255
Should be between 0 and 255
Providing a noise texture is required for this drawable.
Compiles a new renderer instance. There can multiple renderers on a single page.
Asynchronous behaviour is required for parallel shader compiling. Trying to draw before the returned promise resolves, results in no action taken. Settings can be set before promise resolution and they will be applied later.
The descriptors of every to-be-drawn objects are required before creating the renderer, allowing the compiler to only create the shaders that will actually be used.
Example usage:
import { compile, hsl, CircleFactory, CircleLight } from 'sdf-2d';
const canvas = document.querySelector('canvas');
const Circle = CircleFactory(hsl(30, 66, 50));
const renderer = await compile(canvas, [Circle.descriptor, CircleLight.descriptor]);
The returned renderer will only be able to draw to this canvas.
The descriptor of every single object (and light) that ever needs to be drawn by this renderer has to be given before compiling.
Sensible defaults are provided, but these can be overridden.
Create a renderer, draw a 2D noise texture with it, then destroy the used resources, while returning the generated texture in the form of a canvas.
The resolution of the end result
A starting value can be 15
A starting value can be 1
Ignore WebGL2, even when it's available
Implements the boilerplate code required to run real-time animations
in the browser. An FPS based autoscaler is also used. This creates an additional fps
key in the renderers insights
property.
Example usage:
<canvas id="main" style="width: 300px; height: 150px"></canvas>
The canvas needs to have a fixed size specified by CSS.
import { CircleFactory, CircleLight, hsl, runAnimation } from 'sdf-2d';
const canvas = document.querySelector('canvas');
const Circle = CircleFactory(hsl(180, 100, 40));
runAnimation(canvas, [Circle.descriptor, CircleLight.descriptor], (renderer, time) => {
renderer.addDrawable(
new Circle([150 + 50 * Math.cos(time / 1000), 75 + 50 * Math.sin(time / 1000)], 25)
);
renderer.addDrawable(new CircleLight([150, 75], hsl(270, 100, 40), 0.1));
return true;
});
The returned renderer will only be able to draw to this canvas.
The descriptor of every single object (and light) that ever needs to be drawn by this renderer has to be given before compiling.
This function will be called before rendering each frame.
renderDrawables
must not be called by the animate function. It should return true
if the animation should be continued. To break out of the animation loop, a false
(falsy)
return value must be given.
Contains the default values used for RuntimeSettings.
Contains the default values used for StartupSettings.
Return a color given in a hexadecimal form as a vec3.
A hexadecimal color with (#ff0000) or without (ff0000) a leading hash mark.
source: https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb