Skip to content

Instantly share code, notes, and snippets.

View antiface's full-sized avatar

A.G. antiface

View GitHub Profile
@antiface
antiface / image_matrix.py
Created August 6, 2016 14:06 — forked from vgmoose/image_matrix.py
Creates a C array from a bitmap file
import json
import sys
import os
print ".--=============--------------=============--."
print "| Welcome to Image Matrix Maker! |"
print ".--=============--------------=============--."
yeswords = ["yes", "y", "ya", "ok", "okay"]
@antiface
antiface / gist:3356980defe35d4faf907989ad9e2cc2
Created August 6, 2016 14:05 — forked from vgmoose/bitmap.py
number of islands in a bitmap
bitmap = [[0,0,1,1,0,0,0,1,0,0],[0,1,1,0,0,1,1,1,0,0],[0,1,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,0,0,1,1],[0,0,0,0,1,1,1,1,1,0],[0,1,1,0,0,0,0,0,0,0]]
height = len(bitmap)
width = len(bitmap[0])
visited = [[0]*width for x in range(0, height)]
count = 0
def visitAll(x, y):
@antiface
antiface / bitmap.py
Created August 6, 2016 14:05 — forked from mharriger/bitmap.py
Python fast monochrome bitmap ideas
from bitarray import bitarray
class Bitmap:
def __init__(self, width, height, major_axis = 'x'):
self._width = width
self._height = height
self._data = (width * height) * bitarray('0')
self._major_axis = major_axis
def _get_rows(self):
@antiface
antiface / gradient.py
Created August 6, 2016 14:04 — forked from adusak/gradient.py
Gradient - generates gradient
from PIL import Image
def generate_gradient():
im = Image.new("RGB", (255, 255))
for x in range(255):
for y in range(255):
im.putpixel((x, y), (x, 0, y))
im.save("../../portfolio/less1/gradient.png")
im.show()
@antiface
antiface / gradient.py
Created August 6, 2016 14:04 — forked from adusak/gradient.py
Gradient - generates gradient
from PIL import Image
def generate_gradient():
im = Image.new("RGB", (255, 255))
for x in range(255):
for y in range(255):
im.putpixel((x, y), (x, 0, y))
im.show()
@antiface
antiface / combinatorics.py
Created August 6, 2016 14:04 — forked from adusak/combinatorics.py
Combinatorics - permutations, variations, combinations
from enum import Enum
class OpType(Enum):
permutation = 1
variation = 4
variation_repetition = 2
combination = 5
combination_repetition = 3
@antiface
antiface / generate_points.py
Created August 6, 2016 14:04 — forked from adusak/generate_points.py
Generates points within specified bounds
import random
def generate_points(n, canvas_size, gauss=False):
points = []
for i in range(n):
if gauss:
x = -1
y = -1
while not (point_in_bounds((x, y,), canvas_size)):
@antiface
antiface / line_intersections.py
Created August 6, 2016 14:04 — forked from adusak/line_intersections.py
Code to generate number of same length lines and find their intersections
from math import radians, cos, sin
import random
from python.common.svg import Svg
from python.less5.generate_points import generate_points, point_in_bounds
from python.common import line as ln
def generate_lines(n, length, canvas_size, gauss=False):
lines = []
@antiface
antiface / triangulation.py
Created August 6, 2016 14:04 — forked from adusak/triangulation.py
Triangluation
import random
from python.common import line as ln
from python.common.svg import Svg
from python.less5.generate_points import generate_points
def triangulate(number_of_points, canvas_size, sort=True, name="triangulation", gauss=False):
svg = Svg()
points = generate_points(number_of_points, canvas_size, gauss)
@antiface
antiface / line.py
Created August 6, 2016 14:04 — forked from adusak/line.py
Class representing a line with some helper functions for operations with lines
import math
class Line:
def __init__(self, x1, y1, x2, y2, draw=True):
self.x1 = x1
self.x2 = x2
self.y1 = y1
self.y2 = y2
self.draw = draw