Tutorial:Il comando Tartaruga
Digitando il comando Tartaruga[] nella barra di inserimento viene creato nella vista Grafici un punto chiamato tartaruga1 di coordinate (0, 0) e orientato in direzione del semiasse positivo delle ascisse .
Contemporaneamente, nell'angolo in basso a sinistra della vista Grafici è visualizzato anche il pulsante Esegui (che diventa Pausa quando si fa clic su di esso).
Una tartaruga non è altro che un punto animato, che inizia a muoversi non appena viene premuto il pulsante Esegui oppure viene applicato il comando AvviaAnimazione[]. Tutti i comandi impartiti alla tartaruga mentre è visualizzato il pulsante Play vengono memorizzati da GeoGebra e saranno eseguiti nell'ordine dopo la pressione del pulsante.
La finestra di dialogo Proprietà dell'oggetto tartaruga è la stessa dell'oggetto punto, anche se con funzionalità limitate o leggermente differenti: ad esempio la modifica del colore non viene applicata alla tartaruga, ma solo ad una sua eventuale traccia.
Per modificare la posizione della tartaruga è possibile utilizzare il comando ImpCoordinate[Oggetto, x, y], mentre per determinare la posizione della tartaruga nel piano è possibile utilizzare le funzioni x()
e y()
, anche se è necessario tenere presente che tali funzioni restituiscono la posizione finale della tartaruga, indipendentemente dal fatto che i comandi di movimento siano stati eseguiti o meno.
Comandi specifici per la tartaruga
- Translations :
- TurtleForward et TurtleBack,
- the named turtle will move forward or backward in a straight line, the given distance.
- TurtleForward et TurtleBack,
- Rotations :
- TurtleRight et TurtleLeft,
- the named turtle will pivot on the spot to the right or to the left of the given angle.
- TurtleRight et TurtleLeft,
- Traces :
- TurtleDown,
- the named turtle will leave a trace of its movement, and
- the named turtle will leave a trace of its movement, and
- TurtleUp,
- the named turtle will not trace its movement.
- TurtleDown,
Some commands such as Execute[], Repeat[] and RunUpdateScript[] or RunClickScript[] will often be requested.
- Construct a square
Validate successively each of the following commands in Input :
t=Turtle[]
TurtleForward[t,1]
TurtleLeft[t,90°]
TurtleForward[t,1]
TurtleLeft[t,90°]
TurtleForward[t,1]
TurtleLeft[t,90°]
TurtleForward[t,1]
Of course, as announced from the start, nothing happens in Graphics, after the appearance of the turtle and the Play button, just if Algebra is open, you may notice changes in the coordinates of the point t. (reminder: do not deprive yourself of the functionality "Replay" for Input field !!!) and finally press the Play button
A turtle, named t, will build a direct square, side 1, from the origin.
Obviously, the input of these 8 command lines is tedious, especially when you know that it can be reduced to an input of 2 lines :
t=Turtle[]
Repeat[4, TurtleForward[t, 1], TurtleLeft[t, 90° ]]
Immediately, a remark, the passage of global arguments work, so if a numeric variable c is defined :
Repeat[4, TurtleForward[t, c], TurtleLeft[t, 90° ]]
The turtle t, will build a direct square, side c, from the origin, backwards, if c is negative.
But the trace will not be affected by a subsequent change in the value of c.
And without further ado, validate successively each of the following commands in Input :
c=1
n=5
Repeat[n,Repeat[4, TurtleForward[t, c], TurtleLeft[t, 90° ]],SoitValeur[c,c+1]]
The execution trace you these classic square 5 nested respective sides 1, 2, 3, 4 and 5.
- "Process"
The Logo's philosophy was rather define "procedures", realizing a basic working, procedures are then solicited a group to make a more complex task.
I will use the GeoGebra Scripts attached to objects to define procedures. I chose deliberately as object type "text", which allows me to easily display the listing,
I select Text tool, and validate :
For Square :c
Repeat[4, TurtleForward[t, c], TurtleLeft[t, 90° ]]
By opening the properties of this text, I renames Square, and I do a copy / paste of instruction in Scripting / On Click tab (don't forget to press the "Ok" button)
The execution of the following 2 commands :
c=2
t=Turtle[]
and one click on the text
built as expected a square of side 2
So now with other text in the same file, I renamed NestedSquares :
For NestedSquares :n :c
Repeat[n,RunClickScript[Square],SetValue[c,c+1]]
after validating c=1
and n=5
,
one click on this new text gives me the construction of previous nested squares.
- Example page 55 de "Logo, des ailes pour l'esprit" ("Alas para la mente" Horacio C. Reggini)
Pour Feuille
TurtleLeft[t,45°]
TurtleForward[t,2]
TurtleBack[t,2]
TurtleLeft[t,90°]
TurtleForward[t,2]
TurtleBack[t,2]
TurtleRight[t,135°]
Pour Epi
TurtleLeft[t,90°]
TurtleForward[t,5]
Repeat[3,TurtleRight[t,90°], RunClickScript[Feuille], TurtleLeft[t,90°], TurtleForward[t,1.25]]
TurtleBack[t,8.75]
TurtleRight[t,90°]
Pour Champ
Repeat[3,RunClickScript[Epi],TurtleUp[t],TurtleForward[t,4],TurtleDown[t]]
With a management button whose script :
Delete[t]
t=Turtle[]
SetCoords[t,-8,-1]
StartAnimation[]