Skip to content

Instantly share code, notes, and snippets.

@vassvik
vassvik / Simulation_Projection.md
Last active June 13, 2024 09:23
Realtime Fluid Simulation: Projection

Realtime Fluid Simulation: Projection

The core of most real-time fluid simulators, like the one in EmberGen, are based on the "Stable Fluids" algorithm by Jos Stam, which to my knowledge was first presented at SIGGRAPH '99. This is a post about one part of this algorithm that's often underestimated: Projection

MG4_F32.mp4

Stable Fluids

The Stable Fluids algorithm solves a subset of the famous "Navier Stokes equations", which describe how fluids interact and move. In particular, it typically solves what's called the "incompressible Euler equations", where viscous forces are often ignored.

@spite
spite / index.svg
Last active March 20, 2021 13:51
WebGL in SVG via foreignObject
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// This is Twigl's "geekest mode" so the code runs inside a "main" function.
// FC.xy is fragcoord
// r.xy is resolution
// t is time (in seconds I think)
// o.rgba is output color
// This is the original code, before any readability improvements:
/*
#define X(S,D)I=ivec3(S);D=fract(float(I.x^I.y^I.z)*PI
const {hexToHsluv, hsluvToHex} = require('hsluv')
const interpolate = (a1, a2) => x => a1.map((c, i) => c + (a2[i] - c) * x)
const range = steps => Array.from({length: steps + 1}, (_, i) => i / steps)
const stopsToHsluv = (start, end) => {
const hStart = hexToHsluv(start)
const hEnd = hexToHsluv(end)
const throughZero = Math.abs(hStart[0] - hEnd[0]) > 180
@positlabs
positlabs / spark-convert-audio.sh
Last active August 5, 2021 20:20
FFMPEG audio conversion for Spark AR
#! /bin/bash
# This command converts audio according to the specifications listed in the Spark docs:
# https://sparkar.facebook.com/ar-studio/learn/documentation/docs/audio
# mono m4a, 44.1kHz sample rate, 16-bit-depth resolution
# Usage:
# convert-audio.sh myaudio.mp3 converted.m4a
# Notes:
# Always use m4a for output file type
# Change "64k" to a higher value to improve bitrate/quality. e.g. 96k 128k 192k
@matthewmayer
matthewmayer / whatthefont.js
Last active July 10, 2020 13:30
paste this into Javascript console to see what fonts are being used
function walk(node) {
// I stole this function from here:
// http://is.gd/mwZp7E
var child, next;
var tagName = node.tagName ? node.tagName.toLowerCase() : "";
if (tagName == 'input' || tagName == 'textarea') {
return;
}
@changhuixu
changhuixu / copy-to-clipboard.ts
Last active April 7, 2020 13:53
JavaScript Copy To Clipboard Example
copy() {
try {
if ((navigator as any).clipboard) {
(navigator as any).clipboard.writeText(this.couponCode);
} else if ((window as any).clipboardData) { // IE
(window as any).clipboardData.setData('text', this.couponCode);
} else { // other browsers, iOS, Mac OS
this.copyToClipboard(this.inputEl.nativeElement);
}
this.tooltipText = 'Copied to Clipboard.'; // copy succeed.
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Plexus
// Collab by Ben Ursu & Dan Cronin | Afrosquared
// Spark AR Studio
// Instagram | https://www.instagram.com/a/r/?effect_id=2029175904053487
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Laser Focused
// Ben Ursu | Afrosquared
// Spark AR Studio
// Instagram | https://www.instagram.com/a/r/?effect_id=206763150244323
@surma
surma / README.md
Last active March 8, 2024 12:06
webpack-emscripten-wasm

Minimal example making webpack and wasm/Emscripten work together.

Build instructions:

  • Clone this gist
  • npm install
  • npm start
  • Open http://localhost:8080
  • Look at console