130
>Je kunt met de programmeertaal &turtlelang; nieuwe dingen maken. Als je een programma schrijft zul je vaak <link linkend="containers"
132
> nodig hebben, en in sommige gevallen heb je het commando <link linkend="learn"
134
> nodig om nieuwe commando's te maken. Als je een <link linkend="containers"
136
> of een nieuw commando met behulp van <link linkend="learn"
138
> maakt, dan moet je er een naam aan geven.</para>
132
>When using the &turtlelang; programming language you create new things. If you write a program you will often need <link linkend="containers"
134
> and in some cases you need <link linkend="learn"
136
> to create new commands. When making a new command with <link linkend="learn"
138
> you will have to specify a name.</para>
140
>Je kunt een willekeurige naam kiezen, als die maar niet al wordt gebruikt. Bijvoorbeeld, je kunt een plaatshouder niet <link linkend="forward"
142
> noemen, omdat die naam al wordt gebruikt voor een commando, en dus al een betekenis heeft. <screen>
143
# hier wordt vooruit gebruikt als een plaatshouder, maar die heeft al een betekenis
144
# dus komt er een foutmelding:
140
>You can choose any name, as long as it does not already have a meaning. For instance you cannot name a function <link linkend="forward"
142
>, since that name is already used for an internal command. <screen>
143
# here forward is used as a new command,
144
# but it already has a meaning so
145
# this will produce an error:
147
print "this is invalid"
147
# dit werkt echter wel (is een commando):
150
> Namen mogen alleen letters, cijfers en onderstreepjes (_) bevatten. Ze moeten altijd met een letter beginnen. </para>
155
> Names can contain only letters, numbers and underscores (_). Yet they have to start with a letter. Container names have to start with the container prefix ($). <screen
156
># here forward is used as a container,
157
# starting with the $ prefix, so it does
158
# not conflict with the forward command
152
164
>Plaatshouders worden <glossterm
153
165
>geaccentueerd</glossterm
198
210
>Rekensymbolen</title>
200
>&kturtle; kent alle basissymbolen van het rekenen: optellen (<userinput
212
>&kturtle; supports all basic math symbols: add (<userinput
202
>), aftrekken (<userinput
214
>), subtract (<userinput
204
>), vermenigvuldigen (<userinput
216
>), multiply (<userinput
218
>), divide (<userinput
208
>) en de haakjes <userinput
220
>) and the brackets <userinput
357
<sect3 id="turnright">
359
>draairechts (dr)</title>
373
<anchor id="turnright"/>
377
>turnright (tr)<indexterm
379
>turnright (tr)</primary
368
385
>draairechts X</screen>
370
>draairechts</userinput
371
> laat de schildpad X graden naar rechts draaien. <userinput
372
>draairechts</userinput
373
> kun je afkorten met <userinput
387
>turnright</userinput
388
> the turtle to turn an amount of X degrees to the right. <userinput
389
>turnright</userinput
390
> can be abbreviated to <userinput
380
<sect3 id="direction">
382
>richting (rt)</title>
397
<anchor id="direction"/>
401
>direction (dir)<indexterm
403
>direction (dir)</primary
433
453
>ganaar X,Y</screen>
435
>ganaar X,Y</userinput
436
> laat de schildpad naar een bepaalde plaats op het canvas gaan. De plaats is op X <glossterm linkend="pixels"
438
> vanaf de linkerkant en Y <glossterm linkend="pixels"
440
> vanaf de bovenkant van het canvas. Opmerking: de schildpad tekent met het commando <userinput
456
> commands the turtle to go to a certain place on the canvas. This place is X <glossterm linkend="pixels"
458
> from the left of the canvas, and Y <glossterm linkend="pixels"
460
> form the top of the canvas. </para
518
>Using the commands <userinput
526
> the turtle will not draw a line, no matter if the pen is up or down.</para>
530
<sect2 id="locate-the-turtle">
532
>Where is the turtle?</title>
534
>There are two commands which return the position of the turtle on the screen.</para>
550
> returns the number of pixels from the left of the canvas to the current position of the turtle.</para
568
> returns the number of pixels from the top of the canvas to the current position of the turtle.</para
612
<!--<sect2 id="canvas">
614
693
>Commands to control the canvas</title>
616
695
>There are several commands to control the canvas.</para>
617
<sect3 id="resizecanvas">
619
>canvassize (cs)</title>
697
<anchor id="resizecanvas"/>
700
>canvassize (cs)<indexterm
702
>canvassize (cs)</primary
627
708
>canvassize X,Y</screen>
629
710
>canvassize</userinput
630
711
> command you can set the size of the canvas. It takes X and Y as input, where X is the new canvas width in <glossterm linkend="pixels"
631
712
>pixels</glossterm
643
<sect3 id="setbgcolor">
645
>canvascolor (cc)</title>
724
<anchor id="setbgcolor"/>
728
>canvascolor (cc)<indexterm
730
>canvascolor (cc)</primary
654
736
>canvascolor R,G,B</screen>
656
738
>canvascolor</userinput
657
739
> set the color of the canvas. <userinput
658
740
>canvascolor</userinput
726
806
<sect2 id="clean">
728
808
>Commando's om schoon te maken</title>
730
810
>Er zijn twee commando's waarmee je het canvas kunt schoonmaken nadat je er een bende van hebt gemaakt.</para>
816
>clear (ccl)<indexterm
818
>clear (ccl)</primary
744
826
>schoon</userinput
745
827
> kun je alle tekeningen op het canvas wissen. De rest blijft staan, de positie en de hoek van de schildpad, de kleur van het canvas, de zichtbaarheid van de schildpad en de grootte van het canvas blijven zoals ze waren.</para
761
844
>alsnieuw</screen>
764
> maakt nog meer schoon dan het commando <userinput
766
>. Na het commando <userinput
768
> is alles zoals het was toen je &kturtle; net had opgestart. De schildpad wordt in het midden van het scherm gezet, de canvaskleur is wit en de schildpad tekent een zwarte lijn op het canvas.</para
847
> cleans much more thoroughly than the <userinput
849
> command. After a <userinput
851
> command everything is like is was when you had just started &kturtle;. The turtle is positioned at the middle of the screen, the canvas color is white, the turtle draws a black line on the canvas and the canvassize is set to 400 x 400 pixels.</para
775
857
<sect2 id="sprites">
786
868
>Hierna volgt een volledig overzicht van alle commando's die je kunt gebruiken bij sprites.</para>
788
870
>[De huidige versie van &kturtle; heeft alleen een schildpad als sprite. Andere sprites zijn er dus niet. In toekomstige versies van het programma zul je de schildpad kunnen veranderen in je eigen ontwerp]</para>
789
<sect3 id="spriteshow">
803
> maakt de schilpad weer zichtbaar nadat hij is verborgen. <userinput
805
> kun je afkorten met <userinput
812
<sect3 id="spritehide">
814
>verberg (vs)</title>
826
> verbergt de schildpad. Dit is handig als je de schildpad niet in je tekening wilt zien. <userinput
828
> kun je afkorten met <userinput
872
<anchor id="spriteshow"/>
876
>spriteshow (ss)<indexterm
878
>spriteshow (ss)</primary
886
>spriteshow</userinput
887
> makes the turtle visible again after it has been hidden. <userinput
888
>spriteshow</userinput
889
> can be abbreviated to <userinput
896
<anchor id="spritehide"/>
900
>spritehide (sh)<indexterm
902
>spritehide (sh)</primary
910
>spritehide</userinput
911
> hides the turtle. This can be used if the turtle does not fit in your drawing. <userinput
912
>spritehide</userinput
913
> can be abbreviated to <userinput
837
921
<sect2 id="writing">
839
>Kan de schildpad schrijven?</title>
923
>Can the turtle write?</title>
841
925
>Het antwoord is: <quote
843
927
>. De schildpad kan schrijven. Hij schrijft zo'n beetje alles wat je hem opdraagt.</para>
998
>random (rnd)<indexterm
1000
>random (rnd)</primary
916
1006
>gok X,Y</screen>
919
> is een commando dat invoer vraagt en uitvoer geeft. Als invoer vraagt het commando twee cijfers, het eerste cijfer (X) zet de minimum uitvoer, en het tweede (Y) zet de maximum. De uitvoer is een willekeurig gekozen getal dat gelijk is aan of groter dan het minimum en gelijk aan of kleiner dan het maximum. Hier is een klein voorbeeld:<screen>
1009
> is a command that takes input and gives output. As input are required two numbers, the first (X) sets the minimum output, the second (Y) sets the maximum. The output is a randomly chosen number that is equal or greater than the minimum and equal or smaller than the maximum. Here a small example: <screen>
926
> Met het commando <userinput
928
> kun je wat chaos aan je programma toevoegen.</para
1016
> Using the <userinput
1018
> command you can add a bit of chaos to your program.</para
1021
1113
>-teken dat ervoor wordt geplaatst.</para>
1024
>Plaatshouders die niet worden gebruikt zijn leeg. Een voorbeeld: <screen>
1027
Er wordt niets op het canvas geschreven. Als we proberen met lege plaatshouders te <link linkend="math"
1029
> krijgen we foutmeldingen. </para>
1116
>Containers that are not used contain nothing. An example: <screen>
1119
> This will print nothing and you get an error message. </para>
1031
1121
<sect2 id="variables">
1093
1183
>tekenreeksen</link
1096
>Ook tekenreeksen kunnen worden opgeslagen in <link linkend="containers"
1097
>plaatshouders</link
1098
>, net zoals <link linkend="number"
1100
>. Tekenreeksen lijken veel op variabelen. Het grootste verschil met getallen is dat je met tekenreeksen niet kunt <link linkend="math"
1102
>. Een voorbeeld van het gebruik van tekenreeksen: <screen>
1104
$naam = vraag "Voer je naam in..."
1105
schrijf $x + $naam + ", hoe gaat het met je?"
1186
>Strings can also be stored in <link linkend="containers"
1188
> just like <link linkend="number"
1190
> Strings are a lot like variables. The biggest difference is that they contain text in stead of numbers. For this reason strings cannot be used in <link linkend="math"
1191
>mathematical calculations</link
1192
> and <link linkend="questions"
1194
>. An example of the use of strings: <screen>
1196
$name = ask "Please enter your name..."
1197
print $x + $name + ", how are you?"
1107
> Op de eerste regel wordt <userinput
1199
> On the first line the string <userinput
1111
>. Op de tweede regel wordt de tekenreeks <userinput
1113
> gesteld op de uitvoer van de opdracht <userinput
1115
>. Op de derde regel schrijft het programma een samenstelling van de drie tekenreeksen op het canvas.</para>
1203
>. On the second line the string <userinput
1205
> is set to the output of the <userinput
1207
> command. On the third line the program prints a composition of three strings on the canvas.</para>
1117
1209
>Dit programma vraagt je je naam in te voeren. Als je bijvoorbeeld de naam <quote
1127
1219
>Kan de schildpad rekenen?</title>
1129
>Ja, &kturtle; kan voor jou rekenen, namelijk optellen (+), aftrekken (-), vermenigvuldigen (*) en delen (/). Dit is een voorbeeld waarin dit alles wordt gebruikt: <screen>
1221
>Yes, &kturtle; will do your math. You can add (+), subtract (-), multiply (*), and divide (/). Here is an example in which we use all of them: <screen>
1134
schrijf "a: "+$a+", b: "+$b+", c: "+$c+", d: "+$d
1226
print "a: "+$a+", b: "+$b+", c: "+$c+", d: "+$d
1136
> Weet je welke waarden a, b, c, en d hebben? Merk in het voorbeeld het gebruik op van het <link linkend="assignment"
1228
> Do you know what value a, b, c and d have? Please note the use of the <link linkend="assignment"
1142
1234
>Als je een eenvoudige rekensom wilt laten doen, dan kan dat bijvoorbeeld zo: <screen
1148
1240
schrijf ( ( 20 - 5 ) * 2 / 30 ) + 1
1150
1242
> Het gedeelte tussen de binnenste haakjes zal als eerste worden uitgerekend. In dit voorbeeld wordt 20 - 5 berekend, dan wordt de uitkomst vermenigvuldigd met 2, en daarna wordt er gedeeld door 30. Tot slot wordt er 1 bij opgeteld (het antwoord is 2).</para>
1244
>&kturtle; has advanced mathematical features. It knows the number <userinput
1246
> and trigonometrical functions like <userinput
1258
> and the functions <userinput
1268
>sin, cos, tan</primary
1272
>arcsin, arccos, arctan</primary
1282
>Let the turtle round your numbers</title>
1284
>If you need integers in calculations, use this function.</para>
1299
> the given number to the nearest integer. <screen>
1305
> With this code the turtle will print the numbers 11 and 10.</para
1153
1312
<sect1 id="questions">
1303
1462
>Vragenlijm</title>
1305
>Vragen kunnen aan elkaar geplakt worden met <quote
1307
>. Zo kun je van een paar kleine vragen een grote vraag maken. <screen>
1464
>Question glue-words enable us to glue questions into one big question. <screen>
1310
als ($a < 5) en ($b == 5) {
1467
if ($a < $b) and ($b == 5) {
1314
> In dit voorbeeld is het lijmwoord <userinput
1316
> gebruikt om twee vragen (<userinput
1471
> In this example the glue-word <userinput
1473
> is used to glue 2 questions (<userinput
1317
1474
>a < 5</userinput
1320
>) aan elkaar te plakken. Als een zijde van de <userinput
1324
> als antwoord heeft, dan zal de hele vraag <quote
1326
> zijn, omdat bij het lijmwoord <userinput
1328
> beide zijden <quote
1330
> moeten zijn om het antwoord <quote
1332
> te krijgen. Vergeet de haakjes om de vragen niet!</para>
1477
>) together. If one side of the <userinput
1479
> would answer <quote
1481
> the whole question would answer <quote
1483
>, because with the glue-word <userinput
1485
> both sides need to be <quote
1487
> in order to answer <quote
1489
>. Please do not forget to use the brackets around the questions!</para>
1335
1492
>Hier is een schematisch overzicht, een meer gedetailleerde uitleg volgt hieronder: <table>
1439
1608
>De programmastuurcommando's maken het mogelijk, —zoals de naam al zegt— het verloop van een programma te sturen.</para>
1441
>Commando's die het programmaverloop sturen worden <glossterm
1442
>geaccentueerd </glossterm
1443
> met donkergroen in een vet lettertype. De accolades worden meestal samen met de programmastuurcommando's gebruikt en worden <glossterm
1444
>geaccentueerd</glossterm
1445
> met vet zwart.</para>
1610
>Execution controlling commands are <glossterm
1611
>highlighted</glossterm
1612
> with dark green in a bold font type. The brackets are mostly used together with execution controllers and they are <glossterm
1613
>highlighted</glossterm
1614
> with bolded black.</para>
1447
1616
<sect2 id="wait">
1517
1694
</variablelist>
1522
>De lus "terwijl"</title>
1530
>terwijl <link linkend="questions"
1533
Het programmastuurcommando <userinput
1535
> lijkt veel op <link linkend="if"
1539
>. Het verschil is dat <userinput
1541
> de programmacode tussen de accolades blijft herhalen totdat het antwoord op de <link linkend="questions"
1553
> Op de eerste regel krijgt <userinput
1555
> de waarde 1. Op de tweede regel wordt de <link linkend="questions"
1558
>x < 5</userinput
1559
> gesteld. Omdat het antwoord op deze vraag <quote
1561
> is start de programmabesturing <userinput
1563
> het uitvoeren van de code tussen de accolades totdat het antwoord op de <link linkend="questions"
1567
> is geworden. In dit voorbeeld wordt de code tussen de accolades 4 keer uitgevoerd, omdat telkens als de vijfde regel wordt uitgevoerd de waarde <userinput
1569
> met 1 wordt vermeerderd.</para
1575
1697
<sect2 id="else">
1577
1699
>Als niet, of in andere woorden: "anders"</title>
1619
1745
</variablelist>
1750
>De lus "terwijl"</title>
1762
>terwijl <link linkend="questions"
1765
The execution controller <userinput
1767
> is a lot like <link linkend="if"
1771
>. The difference is that <userinput
1773
> keeps repeating (looping) the code between the brackets until the answer to the <link linkend="questions"
1785
> On the first line <userinput
1787
> is set to 1. On the second line the <link linkend="questions"
1790
>x < 5</userinput
1791
> is asked. Since the answer to this question is <quote
1793
> the execution controller <userinput
1795
> starts executing the code between the brackets until the answer to the <link linkend="questions"
1799
>. In this case the code between the brackets will be executed 4 times, because every time the fifth line is executed <userinput
1801
> increases by 1.</para
1809
>The "repeat" loop</title>
1821
>repeat number { ... }</screen>
1822
The execution controller <userinput
1824
> is a lot like <link linkend="while"
1828
>. The difference is that <userinput
1830
> keeps repeating (looping) the code between the brackets for the given number.</para
1622
1836
<sect2 id="for">
1624
1838
>De lus "voor", een tellende lus</title>
1633
>startpunt</userinput
1635
>eindpunt</userinput
1855
>start point</userinput
1857
>end point</userinput
1636
1858
> { ... }</screen>
1637
1859
De lus <userinput
1638
1860
>voor</userinput
1651
1873
> de waarde 10 heeft bereikt. De code tussen de accolades schrijft de waarde van <userinput
1653
> vermenigvuldigd met 7. Nadat deze commando's zijn uitgevoerd zie je de tafel van 7 op het canvas staan.</para
1875
> vermenigvuldigd met 7. Nadat deze commando's zijn uitgevoerd zie je de tafel van 7 op het canvas staan. </para>
1877
>The default step size of a loop is 1, you can use an other value with <screen
1879
>start point</userinput
1881
>end point</userinput
1883
>step size</userinput
1893
>Leave a loop</title>
1906
Terminates the current loop immediately and transfers control to the statement immediately following that loop</para
1914
>Stop the turtle</title>
1927
Finishes the execution of the code.</para
1670
> is een nogal apart commando, omdat die kan worden gebruikt om je eigen commando's te maken. Het commando dat je maakt kan om <glossterm linkend="input-output"
1672
> vragen en <glossterm linkend="input-output"
1674
> geven. Laten we eens kijken hoe je een nieuw commando kunt maken: <screen>
1947
> is a very special command, because it is used to create your own commands. The command you create can take <glossterm linkend="input-output"
1949
> and return <glossterm linkend="input-output"
1951
>. Let us take a look at how a new command is created: <screen>
1682
> Het nieuwe commando heet <userinput
1959
> The new command is called <userinput
1686
> vraagt om een <glossterm linkend="input-output"
1688
>, een getal, om de grootte van de cirkel te bepalen. <userinput
1690
> geeft geen <glossterm linkend="input-output"
1692
>. Het commando <userinput
1694
> kan nu worden gebruikt als een normaal commando in de rest van de programmacode. Hier een voorbeeld: <screen
1710
>In het volgende voorbeeld maken we een commando met een uitvoerwaarde. <screen>
1713
leer vermenigvuldigMetZichzelf $n {
1718
$i = vraag "Voer een getal in en klik op OK"
1719
schrijf $i + " vermenigvuldigd met zichzelf is " + vermenigvuldigMetZichzelf $i
1721
> In dit voorbeeld wordt een nieuw commando met de naam <userinput
1722
>vermenigvuldigMetZichzelf</userinput
1723
> gemaakt. De invoer van dit commando wordt vermenigvuldigd met zichzelf en daarna doorgegeven met behulp van het commando <anchor id="return"/><userinput
1724
>geefdoor</userinput
1725
>. Het commando <userinput
1726
>geefdoor</userinput
1727
> is een manier om de waarde van een functie die je hebt gemaakt als antwoord te geven. </para>
1729
>Commando's kunnen meer dan een <glossterm linkend="input-output"
1731
> nodig hebben. In het volgende voorbeeld wordt een commando gemaakt dat een rechthoek tekent. <screen
1732
>leer rechthoek $X, $Y {
1963
> takes one <glossterm linkend="input-output"
1965
>, a number, to set the size of the circle. <userinput
1967
> returns no <glossterm linkend="input-output"
1971
> command can now be used like a normal command in the rest of the code. See this example: <screen
1987
>In the next example, a command with a return value is created. <screen>
1990
learn multiplyBySelf $n {
1994
$i = ask "Please enter a number and press OK"
1995
print $i + " multiplied by itself is: " + multiplyBySelf $i
1997
> In this example a new command called <userinput
1998
>multiplyBySelf</userinput
1999
> is created. The input of this command is multiplied by itself and then returned, using the <anchor id="return"/><userinput
2001
> command. The <userinput
2003
> command is the way to output a value from a function you have created. </para>
2005
>Commands can have more than one <glossterm linkend="input-output"
2007
>. In the next example, a command that draws a rectangle is created. <screen>
2019
> Now you can run <userinput
2020
>box 50, 100</userinput
2021
> and the turtle will draw a rectangle on the canvas. </para>