Skip to content

Instantly share code, notes, and snippets.

@SpineyPete
SpineyPete / rounded_rect_ngon.lua
Created April 22, 2021 09:12
Generates a rounded rectangle n-gon, renderable with a triangle fan.
function roundrectpoly(x, y, w, h, r, n)
-- required args
assert(x ~= nil and type(x) == "number")
assert(y ~= nil and type(y) == "number")
assert(w ~= nil and type(w) == "number")
assert(h ~= nil and type(h) == "number")
-- optional args
assert(r == nil or type(r) == "number")
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@SpineyPete
SpineyPete / grid.styl
Last active October 6, 2019 14:32
Stylus Flexbox Grid System
// -------
// Globals
// -------
pagewidth = 50rem
hgap = 1rem
vgap = 1rem
// ----------------
// Utlity Functions
@SpineyPete
SpineyPete / hemisphere_concentric.pde
Last active April 11, 2022 18:40
Concentric Hemisphere Point Generator (Processing 3 Sketch)
// Visualization of Shirley and Chui's Concentric Mapping
// projected onto a hemisphere -- e.g. for irradiance tracing.
// The points are drawn to the window and C code is output to the console.
// This import is needed since Processing 4.
// In Processing complains about it not finding it:
// In the menubar go to to sketch -> import library -> add library,
// enter javafx in the searchbox and download it.
import processing.javafx.*;
@SpineyPete
SpineyPete / fibonacci.c
Created January 5, 2019 17:51
fibonacci number formula (untested)
double fib(int n) {
const double sqrt5 = sqrt(5);
const double phi_a = (1 + sqrt5)/2;
const double phi_b = (1 - sqrt5)/2;
return (pow(phi_a, n) - pow(phi_b, n))/sqrt5;
}
@SpineyPete
SpineyPete / gist:0f2ae2bbfe7a222f01158c14a6279890
Created December 4, 2018 19:35
Adaptively Subdivided Fan (Processing 3.0)
PVector clickPos = new PVector(0, 0);
PVector clickRadi = new PVector(100, 100);
void angler(
PVector arcPos, float arcRadi, float arcTurn, PVector arcDir,
float stepSize, boolean fixStep) {
float halfAngle = PI*arcTurn;
float totalAngle = TAU*arcTurn;
float totalSteps = totalAngle*arcRadi/stepSize;
// Makes text funky.
"use strict";
function funkyType(selector, args) {
function limitDecimals(n, decimals) {
decimals = Math.pow(10, decimals);
return Math.trunc(n * decimals) / decimals;
}
// sRGB to/from linear-space conversions, by Ian Taylor
// source: http://chilliant.blogspot.be/2012/08/srgb-approximations-for-hlsl.html
// Alternate LinearToGamma(), without pow():
// srgb = 0.585122381 * sqrt(linear) +
// 0.783140355 * sqrt(sqrt(linear)) -
// 0.368262736 * sqrt(sqrt(sqrt(linear)));
vec3 LinearToGamma(in vec3 linear) {
return max(1.055f * pow3(linear, 0.416666667f) - 0.055f, 0);
@SpineyPete
SpineyPete / hdr_crosstalk.glsl
Last active October 27, 2017 01:02
Crosstalk
// Crosstalk makes HDR highlights tend towards white.
// This is more realistic and maintains definition in overexposed areas.
// --
// Threshold is the point at which the desaturation kicks in.
// Shallowness is the rate at which the color reaches pure white.
// Higher Shallowness values create a slower rise.
vec3 Crosstalk(vec3 color, float threshold, float shallowness) {
// Luminosity
float luma = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
@SpineyPete
SpineyPete / phong_metal.glsl
Created July 28, 2017 12:13
Metallic BRDF
float PhongBase(vec3 viewdir, vec3 lightdir, vec3 normal) {
return max(-dot(viewdir, reflect(lightdir, normal)), 0.0);
}
// Analytic specular without ambient specular might look better like this.
float HalfPhongBase(vec3 viewdir, vec3 lightdir, vec3 normal) {
return -dot(viewdir, reflect(lightdir, normal)) / 2 + 0.5;
}
// Something to approximate the longer tail