Skip to content

Commit 53e361a

Browse files
author
Jakub Klinkovský
committed
new: animation
1 parent 6b6ff9d commit 53e361a

5 files changed

Lines changed: 82 additions & 21 deletions

File tree

animation.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
import builtins
4+
import turtle as t
5+
import time
6+
import math
7+
8+
import fractals._lib as _lib
9+
from fractals import *
10+
11+
builtins.position = (-300, -250)
12+
13+
_lib.init()
14+
15+
for i in range(7):
16+
t.clear()
17+
t.penup()
18+
t.setpos(position)
19+
t.setheading(heading)
20+
t.pendown()
21+
22+
arrowhead_curve(i, size)
23+
# caesaro(i, size)
24+
# dragon_curve(i, size)
25+
# h_tree(i, size, angle=90, par=1/math.sqrt(2))
26+
# h_tree(i, size, angle=85, par=0.69)
27+
# h_tree(i, size, angle=45, par=1/math.sqrt(2))
28+
# stochastic(i, size, angle=45, par=1/math.sqrt(2), factor=0.3)
29+
# koch_antisnowflake(i, size)
30+
# koch_curve(i, size)
31+
# koch_snowflake(i, size)
32+
# sierpinski_triangle(i, size)
33+
34+
t.update()
35+
time.sleep(1)
36+
37+
_lib.exit()
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ def h_tree(iteration, size, angle=90, par=1/math.sqrt(2)):
2323
t.left(angle)
2424
t.backward(size)
2525

26-
_lib.init()
26+
if __name__ == "__main__":
27+
_lib.init()
2728

28-
## classic H-tree
29-
h_tree(iteration, size, angle=90, par=1/math.sqrt(2))
29+
## classic H-tree
30+
h_tree(iteration, size, angle=90, par=1/math.sqrt(2))
3031

31-
## different angle
32-
#h_tree(iteration, size, angle=85, par=0.69)
32+
## different angle
33+
# h_tree(iteration, size, angle=85, par=0.69)
3334

34-
## Pythagoras tree
35-
#builtins.size = 200
36-
#h_tree(iteration, size, angle=45, par=1/math.sqrt(2))
35+
## Pythagoras tree
36+
# builtins.size = 200
37+
# h_tree(iteration, size, angle=45, par=1/math.sqrt(2))
3738

38-
_lib.exit()
39+
_lib.exit()
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def stochastic(iteration, size, angle, par, factor=0.3):
2626
t.left(angle2)
2727
t.backward(size2)
2828

29-
_lib.init()
30-
stochastic(iteration, size, angle=45, par=1/math.sqrt(2), factor=0.3)
31-
_lib.exit()
29+
if __name__ == "__main__":
30+
_lib.init()
31+
stochastic(iteration, size, angle=45, par=1/math.sqrt(2), factor=0.3)
32+
_lib.exit()

fractals/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
6+
# hack - enable importing from _this_ directory
7+
sys.path.append(os.path.dirname(__file__))
8+
9+
from arrowhead_curve import *
10+
from caesaro_fractal import *
11+
from dragon_curve import *
12+
from dragon_curve_tiling import *
13+
from H_tree import *
14+
from H_tree_stochastic import *
15+
from koch_antisnowflake import *
16+
from koch_curve import *
17+
from koch_snowflake import *
18+
from sierpinski_triangle import *

fractals/dragon_curve_tiling.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
def changeColor():
1616
t.pencolor(colors.pop())
1717

18-
_lib.init()
19-
for heading in [0, 90, 180, 270]:
20-
t.penup()
21-
t.home()
22-
t.setheading(heading)
23-
changeColor()
24-
t.pendown()
25-
dragon_curve(iteration, size, swap=True)
26-
_lib.exit()
18+
def dragon_curve_tiling():
19+
for heading in [0, 90, 180, 270]:
20+
t.penup()
21+
t.home()
22+
t.setheading(heading)
23+
changeColor()
24+
t.pendown()
25+
dragon_curve(iteration, size, swap=True)
26+
27+
if __name__ == "__main__":
28+
_lib.init()
29+
dragon_curve_tiling()
30+
_lib.exit()

0 commit comments

Comments
 (0)