Skip to content

Instantly share code, notes, and snippets.

View fogleman's full-sized avatar

Michael Fogleman fogleman

View GitHub Profile
@fogleman
fogleman / ospTutorial.cpp
Created August 17, 2016 16:34
OSPRay Sphere Smooth Shading
#include <stdio.h>
#ifdef _WIN32
# include <malloc.h>
#else
# include <alloca.h>
#endif
#include "ospray/ospray.h"
// helper function to write the rendered image as PPM file
void writePPM(const char *path, const osp::vec2i &size, const uint32_t *pixel) {
@fogleman
fogleman / slice.go
Created July 20, 2016 16:10
Slices
package main
import (
"fmt"
"github.com/fogleman/ln/ln"
)
const Slices = 10
const Size = 1024
@fogleman
fogleman / voronoi.py
Created May 24, 2016 13:50
Voronoi / Poisson
from math import pi, sin, cos, hypot, floor
from pyhull.voronoi import VoronoiTess
from shapely.geometry import Polygon
import cairocffi as cairo
import colorsys
import random
R = 0.05
FILL = 0x422B36
@fogleman
fogleman / sunburst.py
Last active May 24, 2016 13:48
Sunburst
from collections import Counter
from math import pi
import cairo
COLORS = {
'a': (0, 0, 180),
'b': (175, 13, 102),
'c': (146, 248, 70),
'd': (255, 200, 47),
'e': (255, 118, 0),
@fogleman
fogleman / wiggle.py
Created May 24, 2016 13:47
Wigglegrams
from PIL import Image, ImageChops, ImageDraw
import os
def load_images(folder):
result = []
for name in os.listdir(folder):
path = os.path.join(folder, name)
print path
im = Image.open(path)
result.append(im)
@fogleman
fogleman / elevation.py
Created May 5, 2016 22:07
elevation.py
import pg
class Window(pg.Window):
def setup(self):
self.set_clear_color(0.87, 0.81, 0.70)
self.wasd = pg.WASD(self, speed=0.3)
self.wasd.look_at((0, 0, 0), (30, -5, 30))
self.context = pg.Context(pg.DirectionalLightProgram())
self.context.specular_multiplier = 0.25
self.context.ambient_color = (0.5, 0.5, 0.5)
@fogleman
fogleman / terrain.go
Created May 5, 2016 17:34
terrain.go
package main
import (
"image"
"image/png"
"net/http"
. "github.com/fogleman/pt/pt"
)
@fogleman
fogleman / sgf.py
Created March 21, 2016 01:46
SGF Parser & Board State for Go / Baduk
import sys
class Board(object):
def __init__(self, size):
self.size = size
self.grid = {}
def move(self, color, x, y):
self.set(color, x, y)
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx = x + dx
@fogleman
fogleman / permutations.py
Created March 19, 2016 22:02
Permutations of Rides & Vehicles
import itertools
import math
# https://www.wolframalpha.com/input/?i=1,6,90,2520,113400
# a(n) = (2n)! / 2^n
# https://oeis.org/A000680
def f(n):
return math.factorial(2 * n) / (2 ** n)
def brute():
@fogleman
fogleman / text.go
Created February 24, 2016 02:56
Meme-style Text
package main
import "github.com/fogleman/gg"
func main() {
const S = 1024
dc := gg.NewContext(S, S)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.LoadFontFace("/Library/Fonts/Impact.ttf", 96)