-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
238 lines (221 loc) · 11 KB
/
index.html
File metadata and controls
238 lines (221 loc) · 11 KB
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
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>line.script</title>
<base href="%BASE_URL%">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
</head>
<body>
<div id=app>
<div id=canvas_holder>
<canvas id=canvas></canvas>
</div>
<div id=devarea>
<div id=transport>
<button id=sfwd class=green title="Step once (Ctrl+Alt+Enter)">StepFwd</button>
<button id=play class=green title="Play animation (Ctrl+Enter)">Play</button>
<button id=pause class=yellow title="Pause animation (Ctrl+Enter)">Pause</button>
<button id=ffwd class=green title="Fast fwd to end (Ctrl+Shift+Enter)">FastFwd</button>
<button id=stop class=red title="Stop and reset (Ctrl+Esc)">Stop</button>
<div id=file>
<button id=load class=blue title="Save/Restore (Ctrl+O) (Ctrl+S to Save)">Load</button>
</div>
<div id=flags>
<button id=help class=as-link title="Help (Ctrl+?)">help</button>
|
<label for=trace title="Toggle Highlight current operation on/off (Shift+Alt+T)">
trace mode<input type=checkbox id=trace>
</label>
</div>
</div>
<textarea id=code cols=80 rows=25></textarea>
<div id=disk>
<nav id=save_menu>
<ul>
<li>
<button class=naked id=save></button>
</li>
</ul>
</nav>
<ul id=saves>
<li>
<span class=name></span>
<button class="naked save" title=Save>
<div role=presentation></div>
</button>
<button class="naked delete" title=Delete>
<div role=presentation></div>
</button>
</li>
</ul>
</div>
<pre id=out></pre>
</div>
<div id=useful_links style="display:none">
<a target=_blank rel=noreferrer href=https://github.com/mbolis/line.script title="Find me on GitHub">
<svg viewBox="0 0 438.549 438.549">
<path fill="currentColor" d="M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"></path>
</svg>
</a>
</div>
</div>
<template id="default_code">
// Rainbow Polygons, by mbolis
strafeLeft(30)
for (var n = 3; n <= 12; n++) {
color = hsl(360 / 12 * (n-3), 1, 0.5)
polygon(n, 20)
// strafeLeft(0.5) // uncomment for a more pleasant effect
}
background = "white"
hide()
function polygon(sides, size) {
var angle = 360 / sides;
for (var i = 0; i < sides; i++) {
forward(size)
right(angle)
}
}
function strafeLeft(distance) {
up()
left(90)
forward(distance)
right(90)
down()
}
</template>
<script type=module src=src/index.ts></script>
<dialog id=help_dialog>
<nav class=dialog-bar>
<button class=close>Close</button>
</nav>
<aside>
<h1 tabindex=-1 autofocus>line.script</h1>
<p>
This is a simulation of a triangular robot walking a paper plane while holding a pencil.
</p>
<p>
You can control the robot's movements by writing a JavaScript program, giving it instructions to draw whatever
you like!
</p>
<p>
Use the buttons in the top right bar (or the corresponding keyboard shortcuts) to play your program at different
paces, save it and restore previous saves.
</p>
<section>
<h2>Drawing functions:</h2>
<p>
Use these functions to control the robot.
</p>
<dl>
<dt>forward(steps: <em>number</em>)</dt>
<dd>Move forward <em>steps</em> number of units of movement, tracing a line on paper if the pencil is down.
</dd>
<dt>back(steps: <em>number</em>)</dt>
<dd>Move backwards <em>steps</em> number of units of movement, tracing a line on paper if the pencil is down.
</dd>
<dt>right(degrees: <em>number</em>)</dt>
<dd>Turn clockwise <em>degrees</em> number of degrees, leaving no trace on the paper.</dd>
<dt>left(degrees: <em>number</em>)</dt>
<dd>Turn counterclockwise <em>degrees</em> number of degrees, leaving no trace on the paper.</dd>
<dt>up()</dt>
<dd>Pick the pencil tip up from the paper, so that it will leave no trace on it.</dd>
<dt>down()</dt>
<dd>Put the pencil tip down on the paper, to resume tracing every time the robot moves.</dd>
<dt>hide()</dt>
<dd>Make the robot invisible.</dd>
<dt>show()</dt>
<dd>Make the robot visible again.</dd>
</dl>
</section>
<section>
<h2>Properties:</h2>
<p>
You can set these global properties to change the behavior and appearence of the simulation.
</p>
<p>
For example:
</p>
<div class=code-example>
<blockquote class=cm-s-default>
<span class=cm-variable>foreground</span> <span class=cm-operator>=</span> <span
class=cm-string>"red"</span>;
</blockquote>
</div>
<dl>
<dt>color: <em>color string</em></dt>
<dd>Set the color of the pencil.</dd>
<dt>foreground: <em>color string</em></dt>
<dd>Set the color of all the strokes on paper.</dd>
<dt>background: <em>color string</em></dt>
<dd>Set the color of the paper. Set to "transparent" to revert to the default background.</dd>
<dt>speed: <em>number</em></dt>
<dd>Set the robot's speed. Default speed is 100.</dd>
</dl>
</section>
<section>
<h2>Utility functions:</h2>
<p>
Miscellaneous utilities to interact with the user and the like.
</p>
<dl>
<dt>ask(question: <em>string</em>): <em>string</em></dt>
<dd>Show a prompt pop-up to the user, with <em>question</em>. Returns the text input by the user.</dd>
<dt>print(words...: <em>string[]</em>)</dt>
<dd>Print <em>words</em> (you can pass as many as you want) separated by spaces to the built-in output panel.</dd>
<dt>println(lines...: <em>string[]</em>)</dt>
<dd>Print <em>lines</em> (you can pass as many as you want) separated <strong>and</strong> followed by <em>newline</em> to the built-in output panel.</dd>
<dt>wait(seconds: <em>number</em>)</dt>
<dd>Wait for <em>seconds</em> (can be a decimal number) before the next instruction.</dd>
</dl>
</section>
<section>
<h2>Value functions:</h2>
<p>
Use these functions to produce some useful values to pass into other functions.
</p>
<dl>
<dt>random(min?: <em>number</em>, max?: <em>number</em>): <em>number</em></dt>
<dd>
Generate a pseudo-random number between <em>min</em> (included) and <em>max</em> (excluded).<br>
If only one argument is given, it will be interpreted as <em>max</em>: between 0 and <em>max</em>.<br>
If no arguments are given, between 0 and 1.</dd>
<dt>rgb(red: <em>number</em>, green: <em>number</em>, blue: <em>number</em>, alpha?: <em>number</em>):
<em>color string</em>
</dt>
<dd>Generate a color value, given its <em>red</em>, <em>green</em>, and <em>blue</em> components (valid values
from 0 to 255 included) and an optional <em>alpha</em> value (opacity, from 0 to 1, included).</dd>
<dt>hsl(hue: <em>number</em>, saturation: <em>number</em>, lightness: <em>number</em>, alpha?:
<em>number</em>): <em>color string</em>
</dt>
<dd>Generate a color value, given its <em>hue</em> (in degrees, unconstrained), and <em>saturation</em> and
<em>lightness</em> components (valid values from 0 to 1 included) and an optional <em>alpha</em> value
(opacity, from 0
to 1, included).
</dd>
</dl>
</section>
<section>
<h2>JavaScript objects:</h2>
<p>
Good old built-in objects straight from your browser.
</p>
<dl>
<dt>Math</dt>
<dd>Mathematical constants and functions (<a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math>find Math on MDN</a>)</dd>
<dt>JSON</dt>
<dd>Parse values from and convert values to JSON (<a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON>find JSON on MDN</a>)</dd>
<dt>Date</dt>
<dd>Represents a single moment in time (<a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date>find Date on MDN</a>)</dd>
<dt>RegExp</dt>
<dd>Match text with a pattern (<a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp>find RegExp on MDN</a>)</dd>
</dl>
</section>
</aside>
</dialog>
</body>
</html>