forked from bjpop/js-turtle
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreference.html
545 lines (545 loc) · 16.5 KB
/
reference.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Turtle Graphics</title>
<link rel="stylesheet" href="turtleweb.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Poppins|Roboto" rel="stylesheet">
</head>
<!--body onresize="resizeColumns();"> -->
<body>
<header>
<h1>JavaScript Turtle Graphics</h1>
<div class="navigation">
<ul>
<li><a href="overview.html" title="Overview of Turtle Graphics">Intro</a></li>
<li><a href="guide.html" title="User Guide for Turtle Graphics Integrated Development Environment">Guide</a></li>
<li><a href="turtle.html" title="Integrated Development Environment for Turtle Graphics">IDE</a></li>
<li><a href="javascript.html" title="Tutorial for Simple JavaScript">JavaScript</a></li>
<li><a href="tutorial.html" title="Tutorial for Basic Turtle Graphics">Tutorial</a></li>
<li><a href="animation.html" title="Tutorial for Animation with Turtle Graphics">Animation</a></li>
<li><a href="examples.html" title="Examples of Things Created with Turtle Graphics">Examples</a></li>
<li><a class="active" href="reference.html" title="Language Reference">Reference</a></li>
<li><a href="nerd.html" title="Nerd Links">Nerd</a></li>
<li><a href="about.html" title="About Turtle Graphics">About</a></li>
</div>
</header>
<!--
<h4 id="referenceTitle">
Language Reference
<button id="referenceClose">
<svg class="fi" viewBox="0 0 64 64">
<line x1="2" y1="2" x2="62" y2="62" style="stroke:rgb(0,0,0);stroke-width:8" />
<line x1="62" y1="2" x2="2" y2="62" style="stroke:rgb(0,0,0);stroke-width:8" />
</svg>
</button>
-->
<!--
add a menu .. sort of a table of contents to jump to contents
<a href="#color">jump to color</a>
also roll in the tutorial stuff
</h4>
-->
<article>
<p>
The language reference lists the available functions for JavaScript
Turtle Graphics.
</p>
<p>
Parameters are <em>italicized</em> included within parentheses '(' and ')'
characters. The parentheses must be entered when coding.
Optional parameters and separating
commas are enclosed withing square bracket '[' and ']' characters.
The square brackets in this case should not be included when coding.
</p>
<p>
Alternative forms of
the functions are separated with the pipe '|' character.
All forms are equivalent and use the same parameters.
</p>
<p>
Examples are shown in <code>bold typewriter font</code>. Each example may be clicked
to immediately execute it to see what it does.
</p>
<div id="reference">
<ul>
<li>
forward(<em>distance</em>) | fd(<em>distance</em>)
<p>
Move the turtle forward <em>distance</em> pixels.
</p>
<p>
Example: <code>forward (10)</code>
</p>
</li>
<li>
backward(<em>distance</em>) | back(<em>distance</em>) | bk(<em>distance</em>)
<p>
Move the turtle backward <em>distance</em> pixels, but leave
it pointing forward.
</p>
<p>
Example: <code>backward (10)</code>
</p>
</li>
<li>
right(<em>angle</em>) | rt(<em>angle</em>) | turn(<em>angle</em>)
<p>
Turn the turtle to the right <em>angle</em> degrees.
</p>
<p>
Example: <code>right (90)</code>
</p>
</li>
<li>
left(<em>angle</em>)
<p>
Turn the turtle to the left <em>angle</em> degrees.
</p>
<p>
Example: <code>left (90)</code>
</p>
</li>
<li>
penup() | up() | pu()
<p>
Lift the pen in the turtle so that it does not leave a mark as
it moves.
</p>
<p>
Example: <code>penup()</code>
</p>
</li>
<li>
pendown() | down() | pd()
<p>
Lower the pen in the turtle so that it leaves a mark as
it moves.
</p>
<p>
Example: <code>pendown()</code>
</p>
</li>
<li>
hideturtle() | ht()
<p>
Hide the turtle. It can still draw, but it isn't shown.
Hiding the turtle is useful in complex drawing as there
is significant speed up in not drawing the turtle.
</p>
<p>
Example: <code>hideTurtle()</code>
</p>
</li>
<li>
showturtle() | st()
<p>
Show the turtle.
</p>
<p>
Example: <code>showTurtle()</code>
</p>
</li>
<li>
home()
<p>
Move the turtle to its home in the center
(x=0, y=0) and pointing toward the top (angle=0).
Leave the graphics as they are.
</p>
<p>
Example: <code>home()</code>
</p>
</li>
<li>
clear()
<p>
Clear the graphics area, but leave the turtle where it is.
</p>
<p>
Example: <code>clear()</code>
</p>
</li>
<li>
reset()
<p>
Clear the graphics area and move the turtle to its home in the center
(x=0, y=0) and pointing toward the top (angle=0).
</p>
<p>
Example: <code>reset()</code>
</p>
</li>
<li>
goto(<em>x</em>,<em>y</em>) | setposition(<em>x</em>,<em>y</em>) | setpos(<em>x</em>,<em>y</em>)
<p>
Move the turtle to the coordinates <em>x</em> pixels to the
right of the center of the drawing area (or <em>-x</em> pixels to the
left of the center) and <em>y</em> pixels above the center of the drawing
area (or <em>-y</em> to below the center). This does not draw as the
turtle is moved.
</p>
<p>
Example: <code>goto (20,10)</code>
</p>
</li>
<li>
setx(<em>x</em>)
<p>
Move the turtle horizontally to the coordinates <em>x</em> pixels to the
right of the center of the drawing area (or <em>-x</em> pixels to the
left of the center).
</p>
<p>
Example: <code>setx (0)</code>
</p>
</li>
<li>
sety(<em>y</em>)
<p>
Move the turtle vertically to the coordinates <em>y</em> pixels above
the center of the drawing area (or <em>-y</em> to below the center).
This does not draw on the way.
</p>
<p>
Example: <code>sety (0)</code>
</p>
</li>
<li>
angle(<em>angle</em>) | setheading(<em>angle</em>) | seth(<em>angle</em>)
<p>
Turn the turtle to to the absolute <em>angle</em> relative to top
of the graphic area. <em>0</em> is the top, <em>0</em> is toward the top,
<em>90</em> is toward the right, <em>180</em> is toward the bottom, and
<em>270</em> <em>-90</em> is toward the left.
</p>
<p>
Example: <code>angle (90)</code>
</p>
</li>
<li>
width(<em>width</em>) | pensize(<em>width</em>) | penwidth(<em>width</em>) |
<p>
Change the <em>width</em> of the turtle pen (in pixels).
</p>
<p>
Example: <code>width(5);</code>
</p>
</li>
<li>
<!--
<a name="color"></a>
-->
color(<em>colorcode</em>)
<p>
Change the color of the turtle pen. The <em>colorcode</em> may be a number
from 0 to 15 representing the more or less standard turtle graphics colors. These colors may be accessed from the JavaScript array "logoColors."
<br/>
<button id="black">0 black</button>
<button id="blue">1 blue</button>
<button id="lime">2 lime</button>
<button id="cyan">3 cyan</button>
<button id="red">4 red</button>
<button id="magenta">5 magenta</button>
<button id="yellow">6 yellow</button>
<button id="white">7 white</button>
<button id="brown">8 brown</button>
<button id="tan">9 tan</button>
<button id="green">10 green</button>
<button id="aqua">11 aqua</button>
<button id="salmon">12 salmon</button>
<button id="purple">13 purple</button>
<button id="orange">14 orange</button>
<button id="gray">15 gray</button>
</p>
<p>
Example: <code>color("red")</code>
</p>
<p>
Example: <code>color(4)</code>
</p>
<p>
The <em>colorcode</em> may also be a quoted string with any acceptable CSS color code as in:
</p>
<ul>
<li>
"<em>colorName</em>"
where <em>colorName</em> is any of the named CSS colors.
</li>
<li>
"#<em>RRGGBB</em>"
where <em>RR</em>, <em>GG</em>, and <em>BB</em> is the hexidecimal
amount of red, green and blue respectively.
</li>
<li>
"rgb(<em>RR</em>, <em>GG</em>, <em>BB</em>)"
where <em>RR</em>, <em>GG</em>, and <em>BB</em> is the decimal
amount of red, green and blue respectively.
</li>
<li>
"rgba(<em>RR</em>, <em>GG</em>, <em>BB</em>, <em>AA</em>)"
where <em>RR</em>, <em>GG</em>, and <em>BB</em> is the decimal
amount of red, green and blue respectively and
<em>AA</em> is the alpha channel for transparancy between 1.0 for
opaque and 0.0 for totally transparent.
</li>
<li>
"hsl(<em>hue</em>, <em>sat</em>%, <em>light</em>%)"
where the values are hue is postion on the color wheel (0 to 360),
saturation percentage (sat), and lightness percentage (light).
<br/>
For example: <code>color("hsl(120, 100%, 50%)")</code>
</li>
<li>
"hsl(<em>hue</em>, <em>sat</em>%, <em>light</em>%, alpha)"
where the values are hue is postion on the color wheel (0 to 360),
saturation percentage, lightness percentage and alpha channel
for transparancy between 1.0 for opaque and 0.0 for totally
transparent.
<br/>
For example: <code>color("hsl(120, 100%, 50%, 1)")</code>
</li>
</ul>
</li>
<li>
write(<em>string</em>)
<p>
Places the text in the <em>string</em>along the projected path of
the turtle. The <em>string</em> may be a set of characters enclosed by
single or double quotation marks. The <em>string</em> may also be a value
returned by a function.
</p>
<p>
Example: <code>write("Hello World")</code>
</p>
</li>
<li>
setfont(<em>fontName</em>)
<p>
Set the characteristics (<em>style</em>, <em>variant</em>, <em>weight</em>,
<em>size</em>, and <em>font-family</em> desired for the font for subsequent writes.
</p>
<p>
Example: <code>setfont("italic small-caps bold 12px courier")</code>
</p>
</li>
<li>
curveright (<em>radius</em>[,<em>extent</em>])
<p>
Draw a circular curve from the turtle's postion. The
center of the curve is to the right of the turtle at a perpendicular
distance of <em>radius</em> pixels. The curve is a full circle unless
<em>extent</em> is provided to limit the number of degrees of arc.
</p>
<p>
Example: <code>curveright(30)</code>
</p>
<p>
Example: <code>curveright(10,45)</code>
</p>
</li>
<li>
curveleft (<em>radius</em>[,<em>extent</em>])
<p>
Draw a circular curve from the turtle's postion. The
center of the curve is to the left of the turtle at a perpendicular
distance of <em>radius</em> pixels. The curve is a full circle unless
<em>extent</em> is provided to limit the number of degrees of arc.
</p>
<p>
Example: <code>curveleft(20)</code>
</p>
<p>
Example: <code>curveleft(10,45)</code>
</p>
</li>
<li>
circle (<em>radius</em>[[,(<em>extent</em>],(<em>CCW</em>])
<p>
Draw a circle or arc centered on the turtle's postion. A full circle
is drawn unless <em>extent</em> is provided to limit the number of
degrees of arc. The arc is drawn clockwise unless a boolean <em>CCW</em>
is supplied and has a value of <em>false</em>.
</p>
<p>
Example: <code>circle(10)</code>
</p>
<p>
Example: <code>circle(20,90)</code>
</p>
<p>
Example: <code>circle(30,-90,false)</code>
</p>
</li>
<li>
dot ([<em>radius</em>])
<p>
Draw a filled circle centered on the turtle's postion.
The circle is drawn with a radius of <em>radius</em>) pixels. If
<em>radius</em>) is not specified, it defaults to the larger of
width plus 4 or twice the pensize).
</p>
<p>
Example: <code>dot()</code>
</p>
<p>
Example: <code>dot(10)</code>
</p>
</li>
<li>
beginShape()
<p>
Marks the begining of a shape to be filled. The shape consists of a
set of line segments (forward, backward, right, left, curveright, curveleft).
The set should be continuous and begin and end at the same point.
</p>
<p>
Example: <code>beginShape()</code>
</p>
</li>
<li>
fillShape([styl])
<p>
Fills the shape begun with the last beginShape() directive.
The shape is filled with <em>styl</em>, which may be a logo color number,
a normal HTML color definition (see color above), a gradient or
a pattern. This defaults to the turtle color.
</p>
<p>
Example: <code>fillShape("blue")</code>
</p>
</li>
<li>
n = random([<em>low,</em>]<em>high</em>)
<p>
Pick a random number between <em>low</em> and <em>high</em> -1.
If only one value <em>high</em> is provided, pick a number between 0 and
<em>high</em> -1.
</p>
<p>
Example: <code>write(random(1,7)+ " ")</code>
</p>
<p>
Example: <code>write(random(6)+ " ")</code>
</p>
</li>
<li>
repeat(<em>n</em>, <em>action</em>)
<p>
Allows a function <em>action</em> or group of actions to be repeated
<em>n</em> times.
</p>
<p>
Example: <code>repeat (4, function () {forward(10);right(90)})</code>
</p>
<p>
Example: <code>function el () {forward(10);right(90)}; repeat (4, el)</code>
</p>
</li>
<li>
wrap(<em>bool</em>)
<p>
Turns wrapping on and off at the edges of the graphic area by setting it
<em>true</em> or <em>false</em> respecitively.
</p>
<p>
Example: <code>wrap(true)</code>
</p>
<p>
Example: <code>wrap(false)</code>
</p>
</li>
<li>
animate(<em>action</em>,<em>ms</em>)
<p>
Evalutes <em>action</em> every <em>ms</em> milliseconds.
</p>
<p>
Example: <code>animate ("forward(10)",100)</code>
</p>
<p>
Example: <code>animate ("forward(100);right(90);",100)</code>
</p>
<p>
Example: <code>function el () {forward(100);right(90)}; animate (el,100)</code>
</p>
</li>
<li>
delay(<em>action</em>,<em>ms</em>)
<p>
Evalutes <em>action</em> after a delay of <em>ms</em> milliseconds.
</p>
<p>
Example: <code>delay ("forward(10)",1000)</code>
</p>
<p>
Example: <code>delay ("forward(100);right(90);",1000)</code>
</p>
<p>
Example: <code>function el() {forward(100);right(90); delay (el,100)};el()</code>
</p>
</li>
<!-- this can be done just by hiding the turtle
<li>
redrawOnMove(<em>bool</em>)
<p>
Turn redrawing on or off by specifying the <em>bool</em> as
<em>true</em> or <em>false</em>.
</p>
<p>
Example: <code>redrawOnMove(true)</code>
</p>
<p>
Example: <code>redrawOnMove(false)</code>
</p>
</li>
<li>
draw()
<p>
Draw the turtle and the current image.
</p>
<p>
Example: <code>draw()</code>
</p>
</li>
-->
<li>
n = minX()
<p>
Returns the minimum value of X of the current canvas in pixels.
</p>
<p>
Example: <code>write(minX())</code>
</p>
</li>
<li>
n = maxX()
<p>
Returns the maximum value of X of the current canvas in pixels.
</p>
<p>
Example: <code>write(maxX())</code>
</p>
</li>
<li>
n = minY()
<p>
Returns the minimum value of Y of the current canvas in pixels.
</p>
<p>
Example: <code>write(minY())</code>
</p>
</li>
<li>
n = maxY()
<p>
Returns the maximum value of Y of the current canvas in pixels.
</p>
<p>
Example: <code>write(maxY())</code>
</p>
</li>
</ul>
</article>
</body>
</html>