Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66981 > unrolled thread

Re: Functions help

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2014-02-24 16:01 +0100
Last post2014-02-24 16:01 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Re: Functions help Jean-Michel Pichavant <jeanmichel@sequans.com> - 2014-02-24 16:01 +0100

#66981 — Re: Functions help

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2014-02-24 16:01 +0100
SubjectRe: Functions help
Message-ID<mailman.7309.1393254099.18130.python-list@python.org>
----- Original Message ----- 

> On Feb 23, 2014, at 1:44 AM, Steven D'Aprano <
> steve+comp.lang.python@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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web