Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from __future__ import division
- from PIL import Image
- from PIL import ImageDraw
- from random import randint
- from random import uniform
- import time
- import math
- tid_start = float(time.time())
- #
- #
- # hey man, do your config up here
- # for all of these, larger = longer generation time
- # i'm @cat_abyss by the way nice to meet you
- #
- #
- size = 500 # size of the image, will be a square, so 500x500
- n_closest = randint(1,10) # draw lines to the N closest points of the same color
- TAU = 2.0 * math.pi # just a constant, whoops
- gray_steps = randint(1,6) # how many different shades of gray we want
- max_distance = 20 # max distance from a point to search for neighbours
- #
- # OK BEGIN THE SHIT
- #
- canvas = [[0.0 for x in range(size)] for x in range(size)]
- print "n_closest: " + str(n_closest)
- print "gray_steps: " + str(gray_steps)
- #
- # FUNKTIONER
- #
- def applymap(x, y, master, gray_steps):
- mmap = [ [1, 13, 4, 14], [9, 5, 12, 8], [3, 14, 2, 14], [11, 7, 10, 6] ] # dithering map
- temp = mmap[x%4][y%4]/16
- a = master+(temp*master)
- a = round(a*gray_steps)/gray_steps
- return a
- #
- # DEL ETT - ARKADER
- #
- print "GENERERAR ARKADER"
- var_a = randint(0,600)-300;
- var_b = randint(0,3000)-1500;
- var_c = randint(0,600)-300;
- var_d = randint(0,3000)-1050;
- var_e = round(randint(0,1000)-500);
- var_f = round(randint(0,1000)-500);
- for y in range(0,size):
- for x in range(0,size):
- x_new = x + var_e;
- y_new = y + var_f;
- if math.tan( (x_new+var_a)/var_b+(y_new/var_a) ) * math.tan( (y_new/(var_a*var_b)) + (x_new*2)) > uniform(0,1):
- if math.tan( (y_new/var_d)*x_new ) > 0:
- kek = math.tan(y_new/(var_a*var_b)) + (x_new*2)
- canvas[y][x] = 1.0-kek
- else:
- kek = math.cos((y_new/(var_a*var_b))*(x_new/2))
- canvas[y][x] = 1.0-kek
- #
- # DEL ETT KOMMA FEM: CLIPPING?
- #
- for y in range(0,size):
- for x in range(0,size):
- if canvas[y][x] > 1: canvas[y][x] = 1.0
- if canvas[y][x] < 0: canvas[y][x] = 0.0
- #
- # DEL TVÅ: CIRKEL RUNT ALLT
- #
- print "GENERERAR RAM"
- for y in range(0,size):
- for x in range(0,size):
- kek = 1.0 - ((math.cos(x*(TAU/size))+1)/2) # x-axeln
- kek = kek*(1.0-((math.cos(y*(TAU/size))+1)/2))
- if kek > 1: kek = 1.0
- if kek < 0: kek = 0.0
- canvas[y][x] = kek * canvas[y][x]
- for y in range(0,size):
- for x in range(0,size):
- if canvas[y][x] > 1: canvas[y][x] = 1
- if canvas[y][x] < 0: canvas[y][x] = 0
- #
- # DEL TRE: LINJER OCH DET
- #
- print "FLYTTAR CANVAS TILL GOLFPUTT"
- golfputt = Image.new("RGB", (size,size), 1)
- for y in range(0,size):
- for x in range(0,size):
- useme = applymap(x%size,y,canvas[y][x],gray_steps)
- colour = 255-int(255*useme)
- golfputt.putpixel((x,y), (colour,colour,colour))
- draw = ImageDraw.Draw(golfputt)
- print "GENERERAR LINJER ETC"
- for cykler in range(1,gray_steps+1):
- print "> lager " + str(cykler)
- passad_cykler = cykler/gray_steps
- how_many_points = 0
- for y in range(0,size):
- for x in range(0,size):
- useme = applymap(x%size,y,canvas[y][x],gray_steps)
- if useme == passad_cykler:
- how_many_points = how_many_points + 1
- print " > DET BLIR " + str(how_many_points) + " PUNKTER"
- point = 0
- points = [[0 for x in range(3)] for x in range(how_many_points)] # 0 = x, 1 = y, 2 = distance
- for y in range(0,size):
- for x in range(0,size):
- useme = applymap(x%size,y,canvas[y][x],gray_steps)
- if useme == passad_cykler:
- points[point][0] = x;
- points[point][1] = y;
- point = point + 1
- print " > HITTAR PROXIMITY POINTS"
- painting_color = int((1.0-passad_cykler)*255)
- painting_color = (painting_color,painting_color,painting_color)
- linje_start = float(time.time())
- tid_math = 0
- tid_mathx = 0
- tid_draw = 0
- for master in range(0, how_many_points):
- if master%1000 == 0:
- print str(round((master/how_many_points)*100)) + "% - " + str(master) + " of " + str(how_many_points)
- print " > DISTANCE: " + str(tid_math) + " SORT: " + str(tid_mathx) + " DRAW: " + str(tid_draw)
- tid_math_2 = float(time.time())
- newlist = []
- for slave in range(0, how_many_points):
- kek_x = abs(points[master][0] - points[slave][0])
- kek_y = abs(points[master][1] - points[slave][1])
- if kek_x < max_distance and kek_y < max_distance:
- points[slave][2] = math.sqrt((kek_x**2)+(kek_y**2))
- newlist.append(points[slave])
- tid_math = tid_math + float(time.time()) - tid_math_2
- tid_math_2 = float(time.time())
- newlist.sort(key=lambda x: x[2])
- tid_mathx = tid_mathx + float(time.time()) - tid_math_2
- tid_math_2 = float(time.time())
- for i in range(1,(n_closest+1)%len(newlist)):
- draw.line((points[master][0],points[master][1], newlist[i][0],newlist[i][1]), fill = painting_color)
- tid_draw = tid_draw + float(time.time()) - tid_math_2
- #
- # DEL SIST: GÖR EN BILD
- #
- print "SAVING"
- golfputt.save("output.png")
Advertisement
Add Comment
Please, Sign In to add comment