Skip to content

Instantly share code, notes, and snippets.

View fogleman's full-sized avatar

Michael Fogleman fogleman

View GitHub Profile
@fogleman
fogleman / allrgb.py
Last active August 29, 2015 13:57
AllRGB Generator
from itertools import izip, product
import wx
BITS = 6
SIZE = int(((2 ** BITS) ** 3) ** 0.5)
STEP = 2 ** (8 - BITS)
def color_func(color):
r, g, b = color
r, g, b = 0.30 * r, 0.59 * g, 0.11 * b
@fogleman
fogleman / main.py
Last active August 29, 2015 13:57
wxPython Bitmap Viewer
import wx
class View(wx.Panel):
def __init__(self, parent):
super(View, self).__init__(parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.EVT_PAINT, self.on_paint)
self.Bind(wx.EVT_CHAR_HOOK, self.on_char)
self.bitmap = None
@fogleman
fogleman / allrgb.py
Last active August 29, 2015 13:57
4096x4096 AllRGB using Octree
import random
import wx
SIZE = 4096
LOOKUP = [
[0, 1, 4, 5, 2, 3, 6, 7],
[1, 0, 5, 4, 3, 2, 7, 6],
[2, 3, 6, 7, 0, 1, 4, 5],
[3, 2, 7, 6, 1, 0, 5, 4],
@fogleman
fogleman / lindenmayer.py
Last active August 29, 2015 14:02
L-system
from math import sin, cos, radians
import cairo
import random
import re
class System(object):
def __init__(self, rules):
self.rules = rules
self.pattern = re.compile('|'.join('(%s)' % x for x in rules))
def step(self, value):
@fogleman
fogleman / polygons.py
Last active August 29, 2015 14:02
Tiling of Regular Polygons
from math import sin, cos, tan, pi, atan2
import cairo
import random
COLORS = [
0x477984,
0xEEAA4D,
0xC03C44,
0xFEF5EB,
]
@fogleman
fogleman / bot.py
Last active August 29, 2015 14:02
Polygon Tiling G-code
from tile import Model, Shape
def normalize(x, y):
return (round(x + 3.5, 6), round(y + 3.5, 6))
def create_model():
model = Model(width=700, height=700, scale=100)
model.append(Shape(6))
a = model.add(0, range(6), 4)
b = model.add(a, 1, 3)
@fogleman
fogleman / main.py
Last active August 29, 2015 14:02
Electric Fields
from math import hypot, atan2, sin, cos, pi, radians
import cairo
import colorsys
import random
class Model(object):
def __init__(self):
self.particles = []
def add(self, x, y, m=1.0):
self.particles.append((x, y, m))
@fogleman
fogleman / main.py
Last active August 29, 2015 14:03
Poisson Disc
from math import pi, sin, cos, hypot, floor
import cairocffi as cairo
import random
R = 0.012
class Grid(object):
def __init__(self, r):
self.r = r
self.size = r / 2 ** 0.5
@fogleman
fogleman / main.py
Last active August 29, 2015 14:03
Poisson Disc + Voronoi
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.02
FILL = 0x422B36
@fogleman
fogleman / split.py
Last active August 29, 2015 14:04
Python Split Function
def split(values, func):
group = []
previous = None
for value in values:
if previous and func(previous, value):
yield group
group = []
group.append(value)
previous = value
if group: