-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathringOfShapes.py
59 lines (49 loc) · 1.64 KB
/
ringOfShapes.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
# make a function that draws a simple triangle
def drawTriangleFromCenter(theShapeSize):
# a triangle is a three point polygon
polygon(
(-theShapeSize/2, 0), # the lower left point is half the shape width to the left
(theShapeSize/2, 0), # the lower right point is half the shape width to the right
(0, theShapeSize), # the top point is the full shape width up
)
# make a function that draws a ring of shapes
def drawRing(theShapeCount=10, theShapeSize=100, theOffset=10):
with savedState():
for theShape in range(theShapeCount):
with savedState():
translate(0, theOffset)
drawTriangleFromCenter(theShapeSize)
rotate(360/theShapeCount)
####
####
####
# set some variables
# the radius of the ring
myOffset = 10
myShapeCount = 6
myShapeSize = 5
myRingCount = 50
# set some variable for our document
# now let's draw our document
newPage()
# draw a background
fill(1)
rect(0, 0, width(), height())
# move to the center of the document
translate(width()/2, height()/2)
# add a shadow to all shapes
shadow((-2, 2), 5, (0, 0, 0, .1))
# loop through the number of rings we want to draw
for myRing in range(myRingCount):
# make each ring a different color
fill(random(), random(), random())
# draw our ring of shapes
drawRing(myShapeCount, myShapeSize, myOffset)
# now augment our variables so the next ring will be drawn differently
# with more shapes
myShapeCount += 3
# with a slightly bigger size
myShapeSize += 2
# make the offset bigger so each ring is drawn larger
myOffset += myShapeSize
saveImage('ringOfShapes.png')