Nested Loops

Since stating this I keep finding ways to make the program better.  It’s getting rather addictive.

Note I have NOT included the notes at the top of the code,  there isn’t really any need to.

Ok this now asks for number of sides to the shape

works out how to draw the shape

draws the shape 72 times turning 5 degrees each time

allows user to save the final shape

turtle-loop4.py

import turtle
import time
 
set file name
fname= raw_input("Filename (must include .eps ")
#fname="dial.eps"
 
sides = raw_input("number of sides to shape ")
sides = int(sides)
shapeangle = 360 / sides
 
for x in range(0,72):
	turtle.left(5)
	for n in range(0,sides):
		turtle.forward(150)
		turtle.left(shapeangle) 
time.sleep(1)
 
ts = turtle.getscreen()
ts.getcanvas().postscript(file=fname)
 
print "Saved image to: ", fname
print "All done. Click image to exit."
 
turtle.exitonclick()

the following stack overflow page provided me with some of the above code

http://stackoverflow.com/questions/19919237/python-turtle-setup-truncates-canvas-to-screen-size-how-to-avoid-that

 

import turtle
import time
 
#set file name
fname="dial.eps"
 
for x in range(0,72):
	turtle.left(5)
	for n in range(0,5):
		turtle.forward(150)
		turtle.left(90) 
time.sleep(1)
 
ts = turtle.getscreen()
ts.getcanvas().postscript(file=fname)
 
print "Saved image to: ", fname
print "All done. Click image to exit."
 
turtle.exitonclick()

turtle-loop3.py

 

Original version

import turtle
import time
 
for x in range(0,72):
	turtle.left(5)
	for n in range(0,5):
		turtle.forward(150)
		turtle.left(90) 
time.sleep(60)

turtle-loop2.py

For completeness

import turtle
import time
 
for n in range(0, 4):
	turtle.forward(50)
	turtle.left(90) 
time.sleep(5)

turtle-loop.py

Just draws a square