-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
294 lines (233 loc) · 6.34 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link href='app.css' rel='stylesheet' type='text/css'>
<script src="vendor/core.min.js" type="text/javascript" charset="utf-8"></script>
<script src="vendor/shortcut.js" type="text/javascript" charset="utf-8"></script>
<script src="helpers.js" type="text/javascript" charset="utf-8"></script>
<title>TurtleJS</title>
</head>
<body>
<div id="__toolbar">
<span class="title">TurtleJS 0.1.0</span>
<a id='githubLink' href="https://github.com/sequentialread/TurtleJS">Github</a>
<span class="green button" id="__runButton">Run</span>
<span class="blue button" id="__helpButton">Help</span>
</div>
<pre id="__editor">
</pre>
<svg id="__stage" viewbox="-250 -250 500 500">
</svg>
<div id="__consoleBar">
</div>
<div id="__console" style="display:none">
<span>Console</span>
<span class="blue button" id="__closeConsoleButton">Close</span>
<span class="blue button" id="__clearLogsButton">Clear</span>
<div id="__consoleContainer" style="margin-top:30px;">
</div>
</div>
<div id="__loadingScreen" style="display:none">
<span class="title">Running your code...</span>
</div>
<div id="__mdnIframeContainer" style="display:none">
<div class="flexbox-container">
<div class="flexbox-row">
<span class="title-small" id="__mdnIframeTitle"></span>
<span class="blue button" id="__closeMdnButton">Close</span>
<hr/>
<button id="__mdnIframeBackButton" disabled="true"><</button>
<input type="text" id="__mdnIframeUrlBar" value="" readonly>
</div>
<iframe id="__mdnIframe"></iframe>
</div>
</div>
<div id="__helpContainer" style="display:none">
<span class="title">Quick Help</span>
<span id="__hotkeyHelp" style="position:relative; left:4%">
</span>
<span class="blue button" id="__closeHelpButton">Close</span>
<hr/>
<div class="container">
<pre id="__helpContent1" class="helpContent">
// this is a comment. not code.
// here's how to move the turtle:
forward(50);
right(90);
left(90);
// reset the position and rotation
// of the turtle:
home();
// tell it when to draw and when not to draw:
penUp();
forward(50);
penDown();
// change the color of the line:
// (using a CSS3 color definition)
pushColor('red');
pushColor('rgba(255,0,0,0.5)');
pushColor('#BEEEEF');
pushColor('none');
// reset the color to what it was before:
popColor();
// change the fill color of the shape:
// (using a CSS3 color definition)
pushFillColor('gray');
...
popFillColor();
// change the width of the line:
// (in pixels)
pushWidth(2);
...
popWidth();
// change the opacity of the shape/line:
// (from zero to one)
pushOpacity(0.5);
...
popOpacity();
// position the shape/line over or under:
pushLayer(5);
...
popLayer();
</pre>
<pre id="__helpContent2" class="helpContent">
// define a variable:
var distance = 50;
// use a variable:
forward(distance);
// define a function:
function moveForward50 () {
forward(50);
}
// call a function:
moveForward50();
// display something for debugging:
console.log(distance);
// make a decision:
if(distance > 30) {
console.log('distance is '
+ 'greater than 30');
} else {
console.log('distance is '
+ 'less than or equal to 30');
}
// functions can have parameters:
function moveAndTurn (dist, rot) {
forward(dist);
right(rot);
}
moveForwardAndTurn(50, 90);
//loop over the same code n times
var n = 5;
while(n > 0) {
n = n - 1;
console.log('memememememememe');
}
// this infinite loop will crash:
var n = 5;
while(n > 0) {
console.lag('memememememememe');
}
// this is a shortcut for loops.
// it's harder to cause an infinite loop
// this way. it uses the form:
// for(initializer; condition; incrementer)
for(var i = 0; i < 4; i++) {
forward(50);
right(90);
}
// this is a recursive function.
// it calls itself, which calls itself again.
// also capable of crashing if done wrong.
function abacabadabacaba (letters, depth) {
// if not provided with a depth argument,
// default to zero.
if(depth === undefined) depth = 0;
var newDepth = depth+1;
var letter =
letters[letters.length-newDepth];
if(newDepth == letters.length) {
// we are at our last step,
// so don't recurse any more.
return letter;
} else {
// we need to go deeper
var eitherSide =
abacabadabacaba(letters, newDepth);
return eitherSide + letter + eitherSide;
}
}
// to log 'abacabadabacaba':
console.log(abacabadabacaba(
['a', 'b', 'c', 'd']
));
//guess what this will do?
console.log(abacabadabacaba(
['a', 'b', 'c', 'd', 'f']
));
</pre>
<pre id="__helpContent3" class="helpContent">
// this is a string of characters
var greeting = 'Hello World!';
// HELLO WORLD!
var entusiasticGreeting =
greeting.toUpperCase();
// these are number
var coolnessAmount = -5;
var pi = 3.14;
// to increase your coolness,
// you can assign it a new value
coolnessAmount = (coolnessAmount + 3);
// this is a shortcut for the same statement
coolnessAmount += 3;
// testing whether things are equal is
// different from assigning a value.
// the following will run, but it will
// assign 3 instead of testing for 3
if(coolnessAmount = 3) {
...
}
//you really want:
if(coolnessAmount == 3) {
}
// this is an Array
var shoppingList = [
'apples',
'oranges',
'bananas'
];
var emptyList = [];
var otherEmptyList = new Array();
// this is an object:
var sonic = {
speed: Infinity,
rings: 1,
increaseSpeed: function(amount) {
this.speed += amount;
}
};
//you can get and set most object properties.
sonic.rings = 4;
console.log('sonic is going '
+ sonic.speed + ' miles per hour with '
+ sonic.rings + ' rings');
//even functions can be treated like values.
//and the functions 'remember' the state of
//outside variables when they were created.
//this is one of javascript's core features.
var speedMultiplier = 5;
sonic.increaseSpeed = function (amount) {
this.speed += amount * speedMultiplier;
}
</pre>
</div>
</div>
<script src="vendor/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="app.js" type="text/javascript" charset="utf-8"></script>
<script src="mdnSearch.js" type="text/javascript" charset="utf-8"></script>
<script src="ui.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>