0 Replies - 206 Views - Last Post: 14 October 2013 - 11:39 AM Rate Topic: -----

#1 cheesecakefan741  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-October 12

Drawing A Petal with Turtle Graphics

Posted 14 October 2013 - 11:39 AM

I am having trouble trying to reconnecting the arcs to create a petal.

# Load TurtleWorld functions
from swampy.TurtleWorld import *
import math

# TODO: Arc function
def draw_arc(t,r,theta,seg_len):
    pd(t)
    arc_len=(2*math.pi*r)*(theta/360.0)
    num_seg=int(arc_len/seg_len)
    dang=theta/num_seg
    for i in range (num_seg):
        fd(t,seg_len)
        rt(t,dang)
    
# TODO: Petal function
def draw_petal(t,r,theta,seg_len):
    
    draw_arc(t,r,theta,seg_len)
    rt(t,190-theta)
    draw_arc(t,r,theta,seg_len)
    rt(t,190-theta)
    
# TODO: Flower function
#def draw_flower(t,num_petals):
 #for i in range(num_petals):
     # draw_petal(t,r,theta,seg_len)
     # rt(t,n)

      
# Main program function
def main():
    # TurtleWorld objects
    world = TurtleWorld()
    turtle = Turtle()
    turtle.delay = 0.01
    
    # Flower variables
    num_petals= int(raw_input('Enter the number of petals '))
    
    # Draw graphics
    draw_petal(turtle, 100, 90, 4)
    #draw_flower(turtle,num_petals)
                
    # Press enter to exit
    key = raw_input('Press enter to exit')
    world.destroy()

#Call main program
main()



Is This A Good Question/Topic? 0
  • +

Page 1 of 1