Differenze tra le versioni di "Tutorial:Il comando Tartaruga"
Riga 32: | Riga 32: | ||
==Costruire un quadrato== | ==Costruire un quadrato== | ||
− | + | Per fare costruire a una ''tartaruga'' di nome ''t'' un quadrato di lato 1 a partire dall'origine del sistema di coordinate, digitare nell'ordine i seguenti comandi, premendo il tasto {{KeyCode|Invio}} al termine di ogni inserimento: | |
− | <code>t= | + | <code>t=Tartaruga[]</code><br/> |
− | <code> | + | <code>TartarugaAvanti[t,1]</code><br/> |
− | <code> | + | <code>TartarugaSinistra[t,90°]</code><br/> |
− | <code> | + | <code>TartarugaAvanti[t,1]</code><br/> |
− | <code> | + | <code>TartarugaSinistra[t,90°]</code><br/> |
− | <code> | + | <code>TartarugaAvanti[t,1]</code><br/> |
− | <code> | + | <code>TartarugaSinistra[t,90°]</code><br/> |
− | <code> | + | <code>TartarugaAvanti[t,1]</code><br/> |
− | |||
− | |||
− | |||
− | |||
− | + | Dopo l'inserimento dei comandi solo in ''vista Algebra'' è visibile la posizione finale della tartaruga ''t'', mentre il movimento della tartaruga non sarà visualizzato nella ''vista Grafici'' finché non si preme il pulsante [[Image:Animate Play.png]] ''Esegui''. | |
− | Obviously, the input of these 8 | + | Obviously, the input of these 8 comando lines is tedious, especially when you know that it can be reduced to an input of 2 lines : |
<code>t=Turtle[]</code><br/> | <code>t=Turtle[]</code><br/> | ||
Riga 57: | Riga 53: | ||
Immediately, a remark, the passage of global arguments work, so if a numeric variable ''c'' is defined :<br/> | Immediately, a remark, the passage of global arguments work, so if a numeric variable ''c'' is defined :<br/> | ||
<code>Repeat[4, TurtleForward[t, c], TurtleLeft[t, 90° ]]</code><br/> | <code>Repeat[4, TurtleForward[t, c], TurtleLeft[t, 90° ]]</code><br/> | ||
− | The | + | The tartaruga ''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 | + | But the trace will not be affected by a subsequent change in the valore of ''c''. |
− | And without further ado, validate successively each of the following | + | And without further ado, validate successively each of the following comandi in Input : |
<code>c=1</code><br/> | <code>c=1</code><br/> | ||
Riga 69: | Riga 65: | ||
The execution trace you these classic square 5 nested respective sides 1, 2, 3, 4 and 5. | The execution trace you these classic square 5 nested respective sides 1, 2, 3, 4 and 5. | ||
− | < | + | <cInvio> [[Image:CarrésEmboîtés.png]]</cInvio> |
Riga 79: | Riga 75: | ||
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 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 | + | I select Text strumento, and validate : |
<code>For Square :c</code><br/> | <code>For Square :c</code><br/> | ||
Riga 88: | Riga 84: | ||
in Scripting / On Click tab (don't forget to press the "Ok" button) | in Scripting / On Click tab (don't forget to press the "Ok" button) | ||
− | The execution of the following 2 | + | The execution of the following 2 comandi :<br/> |
<code>c=2</code><br/> | <code>c=2</code><br/> | ||
<code>t=Turtle[]</code><br/> | <code>t=Turtle[]</code><br/> | ||
Riga 99: | Riga 95: | ||
<code>For NestedSquares :n :c</code><br/> | <code>For NestedSquares :n :c</code><br/> | ||
− | <code>Repeat[n,RunClickScript[Square], | + | <code>Repeat[n,RunClickScript[Square],Setvalore[c,c+1]]</code><br/> |
after validating <br/><code>c=1</code> and <br/><code>n=5</code>, <br/>one <b><u>click</u></b> on this new text gives me the construction of previous nested squares. | after validating <br/><code>c=1</code> and <br/><code>n=5</code>, <br/>one <b><u>click</u></b> on this new text gives me the construction of previous nested squares. | ||
Riga 118: | Riga 114: | ||
<code>TurtleRight[t,135°]</code><br/> | <code>TurtleRight[t,135°]</code><br/> | ||
− | < | + | <cInvio> [[Image:Feuille.png]]</cInvio> |
<code>Pour Epi</code><br/> | <code>Pour Epi</code><br/> | ||
Riga 127: | Riga 123: | ||
<code>TurtleRight[t,90°]</code><br/> | <code>TurtleRight[t,90°]</code><br/> | ||
− | < | + | <cInvio> [[Image:Épi.png]]</cInvio> |
<code>Pour Champ</code><br/> | <code>Pour Champ</code><br/> | ||
<code>Repeat[3,RunClickScript[Epi],TurtleUp[t],TurtleForward[t,4],TurtleDown[t]]</code><br/> | <code>Repeat[3,RunClickScript[Epi],TurtleUp[t],TurtleForward[t,4],TurtleDown[t]]</code><br/> | ||
− | < | + | <cInvio> [[Image:Champ.png]]</cInvio><br/><br/> |
With a management button whose script :<br/> | With a management button whose script :<br/> |
Versione delle 18:10, 12 giu 2015
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
- Traslazione
- TartarugaAvanti e TartarugaIndietro:
- la tartaruga si muove avanti o indietro in linea retta della distanza indicata.
- Rotazione
- TartarugaDestra e TartarugaSinistra:
- la tartaruga ruota su se stessa a destra o sinistra dell'angolo indicato.
- Traccia:
- TartarugaGiù:
- la tartaruga indicata lascia una traccia del proprio movimento.
- TartarugaSu,
- la tartaruga indicata non lascia una traccia del proprio movimento.
Sono inoltre applicabili alla tartaruga molti altri comandi, tra i quali Esegui[], Ripeti[] e i comandi EseguiScriptAgg[] ed EseguiScriptClic[].
Costruire un quadrato
Per fare costruire a una tartaruga di nome t un quadrato di lato 1 a partire dall'origine del sistema di coordinate, digitare nell'ordine i seguenti comandi, premendo il tasto Invio al termine di ogni inserimento:
t=Tartaruga[]
TartarugaAvanti[t,1]
TartarugaSinistra[t,90°]
TartarugaAvanti[t,1]
TartarugaSinistra[t,90°]
TartarugaAvanti[t,1]
TartarugaSinistra[t,90°]
TartarugaAvanti[t,1]
Dopo l'inserimento dei comandi solo in vista Algebra è visibile la posizione finale della tartaruga t, mentre il movimento della tartaruga non sarà visualizzato nella vista Grafici finché non si preme il pulsante Esegui.
Obviously, the input of these 8 comando 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 tartaruga 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 valore of c.
And without further ado, validate successively each of the following comandi 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 strumento, 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 comandi :
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],Setvalore[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]]
<cInvio> File:Champ.png</cInvio>
With a management button whose script :
Delete[t]
t=Turtle[]
SetCoords[t,-8,-1]
StartAnimation[]