Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_fractalic_coast_lines.py
- from Tkinter import *
- import random
- from PIL import Image, ImageTk
- root = Tk()
- root.title("Tk fractalic coast lines")
- xm, ym = 720, 720
- canvas = Canvas(root, width=xm, height=ym)
- canvas.grid()
- from PIL import Image, ImageDraw
- import random, math
- pad = 20
- rnd = random.Random()
- iterations = 12
- x, y = 720, 720
- r = min(x,y)/2 * 0.82 # initial shape radius is 82% of image radius
- while 1:
- for gon in [2,3,4]:
- points = [(x/2+r*math.cos(2.*math.pi*i/gon),y/2+r*math.sin(2.*math.pi*i/gon)) for i in range(gon)]
- for i in range(3):
- canvas.delete('all')
- lines = [(points[i],points[(i+1)%gon]) for i in range(gon)]
- for i in range(iterations):
- newLines = []
- for l in lines:
- s = l[0]
- e = l[1]
- d = 0.32 * ((s[0]-e[0])**2 + (s[1]-e[1])**2)**0.5
- alpha = rnd.random() * 2 * math.pi
- mx = (s[0]+e[0])/2 + d * math.cos(alpha)
- my = (s[1]+e[1])/2 + d * math.sin(alpha)
- m = (mx, my)
- newLines += [(s,m),(m,e)]
- lines = newLines
- '''
- for l in lines:
- canvas.create_line((l[0], l[1]), fill='blue')
- '''
- img = Image.new("L", (x,y), 255)
- canvas.create_polygon([l[0] for l in lines], fill='green')
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement