Skip to content

Instantly share code, notes, and snippets.

View raphaelameaume's full-sized avatar

Raphaël Améaume raphaelameaume

View GitHub Profile
@raphaelameaume
raphaelameaume / syncProps.js
Created February 1, 2024 13:23
Save/retrieve props with localStorage
function syncProps(props) {
return Object.keys(props).reduce((all, key) => {
const prop = { ...props[key] };
const storageKey = `${key}`;
const { onChange = () => {} } = prop;
prop.onChange = (prop) => {
localStorage.setItem(storageKey, JSON.stringify(prop.value));
@raphaelameaume
raphaelameaume / ffmpeg.md
Last active September 24, 2020 08:05
Useful commands for ffmpeg
  • Change extension
ffmpeg  -i input.MOV -c copy  output.mp4
  • Add black borders to video
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" output.mp4
@raphaelameaume
raphaelameaume / mapRange.glsl
Created September 10, 2020 10:01
Map a value from one value to another in glsl
float mapRange(float value, float low1, float high1, float low2, float high2) {
return low2 + (value - low1) * (high2 - low2) / (high1 - low1);
}
@raphaelameaume
raphaelameaume / uvRotate.glsl
Created May 29, 2020 15:03
Rotate uv in fragment shader
vec2 uvRotate (vec2 baseUv, float angle, vec2 center) {
vec2 uv = baseUv;
uv -= center;
mat2 m = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
uv = m * uv;
uv += center;
return uv;
@raphaelameaume
raphaelameaume / uvContain.glsl
Created May 29, 2020 15:02
Simulate background-size contain in fragment shader
vec2 uvContain(vec2 baseUv, vec2 size, vec2 resolution) {
float tAspect = size.x / size.y;
float pAspect = resolution.x / resolution.y;
float pWidth = resolution.x;
float pHeight = resolution.y;
float width = 0.;
float height = 0.;
if ( tAspect < pAspect ) {
@raphaelameaume
raphaelameaume / uvCover.glsl
Created May 29, 2020 15:01
Simulate background:size cover in fragment shader
vec2 uvCover (vec2 uv, vec2 size, vec2 resolution) {
vec2 coverUv = uv;
vec2 s = resolution; // Screen
vec2 i = size; // Image
float rs = s.x / s.y;
float ri = i.x / i.y;
vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);
vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;
@raphaelameaume
raphaelameaume / uvScale.glsl
Created May 29, 2020 15:00
Scale uv in fragment shader
vec2 uvScale (vec2 baseUv, float scale) {
vec2 uv = baseUv;
float s = 1. / scale;
uv = uv * s - ( s - 1.) * 0.5;
return uv;
}
vec2 uvScale (vec2 baseUv, vec2 scale) {