-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
540 lines (464 loc) · 14.4 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
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
<html>
<head>
<meta charset="utf-8">
<title>Turtoga kids Graphics gr-v004c -200404 trimmed spaces</title>
<!--
Changes:
-v004c -200404 trimmed spaces -so eg fw_ will not be wrong (_=space)
-v004b 181120a - (tried) fixed default values if not give args
-->
</head>
<body style="padding: 0; margin: 0">
<canvas id="cnv" style="position: fixed; top: 0; left: 0">
</canvas>
<div id="consola" style="position: fixed; padding: 5px; width: 100%; height: 130px; bottom: 0px; background: #000; color: #4F4; font-size: 96pt; font-family: monospace; font-weight: bold; -webkit-box-shadow: 0px 0px 15px #000; -moz-box-shadow: 0px 0px 15px #000">
</div>
<div style="position: fixed; right: 0px; top: 0px; width: 32px; height: 32px">
<img src="info.png" onclick="showInfo();">
</div>
<div id="info" style="display: none; background: #000; color: #EEF; position: fixed; right: 0px; top: 0px; padding: 15px; font-family: tahoma, helvetica, sans; width: 30%; -webkit-box-shadow: 0px 0px 15px #000; -moz-box-shadow: 0px 0px 15px #000">
<div style="position: fixed; right: 0px; top: 0px; width: 32px; height: 32px">
<img src="cerrar.png" onclick="hideInfo();">
</div>
<h1><img src="tortuga.png" align="center" style="margin: 10px">Turtle kids Graphics</h1>
ΑΠΛΗ ΕΚΔΟΣΗ ΤΗΣ logo ΓΙΑ ΜΙΚΡΑ ΠΑΙΔΙΑ Η' ΆΤΟΜΑ ΜΕ ΠΡΟΒΛΗΜΑΤΑ ΌΡΑΣΗΣ!<br><br>
ΕΝΤΟΛΕΣ:
<ul>
<li><b>ΜΠΡΟΣΤΑ X ,ΜΠ χ ,FW</b>: ΜΠΡΟΣΤΑ Χ ΒΗΜΑΤΑ</li>
<li><b>ΠΙΣΩ X , ΠΙ Χ ,BW</b>: ΠΙΣΩ Χ ΒΗΜΑΤΑ</li>
<li><b>ΔΕΞΙΑ X , ΔΕ χ ,RT</b>: ΔΕΞΙΑ Χ ΜΟΙΡΕΣ</li>
<li><b>ΑΡΙΣΤΕΡΑ X, ΑΡ χ ,LT</b>: ΑΡΙΣΤΕΡΑ Χ ΜΟΙΡΕΣ</li>
<li><b>ΣΤΑ , ΑΟΡΑΤΟ-ΜΕΛΑΝΙ</b>: ΣΤΥΛΟ ΑΝΩ</li>
<li><b>ΣΤΚ , ΟΡΑΤΟ-ΜΕΛΑΝΙ</b>: ΣΤΥΛΟ ΚΑΤΩ</li>
<li><b>ΕΠΑΝΑΛΑΒΕ X</b>: ΠΧ ΕΠΑΝΑΛΑΒΕ 5 ΜΠ 10 ΔΕ 45</li>
<li><b>clr , ΚΑΘΑΡΙΣΜΟΣ</b>: Clear everything and start over</li>
</ul>
F11 - fullscreen.<br>
Σημείωση: εαν δεν βάλετε αριθμό θα θεωρηθεί ότι προχωράτε 100pixels ή στρίβετε 90 μοίρες<br>
Works on Google Chrome, Mozilla Firefox or any other standards compliant web browser.<br><br>
This tool was made with the intent to help young kids to be introduced in the art of programming.<br><br>
If you like it or find it useful you can donate with the button below.
All the proceedings will be used to help develop this tool further and help my older girl
(for whom i developed this tool, she hasn't one eye and the other has very low vision, so i decided to help her learn programming which doesn't need too much visual accuracy).<br><br>
<!--
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" align="center">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="2THMZGBMQUQN6">
<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
-->
Η Ελληνική έκδοση μπορεί να βρεθει εδώ : <a href="https://github.com/plirof/tortuga-kids-gr">github : tortuga-kids-gr</a>
All the code covered by the <a href="http://www.gnu.org/licenses/gpl.html">GPLv3 license</a>.<br><br>
Developed by John Villar.<br><br>
Twitter: <a href="http://twitter.com/johnvillarz">@johnvillarz</a><br>
E-mail: johnvillarzavatti [at] gmail [dot] com<br>
</div>
<script type="text/javascript">
var prompt = ">";
var linea = "";
var vieja_linea = "";
var tortuga = new Image();
var tortuga_m = {};
tortuga.src = "./tortuga.png"
tortuga.px = 0;
tortuga.py = 0;
tortuga.dx = 0;
tortuga.dy = 0;
tortuga.angulo = 90;
tortuga.dangulo = 90;
var historial = new Array();
var historial_pos = -1;
var cnv = document.getElementById('cnv');
var ctx = cnv.getContext('2d');
var consola = document.getElementById('consola');
var moduloDelta = 0.7;
var dibujar = true;
var intervaloAnim = null;
var intervaloRefresh = null;
var EPSILON = 0.00001;
function forward(a) {
var delta = new Number(a[0]);
if(isNaN(a[0])) {delta=new Number('100');} //jon test
var an = tortuga_m.angulo * Math.PI / 180;
tortuga_m.dx = tortuga_m.px + Math.cos(an)*delta;
tortuga_m.dy = tortuga_m.py - Math.sin(an)*delta;
var obj = {x: tortuga_m.dx, y: tortuga_m.dy, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function backwards(a) {
var delta = new Number(a[0]);
if(isNaN(a[0])) {delta=new Number('100');} //jon test 181120 to prevent turtle going to top corner if no arg is biven
var an = tortuga_m.angulo * Math.PI / 180;
tortuga_m.dx = tortuga_m.px - Math.cos(an)*delta;
tortuga_m.dy = tortuga_m.py + Math.sin(an)*delta;
var obj = {x: tortuga_m.dx, y: tortuga_m.dy, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function right_turn(a) {
var delta = new Number(a[0]);
if(isNaN(a[0])) {delta=new Number('90');} //jon test
tortuga_m.dangulo = tortuga_m.angulo - delta;
var obj = {x: tortuga_m.px, y: tortuga_m.py, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function left_turn(a) {
var delta = new Number(a[0]);
//alert(a[0]); //jon test
if(isNaN(a[0])) {delta=new Number('90');} //jon test
tortuga_m.dangulo = tortuga_m.angulo + delta;
var obj = {x: tortuga_m.px, y: tortuga_m.py, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function clear(a) {
pasoFigura = 0;
figura = new Array();
tortuga_m.px = 0;
tortuga_m.py = 0;
tortuga_m.angulo = 90;
tortuga_m.dx = 0;
tortuga_m.dy = 0;
tortuga_m.dangulo = 90;
dibujar = true;
var obj = {x: tortuga_m.dx, y: tortuga_m.dy, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function pen_up(a) {
dibujar = false;
var obj = {x: tortuga_m.px, y: tortuga_m.py, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
function pen_down(a) {
dibujar = true;
var obj = {x: tortuga_m.px, y: tortuga_m.py, a: tortuga_m.dangulo, t: dibujar};
figura.push(obj);
};
var commands = [
{nom: "ΜΠΡΟΣΤΑ", f: function (a) {
forward(a);
return a.slice(1);
}},
{nom: "ΜΠ", f: function (a) {
forward(a);
return a.slice(1);
}},
{nom: "FW", f: function (a) {
forward(a);
return a.slice(1);
}},
{nom: "ΠΙΣΩ", f: function(a) {
backwards(a);
return a.slice(1);
}},
{nom: "ΠΙ", f: function(a) {
backwards(a);
return a.slice(1);
}},
{nom: "BW", f: function(a) {
backwards(a);
return a.slice(1);
}},
{nom: "ΔΕΞΙΑ", f: function(a) {
right_turn(a);
return a.slice(1);
}},
{nom: "ΔΕ", f: function(a) {
right_turn(a);
return a.slice(1);
}},
{nom: "RT", f: function(a) {
right_turn(a);
return a.slice(1);
}},
{nom: "ΑΡΙΣΤΕΡΑ", f: function(a) {
left_turn(a);
return a.slice(1);
}},
{nom: "ΑΡ", f: function(a) {
left_turn(a);
return a.slice(1);
}},
{nom: "LT", f: function(a) {
left_turn(a);
return a.slice(1);
}},
{nom: "ΣΤΑ", f: function(a) {
pen_up(a);
return a;
}},
{nom: "ΑΟΡΑΤΟ-ΜΕΛΑΝΙ", f: function(a) {
pen_up(a);
return a;
}},
{nom: "ΣΤΚ", f: function(a) {
pen_down(a);
return a;
}},
{nom: "ΟΡΑΤΟ-ΜΕΛΑΝΙ", f: function(a) {
pen_down(a);
return a;
}},
{nom: "ΕΠΑΝΑΛΑΒΕ", f: function(a) {
var reps = new Number(a[0]);
var b = a.slice(1);
var c = new Array();
for (var i=0; i<reps; i++) {
c = c.concat(b);
}
for (var i=0; i<c.length; i++) {
if ((c[i] == "ΕΠΑΝΑΛΑΒΕ")&&(c.length>i+1)) {
c[i+1] = "" +(new Number(c[i+1])-1);
}
}
return c;
}},
{nom: "clr", f: function(a) {
clear(a);
return a;
}},
{nom: "cls", f: function(a) {
clear(a);
return a;
}},
{nom: "ΚΑΘΑΡΙΣΜΟΣ", f: function(a) {
clear(a);
return a;
}},
{nom: "ΚΟ", f: function(a) {
clear(a);
return a;
}},
{nom: "ΝΕΟ", f: function(a) {
clear(a);
return a;
}}
];
var figura = new Array();
var pasoFigura = 0;
cnv.left = 0;
cnv.top = 0;
cnv.width = window.innerWidth;
cnv.height = window.innerHeight;
window.addEventListener ("resize", function() {
cnv.width = window.innerWidth;
cnv.height = window.innerHeight;
}, true);
function actualizarConsola() {
//consola.innerText = prompt + linea.slice(Math.max(0, linea.length-16));
consola.textContent = prompt + linea.slice(Math.max(0, linea.length-16));
};
function moverA(x, y, ang) {
tortuga.px = x;
tortuga.py = y;
tortuga.angulo = ang;
};
function animarTortuga() {
if ((figura.length>0)&&(pasoFigura<figura.length)) {
var p0 = figura[pasoFigura];
tortuga.dx = p0.x;
tortuga.dy = p0.y;
tortuga.dangulo = p0.a;
dibujar = p0.t;
intervaloAnim = setInterval(function() {
var dx = tortuga.dx - tortuga.px;
var dy = tortuga.dy - tortuga.py;
var dang = tortuga.dangulo - tortuga.angulo;
tortuga.pendiente = true;
var eps = 0;
var destX = tortuga.px;
var destY = tortuga.py;
var destAng = tortuga.angulo;
if (dx*dx<EPSILON) {
tortuga.px = tortuga.dx;
eps++;
} else {
destX = tortuga.px + dx * moduloDelta;
}
if (dy*dy<EPSILON) {
tortuga.py = tortuga.dy;
eps++;
} else {
destY = tortuga.py + dy * moduloDelta;
}
if (dang*dang<EPSILON) {
tortuga.angulo = tortuga.dangulo;
eps++;
} else {
destAng = tortuga.angulo + dang * moduloDelta;
}
moverA(destX, destY, destAng);
if (eps >= 3) {
pasoFigura++;
if (pasoFigura < figura.length) {
tortuga.dx = figura[pasoFigura].x;
tortuga.dy = figura[pasoFigura].y;
tortuga.dangulo = figura[pasoFigura].a;
dibujar = figura[pasoFigura].t;
} else {
clearInterval(intervaloAnim);
}
}
}, 35);
}
};
function ejecutar(comando) {
comando=comando.trim();//added by jon fo fix extra space 200404
var ops = comando.split(" ");
var t = tortuga;
if (pasoFigura<figura.length-1) {
t = figura[figura.length-1];
t.px = t.x;
t.py = t.y;
t.dx = t.x;
t.dy = t.y;
t.angulo = t.a;
t.dangulo = t.a;
}
tortuga_m = {
px: t.px,
py: t.py,
dx: t.dx,
dy: t.dy,
angulo: t.angulo,
dangulo: t.dangulo
};
while (ops.length>0) {
var ejecuto = false;
for (var i=0; i < commands.length; i++) {
var cmd = commands[i];
if (cmd.nom.slice(0, ops[0].length).toUpperCase() == ops[0].toUpperCase()) {
ops = cmd.f(ops.slice(1));
tortuga_m.px = tortuga_m.dx;
tortuga_m.py = tortuga_m.dy;
tortuga_m.angulo = tortuga_m.dangulo;
ejecuto = true;
break;
}
}
if (!ejecuto) {
break;
}
}
animarTortuga();
}
function completarComando(comando) {
var ops = comando.split(" ");
if (ops.length>0) {
var com = ops[ops.length-1];
for (var i=0; i < commands.length; i++) {
var cmd = commands[i];
if (cmd.nom.slice(0, com.length).toUpperCase() == com.toUpperCase()) {
return (ops.slice(0, ops.length-1).join(" ") + " " + cmd.nom).trim()+" ";
}
}
}
return comando;
};
document.onkeydown = function(ev) {
if (ev.keyCode == 8) { // Borrar
if (linea.length>0) {
linea = linea.slice(0, linea.length-1);
actualizarConsola();
}
return false;
} else if (ev.keyCode == 13) { // Enter
if (linea.length>0) {
ejecutar(linea);
historial.push(linea);
historial_pos = historial.length;
linea = "";
actualizarConsola();
}
} else if (ev.keyCode == 38) { // Arriba
if (historial_pos == historial.length) {
vieja_linea = linea;
}
historial_pos--;
if (historial_pos<0) {
historial_pos = 0;
}
linea = historial[historial_pos];
actualizarConsola();
} else if (ev.keyCode == 40) { // Abajo
historial_pos++;
if (historial_pos<historial.length) {
linea = historial[historial_pos];
} else if (historial_pos==historial.length) {
linea = vieja_linea;
vieja_linea = "";
} else if (historial_pos>historial.length) {
historial_pos = historial.length;
}
actualizarConsola();
} else if (ev.keyCode == 37) { // Izquierda
} else if (ev.keyCode == 39) { // Derecha
} else if (ev.keyCode == 9) { // Tab
linea = completarComando(linea);
actualizarConsola();
return false;
}
};
document.addEventListener("kerydown", document.onkeydown, true);
document.onkeypress = function(ev) {
var ch = String.fromCharCode(ev.charCode);
if (((ch.trim().length>0)||(ch == " "))&& (ev.charCode != 0)) {
linea += ch;
actualizarConsola();
}
};
intervaloRefresh = setInterval(function() {
var cx = cnv.width / 2;
var cy = cnv.height / 2;
var tw = tortuga.width / 2;
var th = tortuga.height / 2;
ctx.fillStyle = "rgb(255, 255, 255)";
ctx.fillRect(0, 0, cnv.width, cnv.height);
ctx.fillStyle = "black";
ctx.lineWidth = 8;
ctx.beginPath();
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.moveTo(cx, cy);
var u = Math.min(figura.length-1, pasoFigura);
for (var i=0; i<u; i++) {
var obj = figura[i];
if (obj.t) {
ctx.lineTo(obj.x + cx, cy + obj.y);
} else {
ctx.moveTo(obj.x + cx, cy + obj.y);
}
}
if (u<figura.length) {
if (dibujar) {
ctx.lineTo(cx + tortuga.px, cy + tortuga.py);
} else {
ctx.moveTo(cx + tortuga.px, cy + tortuga.py);
}
}
ctx.stroke();
ctx.save();
ctx.translate(cx + tortuga.px, cy + tortuga.py);
ctx.rotate(-(tortuga.angulo-90) * Math.PI / 180);
ctx.drawImage(tortuga, -tw, -th);
ctx.restore();
}, 15);
function showInfo() {
var elem = document.getElementById("info");
elem.style.display = "block";
};
function hideInfo() {
var elem = document.getElementById("info");
elem.style.display = "none";
};
actualizarConsola();
</script>
<!-- TogetherJS Collaboration -->
<!-- example : URL should end in www.domain.com/index.html#&togetherjs=mysession01 -->
<script> /* 200331 -added by jon custom togetherjs hub*/
TogetherJSConfig_hubBase = "https://togetherjs-jj.glitch.me";//temp free server -not
TogetherJSConfig_suppressJoinConfirmation=true;
//TogetherJSConfig_toolName="dimotiko2";//Name to displey instead of togetherJS
</script>
<script DISABLEDsrc="https://togetherjs.com/togetherjs-min.js"></script>
</body>
</html>