Skip to content

Instantly share code, notes, and snippets.

@cache-tlb
cache-tlb / FordCircle.html
Last active November 20, 2022 03:26
draw Ford circle with canvas
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>test</title>
</head>
<body>
<br/>
@cache-tlb
cache-tlb / HilbertCurve.html
Last active November 11, 2022 11:14
generate Hilbert Curve on a canvas
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>test</title>
</head>
<body>
<canvas id="canvas"> </canvas>
@cache-tlb
cache-tlb / hand_writting_stokes.html
Last active November 11, 2022 06:03
"Simulating brush strokes with Hooke’s Law in P5JS" (actually with html canvas 2d context)
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>test</title>
</head>
<body>
<canvas id="canvas"> </canvas>
@cache-tlb
cache-tlb / GPUOptimizationForGameDev.md
Created February 8, 2022 07:45 — forked from silvesthu/GPUOptimizationForGameDev.md
GPU Optimization for GameDev
@cache-tlb
cache-tlb / double_pendulum.py
Created January 14, 2021 08:20
Double Pendulum simulation, showing chaos effect
import numpy as np
import math
g = 9.81
dt = 0.005
class Param:
def __init__(self):
self.mass = [1,1]
self.length = [1,1]
@cache-tlb
cache-tlb / print_pi.c
Created January 20, 2020 07:11
mysterious c code that prints pi
long a=10000,b,c=2800,d,e,f[2801],g;
void main(){
for(;b-c;)f[b++] =a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
}
@cache-tlb
cache-tlb / halton.c
Created September 30, 2019 07:49
generate halton sequence
float Halton( int32 Index, int32 Base )
{
float Result = 0.0f;
float InvBase = 1.0f / Base;
float Fraction = InvBase;
while( Index > 0 )
{
Result += ( Index % Base ) * Fraction;
Index /= Base;
Fraction *= InvBase;
@cache-tlb
cache-tlb / spherical_parameterization.py
Last active May 7, 2019 08:33
convert an unit vector to octahedron / cubic environment map uv
# see : "Octahedron Environment Maps" by Thomas Engelhardt and Carsten Dachsbacher
# https://pdfs.semanticscholar.org/fcb9/a6dbdf7b4c31f94e481cf101c83b73ea6410.pdf
def xyz_to_oct_uv(vec):
v = vec / np.sqrt(np.dot(vec, vec))
v = v / np.sum( np.abs(v) )
if v[1] < 0:
x = (1-np.abs(v[2])) * np.sign(v[0]);
z = (1-np.abs(v[0])) * np.sign(v[2]);
else:
x,z = v[0],v[2]
@cache-tlb
cache-tlb / FFT.cpp
Last active September 29, 2017 04:47
simple fft template
#define lowbit(x) (((x) ^ (x-1)) & (x))
typedef complex<long double> Complex;
void FFT(vector<Complex> &A, int s){
int n = A.size();
int p = __builtin_ctz(n);
vector<Complex> a = A;
for(int i = 0;i<n;++i){
@cache-tlb
cache-tlb / YawPitchRowToMat.cpp
Created August 17, 2017 11:16
convert yaw, pitch, row to a rotation matrix
// http://planning.cs.uiuc.edu/node102.html
inline Mat4f YawPitchRowToMat4(float yaw, float pitch, float row) {
Mat4f m;
m.at(3,3) = 1;
float sina = sin(yaw), cosa = cos(yaw);
float sinb = sin(pitch), cosb = cos(pitch);
float sinc = sin(row), cosc = cos(row);
m.at(0,0) = cosa*cosb;
m.at(0,1) = cosa*sinb*sinc - sina*cosc;