• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. this is my first gist
2. import math
3. import turtle
4.
5. def drawPhyllPattern(turtle, t, petalstart, angle = 137.508, size = 2, cspread = 4 ):
6.     """print a pattern of circles using spiral phyllotactic data"""
7.     # initialize position
8.     # turtle.pen(outline=1, pencolor="black", fillcolor="orange")
9.     turtle.color('black')
10.     turtle.fillcolor("orange")
11.     phi = angle * ( math.pi / 180.0 ) #we convert to radian
12.     xcenter = 0.0
13.     ycenter = 0.0
14.
15.     # for loops iterate in this case from the first value until < 4, so
16.     for n in range (0, t):
17.         r = cspread * math.sqrt(n)
18.         theta = n * phi
19.
20.         x = r * math.cos(theta) + xcenter
21.         y = r * math.sin(theta) + ycenter
22.
23.         # move the turtle to that position and draw
24.         turtle.up()
25.         turtle.setpos(x, y)
26.         turtle.down()
27.         # orient the turtle correctly
29.         if n > petalstart-1:
30.             turtle.color("yellow")
31.             drawPetal(turtle, x, y)
32.         else: turtle.stamp()
33.
34.
35. def drawPetal(turtle, x, y ):
36.     turtle.penup()
37.     turtle.goto(x, y)
38.     turtle.pendown()
39.     turtle.color('black')
40.     turtle.fillcolor('yellow')
41.     turtle.begin_fill()
42.     turtle.right(20)
43.     turtle.forward(70)
44.     turtle.left(40)
45.     turtle.forward(70)
46.     turtle.left(140)
47.     turtle.forward(70)
48.     turtle.left(40)
49.     turtle.forward(70)
50.     turtle.penup()
51.     turtle.end_fill() # this is needed to complete the last petal
52.
53.
54. gfg = turtle.Turtle()
55. gfg.shape("turtle")
56. gfg.speed(0) # make the turtle go as fast as possible
57. drawPhyllPattern(gfg, 200, 160, 137.508 )
58. gfg.penup()
59. gfg.forward(1000)
60. turtle.exitonclick()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?