Skip to content

Instantly share code, notes, and snippets.

View stoeckley's full-sized avatar

andrew stoeckley

  • Balcony Studio
  • Netherlands
View GitHub Profile
@stoeckley
stoeckley / RGBtoHSV.swift
Created February 12, 2022 21:29 — forked from FredrikSjoberg/RGBtoHSV.swift
Color space conversion between RGB and HSV
// https://www.cs.rit.edu/~ncs/color/t_convert.html
struct RGB {
// Percent
let r: Float // [0,1]
let g: Float // [0,1]
let b: Float // [0,1]
static func hsv(r: Float, g: Float, b: Float) -> HSV {
let min = r < g ? (r < b ? r : b) : (g < b ? g : b)
let max = r > g ? (r > b ? r : b) : (g > b ? g : b)
@stoeckley
stoeckley / ConeTraceAnalytic.txt
Created December 14, 2021 12:57 — forked from sebbbi/ConeTraceAnalytic.txt
Cone trace analytic solution
Spherical cap cone analytic solution is a 1d problem, since the cone cap sphere slides along the ray. The intersection point to empty space sphere is always on the ray.
S : radius of cone cap sphere at t=1
r(d) : cone cap sphere radius at distance d
r(d) = d*S
p = distance of current SDF sample
SDF(p) = sdf function result at location p
x = distance after conservative step
@stoeckley
stoeckley / gist:1452ffceb62c3d8479810cd5edc36583
Created October 1, 2020 14:08 — forked from boredzo/gist:4604459
Two-color angle gradient in Core Image
kernel vec4 coreImageKernel(__color startColor, __color endColor)
{
vec2 point = destCoord();
float angle = atan(point.y, point.x) + radians(180.0);
//Start from the upper middle, not the left middle
angle += radians(90.0);
angle = mod(angle, radians(360.0));
float fraction = angle / radians(360.0);
@stoeckley
stoeckley / README.md
Created January 30, 2020 18:54 — forked from nikcub/README.md
Facebook PHP Source Code from August 2007
@stoeckley
stoeckley / gfx-tinykaboom.go
Created August 13, 2019 12:14 — forked from peterhellberg/gfx-tinykaboom.go
tinykaboom with gfx
package main
import (
"image"
"image/color"
"math"
"github.com/peterhellberg/gfx"
)
@stoeckley
stoeckley / raytracer.jl
Created November 29, 2018 23:58 — forked from IainNZ/raytracer.jl
Raytracer in Julia
const delta = sqrt(eps(Float64))
immutable Vec
x::Float64
y::Float64
z::Float64
end
+(a::Vec, b::Vec) = Vec(a.x+b.x, a.y+b.y, a.z+b.z)
-(a::Vec, b::Vec) = Vec(a.x-b.x, a.y-b.y, a.z-b.z)
*(a::Float64, b::Vec) = Vec(a*b.x, a*b.y, a*b.z)
@stoeckley
stoeckley / raytracer.nim
Created October 8, 2018 18:26 — forked from hcorion/raytracer.nim
A port of a raytracer, programmed in Nim, built by someone else, to sdl2
#Originally created by AdrianV and can be found here: https://gist.github.com/AdrianV/5774141
#Modified by me, hcorion to add sdl2 support and bring it up to speed with version 0.14.2 of Nim (nim-lang.org).
import math
import sequtils
import sdl2
import times
const
width = 1280
@stoeckley
stoeckley / waves.pde
Created April 4, 2018 20:29 — forked from beesandbombs/waves.pde
waves
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@stoeckley
stoeckley / gist:5965f45cf6bc7853061e5d672ddd3577
Created January 1, 2018 14:04
best way to make this simple struct hashable?
// trying to keep this Hashable simple while minimizing collisions:
struct Simple: Hashable {
enum MyEnum: Int {
case a,b,c,d
}
let enumValue: MyEnum
let someInt: Int