-
Notifications
You must be signed in to change notification settings - Fork 3
/
Art.py
131 lines (119 loc) · 3.15 KB
/
Art.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File: Art.py
# Description: Uses recursive code to draw fractal art
# Student Name: Braeden Conrad
# Student UT EID: bsc875
# Course Name: CS 313E
# Unique Number: 51335
# Date Created: 02/28/18
# Date Last Modified: 02/28/18
import turtle
import math
# code for drawing a cross, includes a scale factor
def drawCross(ttl,scale):
ttl.forward(10*scale)
ttl.left(90)
ttl.forward(40*scale)
ttl.right(90)
ttl.forward(20*scale)
ttl.left(90)
ttl.forward(10*scale)
ttl.left(90)
ttl.forward(20*scale)
ttl.right(90)
ttl.forward(20*scale)
ttl.left(90)
ttl.forward(10*scale)
ttl.left(90)
ttl.forward(20*scale)
ttl.right(90)
ttl.forward(20*scale)
ttl.left(90)
ttl.forward(10*scale)
ttl.left(90)
ttl.forward(20*scale)
ttl.right(90)
ttl.forward(40*scale)
ttl.left(90)
# draws the main branch that goes straight up
def drawMainBranch(ttl,order,x=0,y=0,scale=1.0):
# call function until order decreases to zero
if (order > 0):
ttl.penup()
ttl.goto(x,y)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.setheading(0)
#increment y value by the height of the cross
y += 70*scale
#recursively call with the scale and order decreasing
drawMainBranch(ttl,order-1,x,y,scale-.1)
def drawbranch2(ttl,order,x=10,y=0,scale=1.0):
if (order > 0):
ttl.penup()
ttl.right(120)
# increment the x and y values using geometry plus slight adjustments
x += 45*math.sqrt(2)*scale
y -= 35*scale
ttl.goto(x,y)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.setheading(0)
drawbranch2(ttl,order-1,x,y,scale-.1)
def drawbranch3(ttl,order,x=5,y=-10*math.sqrt(2),scale=1.0):
if (order>0):
ttl.penup()
ttl.left(120)
# decrement x and y using geometry and adjustments
x -= 45*math.sqrt(2)*scale
y -= 35*scale
ttl.goto(x,y)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.penup()
ttl.forward(10*scale)
ttl.right(120)
ttl.pendown()
drawCross(ttl,scale)
ttl.setheading(0)
drawbranch3(ttl,order-1,x,y,scale-.1)
def main():
order = int(input("Enter the order(1-6): "))
while (order<1 and order>6):
order = int(input("Enter the order (1-6): "))
turtle.title("Triangular Crosses")
turtle.setup(800,800,0,0)
turtle.speed(0)
ttl = turtle.Turtle()
ttl.color('green')
drawMainBranch(ttl,order)
ttl.color('red')
drawbranch2(ttl,order)
ttl.color('blue')
drawbranch3(ttl,order)
turtle.done()
main()