-
Notifications
You must be signed in to change notification settings - Fork 0
/
Isogrammen.py
57 lines (51 loc) · 1.54 KB
/
Isogrammen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# https://dodona.ugent.be/nl/courses/453/series/4870/activities/1872809777
import pygame, cmath, sys
pygame.init()
def display(width=800,height=600,fullscreen=False,colour=(0,0,0)):
size = width, height
if fullscreen:
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Tikolu Fractal Display")
screen.fill(colour)
pygame.display.update()
return(screen)
def generate(screen,iterations=15,power=2,hue=(2,2,2),darkmode=False,updatemode=1):
width, height = screen.get_size()
w2 = width / 2
h2 = height / 2
w4 = width / 4
h4 = height / 4
y = 0
while y < height:
x = -1
while x < width:
x += 1
offset = complex((x - w2)/ w4, (y - h2) / h4)
cpoint = complex(0, 0) + offset
i = 0
while i < iterations:
try:
cpoint = (cpoint ** power) + offset
except ZeroDivisionError:
cpoint = ((cpoint+1) ** power) + offset
if abs(cpoint.real) > 2 or abs(cpoint.imag) > 2:
break
i += 1
i = 255 * (i / iterations)
if darkmode == False:
i = abs(i-255)
colour = i/hue[0],i/hue[1],i/hue[2]
point = round((offset.real * w4) + w2), round((offset.imag * h4) + h2)
screen.set_at(point, colour)
if updatemode != 0:
if y % updatemode == 0:
pygame.display.update()
pygame.display.set_caption("Generating Fractal... " + str(round((y/height)*100)) + "%")
# for event in pygame.event.get():
# if event.type == pygame.MOUSEBUTTONDOWN:
# sys.exit()
y += 1
pygame.display.update()
generate(display(900, 900, False, (0,0,0)))