Skip to content

Instantly share code, notes, and snippets.

@44100hertz
44100hertz / fastSine.go
Last active January 26, 2017 17:21
16-bit ultrafast approximate sine via lookup table
package fastSine
import "math"
// Generate any sort of 16-bit lookup table.
// fn expected to take in range 0.0-1.0, output full-range int16
func makeLUT(fn func(float64) int16, size int) []int16 {
lut := make([]int16, size)
for i := 0; i < size; i++ {
lut[i] = fn(float64(i) / float64(size))
@44100hertz
44100hertz / waveforms.go
Last active January 27, 2017 00:23
Some tiny waveform functions for a tracker
package waveforms
import "math"
// Generate any sort of 16-bit lookup table.
// fn expected to take in range 0.0-1.0, output full-range int16
func makeLUT(fn func(float64) int16, size int) []int16 {
lut := make([]int16, size)
for i := 0; i < size; i++ {
lut[i] = fn(float64(i) / float64(size))
@44100hertz
44100hertz / dpicalc.cc
Created February 22, 2017 20:11
DPI calculator
#include <cstdio>
#include <cmath>
#include <vector>
int main()
{
const auto sizes = {12.1, 13.3, 14.0};
const auto res_x = {1440.0, 1680.0, 1920.0, 2048.0, 2560.0, 2880.0, 3840.0};
const double aspect = 10.0/16.0;
const double x_multiple = 1.0/(1.0 + aspect*aspect);
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(scroll-bar-mode -1)
@44100hertz
44100hertz / rainbowGL.cpp
Created April 1, 2017 04:19
Basic SDL + OpenGL rainbow example
#include <SDL2/SDL.h>
#include <GL/glu.h>
#include <cmath>
const float OFF_R = 0;
const float OFF_G = M_PI * 0.75;
const float OFF_B = M_PI * 1.5;
// Doesn't work like a normal hue function; uses sine curve
float toHue(float f, float offset)
@44100hertz
44100hertz / fake_composite.glsl
Last active April 4, 2017 23:07
Super basic multipass composite shader
const float game_wid = 512;
const float step = 1.0 / game_wid;
const float step2 = 1.0 / game_wid / 2.0;
#ifdef PASS1
vec4 effect( sampler2D texture, vec2 tc )
{
float xcoord = tc.x / 2;
float blue = mod(xcoord, step) * game_wid;
float amber = mod(xcoord + step2, step) * game_wid;
@44100hertz
44100hertz / palcycle.glsl
Last active April 6, 2017 20:38
Linear-interpolated palette cycling shader
uniform float offset;
const int numcols = 6;
const vec4 col[numcols] = vec4[numcols](
/* vec4( 0/255.0, 0/255.0, 0/255.0, 1), */
/* vec4( 129/255.0, 29/255.0, 30/255.0, 1), */
/* vec4( 253/255.0, 107/255.0, 91/255.0, 1), */
/* vec4( 99/255.0, 191/255.0, 96/255.0, 1), */
/* vec4( 222/255.0, 214/255.0, 162/255.0, 1)); */
vec4(1,0,0,1),
@44100hertz
44100hertz / 1-1.c
Last active April 9, 2017 19:09
C bubble sort exercise
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void swap(int* a, int* b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
@44100hertz
44100hertz / 1-2.c
Created April 10, 2017 19:21
C word search solver exercise
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *wordgrid = "thiswatsoahgfgdt";
const int grid_size = 4;
// List of words
char** wl;
int num_wl;
@44100hertz
44100hertz / main.rs
Created May 15, 2017 05:59
proof-of-concept game state management technique
trait Scene {
fn update(&mut self, &mut Game) -> bool;
fn draw(&self, game: &mut Game) {}
}
struct Game {
value: i32,
}
impl Game {