Skip to content

Instantly share code, notes, and snippets.

@damienmortini
damienmortini / serviceworker.js
Created January 27, 2020 18:03
Service Worker to replace absolute module paths by relatives node_module paths
self.addEventListener('activate', () => {
self.clients.claim();
});
self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET' || event.request.destination !== 'script') {
return;
}
event.respondWith(fetch(event.request).then((response) => {
// from http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
// http://www.iquilezles.org/www/articles/morenoise/morenoise.htm
// Hector Arellano
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
const float inv289 = 0.00346020761;

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@damienmortini
damienmortini / ScaleX
Last active August 29, 2015 14:22 — forked from nicoptere/ScaleX
/*
JavaScript port of the following algorithm : http://scale2x.sourceforge.net/algorithm.html
*/
var scaleX = ( function( exports )
{
function getPixel32( data, x,y,w )
/*
** Copyright (c) 2012, Romain Dura [email protected]
**
** Permission to use, copy, modify, and/or distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY