Functions help

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Feb 24 16:01:38 CET 2014


----- Original Message ----- 

> On Feb 23, 2014, at 1:44 AM, Steven D'Aprano <
> steve+comp.lang.python at pearwood.info > wrote:
> > Sorry, I don't really understand your question. Could you show an
> > example
> 
> > of what you are doing?
> 

> > Do you mean "add 5" or "*5"? "Add *5 doesn't really mean anything
> > to
> > me.
> 
> Sorry I forgot to add the code that I had to give an example of what
> I was talking about. I’ll put it below, sorry that it’s so long. A

Here's an example of how your star() function could be rewritten.
Note that it does not exactly do what it does in your example regarding the start and end position of the turtle.
So use it for inspiration only ;)


from turtle import *
from math import sin, sqrt, radians

def star(width):
	R = (width)/(2*sin(radians(72)))
	A = (2*width)/(3+sqrt(5))
	# record the initial position
	position = getturtle().pos()
	heading =  getturtle().heading()
	penup()
	left(36) # initial angle
	forward(R)
	pendown()
	for arms in range(5):
		left(144)
		forward(A)
		right(72)
		forward(A)
	penup()
	# go back to the initial position
	getturtle().setpos(position)
	getturtle().setheading(heading)
   
showturtle()
clear()
star(50)


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list