-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern
98 lines (82 loc) · 2.45 KB
/
pattern
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
import turtle
import random
def reset():
turtle.reset()
turtle.speed(0)
def setup():
turtle.speed(0)
turtle.screensize(1000, 800)
def drawRectanglePattern(centerX, centerY, offset, width, height, count, rotation):
recNumber = 0
turtle.pu()
turtle.goto(centerX, centerY)
while recNumber < count:
setRandomColor()
turtle.lt(rotation)
turtle.fd(offset)
turtle.pd()
drawRectangle(width, height)
turtle.pu()
turtle.bk(offset)
recNumber += 1
def drawRectangle(width, height):
turtle.fd(width)
turtle.rt(90)
turtle.fd(height)
turtle.rt(90)
turtle.fd(width)
turtle.rt(90)
turtle.fd(height)
turtle.rt(90)
def drawCirclePattern(centerX, centerY, offset, radius, count):
circNumber = 0
turtle.pu()
turtle.goto(centerX, centerY)
while circNumber < count:
setRandomColor()
turtle.pu()
turtle.fd(offset + radius)
turtle.pd()
turtle.circle(radius)
turtle.pu()
turtle.bk(offset + radius)
turtle.lt(360 / count)
circNumber += 1
def drawSuperPattern(num):
superCount = 0
while superCount < num:
patternNumber = random.randint(0, 2)
if patternNumber is 0:
centerX = random.randint(-500, 500)
centerY = random.randint(-400, 400)
offset = random.randint(-20, 50)
radius = random.randint(40, 80)
count = random.randint(10, 60)
drawCirclePattern(centerX, centerY, offset, radius, count)
superCount += 1
if patternNumber is 1:
centerX = random.randint(-500, 500)
centerY = random.randint(-400, 400)
offset = random.randint(-20, 50)
height = random.randint(40, 150)
width = random.randint(20, 100)
count = random.randint(10, 100)
rotation = random.randint(4, 40)
drawRectanglePattern(centerX, centerY, offset, width, height, count, rotation)
superCount += 1
def setRandomColor():
randomColor = random.randint(0, 6)
if randomColor is 0:
turtle.color("red")
if randomColor is 1:
turtle.color("orange")
if randomColor is 2:
turtle.color("yellow")
if randomColor is 3:
turtle.color("green")
if randomColor is 4:
turtle.color("blue")
if randomColor is 5:
turtle.color("purple")
def done():
turtle.done()