Skip to content

Instantly share code, notes, and snippets.

float remap(float value, float originMin, float originMax, float destinationMin, float destinationMax) {
return destinationMin + (value - originMin) * (destinationMax - destinationMin) / (originMax - originMin);
}
float random2D(vec2 value) {
return fract(sin(dot(value.xy, vec2(12.9898,78.233))) * 43758.5453123);
}
vec2 rotate(vec2 v, float a) {
float s = sin(a);
float c = cos(a);
return vec2(
c * v.x - s * v.y,
s * v.x + c * v.y
);
}
// Classic Perlin 3D Noise
// by Stefan Gustavson
//
vec4 permute(vec4 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
vec3 fade(vec3 t) { return t*t*t*(t*(t*6.0-15.0)+10.0); }
float cnoise(vec3 P) {
vec3 Pi0 = floor(P); // Integer part for indexing
vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
export default class EventEmitter {
on(type, listener) {
if (this._listeners === undefined) this._listeners = {};
const listeners = this._listeners;
if (listeners[type] === undefined)
listeners[type] = listener;
else if (typeof listeners[type] === 'function')