Skip to content

Instantly share code, notes, and snippets.

@arifd
arifd / mmtrim
Last active September 26, 2021 15:10
Take an input movie file, blend a thumbnail to the beginning, normalize loudess and fade out at the end
#!/bin/bash
# Take an input movie file,
# blend a thumbnail to the beginning
# normalize loudness and fade in audio
# fade out at end
# encode for youtube/sharing
# Generate a test video:
# ffmpeg -f lavfi -i testsrc -f lavfi -i aevalsrc="sin(100*t*2*PI*t)" -vf "drawtext=box=1:fontsize=70:text='%{pts\:flt}':x=(w-text_w)/2:y=(h-text_h)/2" -t 10 out.avi
@arifd
arifd / mmcapture
Last active October 5, 2021 21:32
FFMPEG wrapper for screen/microphone capture with well tuned defaults/processing
#!/bin/bash
###############################################################################
# This script is a wrapper over ffmpeg with well-tuned defaults and filters #
# to get the best out of your input devices #
# #
# Screen capture to file will prompt to trim, master and encode audio #
# #
# TODO: camera source / v4l2 sink still not implemented #
# #
@arifd
arifd / place.rs
Created May 24, 2021 14:44
Druid GUI Widget that holds a child and places it at a given x,y coordinate relative to parent
//! Place a widget anywhere in x,y pixel space
use druid::widget::prelude::*;
use druid::{Data, Point, WidgetPod};
pub struct Place<T> {
children: Vec<ChildWidget<T>>,
}
@arifd
arifd / on_change_controller.rs
Last active May 19, 2021 12:17
A helper mod for the Rust Driuid GUI library, to bypass the AppDelgate in order to mutate data on a data change event
use druid::{widget::Controller, Data, Env, Event, EventCtx, Selector, UpdateCtx, Widget};
/// Bypass the `AppDelegate` entirely by appending the return from this function as a
/// `Controller` wrapping whatever you wish to perform a desired action when there is a change in the data
///
/// # Example
///
/// ```
///TextBox::new()
/// .lens(AppData::foo)
@arifd
arifd / build.sh
Created October 1, 2020 21:48
Miniquad, Rust, WASM, Web, build script
#!/bin/bash
#===========================================================================================#
# Miniquad WASM/Web Builder #
# #
# Put this script at the base of your cargo project and run it to quickly build and test #
# your miniquad project in a WASM/Web environment. #
# #
# It creates and pulls in all the necessary files into a directory called 'www/' leaving #
# the originals intact. Just delete the www folder to undo its effect. #
// cheaper smoothstep
// https://forum.unity.com/threads/how-expensive-is-smooth-step-in-shaders-for-mobile.501809/
float cheapstep(float a, float b, float x) {
// remap the value
float remap = x * (1.0 / (b - a)) - (a / (b - a));
// clamp it to 0 and 1, as smoothstep would
return clamp(0., 1., remap);
}
@arifd
arifd / gloss.glsl
Created July 14, 2020 11:48
Overlay a gradient to every pixel
// adds a cinematic sheen by overlaying a glossy radial gradient to every pixel
float gloss(vec2 uv) {
uv = abs(uv - 0.5);
float length2 = dot(uv,uv);
return exp(-length2);
}
@arifd
arifd / getPercentVisible.js
Created April 2, 2020 18:41
Manually determine how much of a HTML element intersects with the viewport
// A function to know how much of a HTML element has been scrolled onto your viewport.
// Note: This should no longer be used, prefer: IntersectionObserver.
// https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
const clamp = (val, min, max) => Math.min(Math.max(min, val), max);
getPercentVisible(element) {
const rect = element.getBoundingClientRect();
// If not even partially visible, return early
if (rect.top >= window.innerHeight || rect.bottom <= 0) return 0;
@arifd
arifd / theatre-curtain-preloader.js
Created March 31, 2020 17:25
Theatre/Theater/Stage Curtain/Drape Preloader for any website
// THEATRE CURTAIN PRELOADER
// by: Arif Driessen
// about: this code produces a fast loading, auto revealing theatre-curtain preloader.
// usage: put this code inside <script> tags INSIDE and at the top of <body>
function createCurtainCSS(NUMFOLDS) {
// draw a preloading Curtain!
const parabola = val => Math.pow(4.0 * val * (1.0 - val), 1.0);
let curtainCSS = 'background-image: ';
// fade to top
curtainCSS += 'linear-gradient(180deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0) 100%), ';
@arifd
arifd / mathstuff.js
Last active October 18, 2020 09:34
Useful common mathematical functions
// Clamp val between min and max
const clamp = (val, min, max) => Math.min(Math.max(min, val), max);
// Supply a value and a range, return val normalized to 0 and 1
const normalize = (val, min, max) => (val - min) / (max - min);
// Shaping Functions ///////////////////////////////////////
// Parabola val between 0 and 1.
// Original function by Iñigo Quiles