Skip to content

Instantly share code, notes, and snippets.

@nomelif
Last active December 8, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomelif/3ff87bd1f4eebc72e6e5976ac5859451 to your computer and use it in GitHub Desktop.
Save nomelif/3ff87bd1f4eebc72e6e5976ac5859451 to your computer and use it in GitHub Desktop.
from PIL import Image
import numpy as np
import random
from multiprocessing import Pool
def f(taajuus):
w = (512 * np.sqrt(3))*2
h = (512 + np.sqrt(3)*128)*2
data = np.zeros((h, w, 3)).astype(np.float32)
parallellism = 2048*16
point = np.random.rand(parallellism).reshape((parallellism//2,2))
targets = np.array([[0,0],[1,0],[1.5, 0.5*np.sqrt(3)],[0, np.sqrt(3)], [1, np.sqrt(3)], [-0.5, np.sqrt(3)*0.5]])
maxI = 100#3200*2
for iteration in range(maxI):
print(iteration / maxI)
target = np.array([random.choice(targets) for x in range(parallellism//2)])
point = point + (target - point)*taajuus
coords = 800 * (point + [0.5, 0])
for x in range(parallellism//2):
data[int(coords[x][1]), int(coords[x][0])] = data[int(coords[x][1]), int(coords[x][0])] + 1
return data
if __name__ == '__main__':
for fr in range(1, 256, 2):
p = Pool(8)
lista = list(p.map(f, [fr/256]*8))
result = lista[0]
lista = lista[1:]
for x in lista:
result = result + x
result = result
img = Image.fromarray(np.minimum(result, 255).astype(np.int8), "RGB")
img.save("/home/shadoko/hutkimus/"+str(fr)+".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment