Skip to content

Instantly share code, notes, and snippets.

@pekkavaa
pekkavaa / ConeTraceAnalytic.txt
Created November 6, 2021 12:39 — 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
@pekkavaa
pekkavaa / extending csv.md
Last active November 13, 2022 01:07
A Straightforward Way To Extend CSV With Metadata

A Straightforward Way To Extend CSV With Metadata

Pekka Väänänen, Aug 19 2021.

This proposal is a response to It's Time to Retire the CSV by Alex Rasmussen and the discussion on lobste.rs. Don't take it too seriously.

CSV files (comma-separated values) are great but sometimes difficult to parse because everybody seems to have a slightly different idea what CSV means. The obvious solution is to transmit some metadata that tells what to expect but where do you put it? Well, how about a ZIP archive?

An archive with two files. The first file, say format.txt, has the metadata inside and the second one is the original CSV file unchanged. This is still readable by non-technical users because ZIP files are natively supported by both Windows and macOS. People can double click on them like a directory and then double click again on the CSV to open it up in Excel.

@pekkavaa
pekkavaa / dod.md
Created September 13, 2020 22:24
Data-Oriented Design Book Review

Data-Oriented Design Book Review

Pekka Väänänen, Sep 14 2020

59b4f66b3c27439a8dd629ade17d65f8

Data-Oriented Design (2018) by Richard Fabian

Computers keep getting faster but the future ain't what it used to be. Instead of higher clock rates we get deeper pipelines, higher latencies, more cores. Programming these systems requires paying attention to how we structure and access our data. In Data-Oriented Design Richard Fabian—who has worked at Frontier Developments, Rockstar Games, and Team17—presents us an approach to reason about these issues from a C++ game developer's perspective.

Data-oriented design is about caches and decoupling meaning from data. The former implies laying out your data so that they're compact and predictably accessed. The latter means exposing the raw transforms from one sequence of bits to another. For example, finding the pla

@pekkavaa
pekkavaa / fpaq0.py
Last active April 19, 2020 18:39
An arithmetic coder
"""
A pretty terrible arithmetic coder with a 0th order model.
Based on Matt Mahoney's fpaq0 implementation available at
http://mattmahoney.net/dc/#fpaq0
"""
import sys
@pekkavaa
pekkavaa / pytorchraster.py
Last active March 15, 2022 14:31
A dumb triangle rasterizer with PyTorch.
import numpy as np
import matplotlib.pyplot as plt
from numpy import array
import torch
from torch import Tensor
"""
A dumb triangle rasterizer with PyTorch.
It evaluates the barycentrics for all image pixels for each triangle
and then picks the "colors" (just barycentrics again) for each pixel
@pekkavaa
pekkavaa / triangle.py
Last active March 15, 2022 14:31
NumPy triangle rasterizer
import numpy as np
import matplotlib.pyplot as plt
from numpy import array
width = 100
height = 80
# The triangle
d = np.array([ [ [0.9, 0.5], [0.5, 0.8], [0.1, 0.15] ] ])
@pekkavaa
pekkavaa / tweak_values.inc
Created March 18, 2018 14:37
C++ tweak variable example.
// This file is automatically generated, but you can add your own variables here too.
// Syntax: SET_VAR(variable_name, default, low_limit, upper_limit, slider_exponent)
// In code you can read the variable with: GET_VAR(variable_name)
SET_VAR(tower_height, 520.0f, 0.0f, 3000.0f, 1.0f)
SET_VAR(KSpring, 520.0f, 1.0f, 3000.0f, 1.0f)
SET_VAR(WireRadius, 2.0f, 0.1f, 34.0f, 1.0f)
SET_VAR(volcanic_sun_x, 0.088000, -20.0f, 20.0f, 1.0f)
SET_VAR(mothership_sun_x, 2.026000, -5.0f, 5.0f, 1.0f)
SET_VAR(mothership_sun_y, 0.507000, -5.0f, 5.0f, 1.0f)
SET_VAR(wire_fog_exp, 0.0f, 0.0f, 100.0f, 1.0f)
@pekkavaa
pekkavaa / ebin
Created June 3, 2016 15:20
A terrible binary number printer
#!/usr/bin/python
import sys
from ast import literal_eval
if len(sys.argv) != 2:
print "Usage: ebin INTEGER"
sys.exit(1)
s = "{0:08b}".format(literal_eval(sys.argv[1]))
n = 4 # split into 4 bit blocks
# awful reversing hack to get proper formatting
s = s[::-1]
@pekkavaa
pekkavaa / LAAMATUT.TXT
Created May 26, 2016 18:40
Laaman tie DJGPP-peliohjelmointiin versio 2.10. By Jokke / BAD KARMA
▄▄▄▄▄ ▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄
█▓▒░ ░█ █▓▒░ ░▒▓▒█ █▒░ ░▒▓▒░ █ █░ ░▒▓▒░█ █▓▒░ ░▒▓█ █ ░▒▓▒░ ░▒█
█▒░ ░▒█ █▒░ ░▒▓▒░█ █░ ░▒▓▒░ ░█ █ ░▒▓▒░ █ █▒░ ░▒▓▒█ █░▒▓▒░ ░▒▓█
█░ ░▒▓█ █▒░ ░▒▓▒░ ░█ █░ ░▒▓▒░ ░▒▓█ █░▒▓▒░ ░▒█▒░ ░▒▓▒░█ █▒▓▒░ ░▒▓▒█
█ ░▒▓▒█ █░ ░▒▓▒░ ░▒█ █ ░▒▓▒░ ░▒▓▒█ █▒▓▒░ ░▒▓▒░ ░▒▓▒░ █ █▒▓▒░ ░▒▓▒░ █
█░▒▓▒░█ █ ░▒▓██ ░▒▓█ █░▒▓▒░██▒▓▒░█ █▓▒░ ░▒▓▒░ ░▒▓▒░ ░█ █▓▒░ ░██▒░ ░█
█▒▓▒░ █ █░▒▓▒██░▒▓▒█ █▒▓▒░ ██▓▒░ ░██▒░ ░▒█▒░ ░▒█▒░ ░▒█ █▒░ ░▒██░ ░▒█
█▓▒░ ░█ █░▒▓▒░██▒▓▒░ █▒▓▒░ ░██▒░ ░▒██░ ░▒▓█░ ░▒▓█░ ░▒▓█ █░ ░▒▓██ ░▒▓█
█▒░ ░▒█▄▄▄█▒▓▒░ ░▒▓▒░ ░█▓▒░ ░▒▓▒░ ░▒▓██ ░▒▓▒█ ░▒▓▒█ ░▒▓▒██░ ░▒▓▒░ ░▒▓▒░█
█░ ░▒▓▒░ ░▒▓▒░ ░▒▓▒░ ░▒▓▒░ ░▒▓▒░ ░▒▓▒░ ░▒▓▒░██▒▓▒██░▒▓▒░██ ░▒▓▒░ ░▒▓▒░ █
@pekkavaa
pekkavaa / ttrack.py
Created May 10, 2016 20:42
A "timetracker" "application"
import readline
import datetime
logpath = "times.txt"
lines = []
try:
with open(logpath, "r") as f:
lines = f.readlines()
except: