View Single Post
Old 19-01-2008, 12:45   #9
^TiGeRShArK^
Senior Member
 
L'Avatar di ^TiGeRShArK^
 
Iscritto dal: Jul 2002
Città: Reggio Calabria -> London
Messaggi: 12103
Quote:
Originariamente inviato da k0nt3 Guarda i messaggi
per non saper ne leggere ne scrivere in python sono riuscito a ottenere una cosa simile
Codice:
import math
from TurtleWorld import *


def polyline(t, length, n, angle):
    """Draw n line segments with the given length and
    angle (in degrees) between them. t is a turtle.
    """
    for i in range(n):
        fd(t, length)
        lt(t, angle)

def arc(t, r, angle):
    """Draw an arc with the given r (radius) and angle
    (in degrees). t is a turtle."""
    arclength = 2 * math.pi * r * angle / 360
    n = int(arclength / 4)
    length = arclength / n
    polyline(t, length, n, float(angle)/n)


def flower(turtle, radius, petals):
    for i in range(petals):
        arc(turtle, radius, 90)
        lt(turtle, 90)
        arc(turtle, radius, 90)
        lt(turtle, (360/petals+90))


TurtleWorld()
bob = Turtle()
bob.delay = 0.001
flower(bob, 90, 7)
infatti hai usato la banale generalizzazione e il left turn che per qualche strano motivo ( ) quei geni hanno chiamato lt anzichè left turn
Ho sempre odiato chi chiama i metodi e le variabili con nomi non significativi

Cmq il mio codice, con un numero di petali pari a 4 ed aggiungendo il left turn funziona perfettamente
__________________
^TiGeRShArK^ è offline   Rispondi citando il messaggio o parte di esso