Skip to content

Commit

Permalink
v0.0.14. Bug Fixes, Add Status Bar (Show Last Error), repcount
Browse files Browse the repository at this point in the history
  • Loading branch information
SteakOverCooked authored and SteakOverCooked committed May 2, 2018
1 parent 3edd3b6 commit e33d654
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 14 deletions.
3 changes: 2 additions & 1 deletion css/main.css
Expand Up @@ -4,4 +4,5 @@
#turtle {position: absolute; top; 0; left: 0; width: 20px; height: 20px;}
.canvas {position: relative; top; 0; left: 0;}
textarea {resize: none;}
pre {width: 99%;}
pre {width: 99%;}
img.banner {height:70px;}
Binary file added images/linode.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/vultr.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion js/logo.js
Expand Up @@ -33,7 +33,10 @@ document.addEventListener('DOMContentLoaded', function() {
let canvas = document.getElementById('logo');
let logo = new LogoCanvas(canvas, $('#turtle'));
let log = $('textarea#about');
let logoparser = new LogoParser(logo, log);
let status = $('div#status');
let logoparser = new LogoParser(logo, log, status);
// update status
logoparser.updateStatus();
$('button#run').click(function() {
let s = "";
s += $('textarea#procedures').val().trim();
Expand All @@ -52,6 +55,8 @@ document.addEventListener('DOMContentLoaded', function() {
}
// save the source code
saveSettings(false);
// update status
logoparser.updateStatus(err);
});
$('textarea#console').keydown(function (e) {
if (e.ctrlKey && e.keyCode == 13) {
Expand Down
52 changes: 45 additions & 7 deletions js/logoparser.js
Expand Up @@ -2,16 +2,27 @@

class LogoParser {
// needs a Logo Object
constructor(logo, console) {
constructor(logo, console, status) {
this.logo = logo;
this.console = console;
this.status = status;
this.clearWarning();
this.clearErr();
this.vars = {};
this.funs = {};
this.funs = {};
this.loadShortCode();
}

// update status
updateStatus(text = "") {
let msg = "";
msg += "(" + this.logo.getX().toFixed(3) + ", " + (-this.logo.getY()).toFixed(3) + "), ";
msg += "∠: " + (this.logo.getAngle() % 360).toFixed(3) + ", ";
msg += this.logo.isPendown() ? "Pendown" : "Penup";
msg += " " + this.getLastErr(text);
this.status.html(msg);
}

// add a short function
_addShortCode(fun_name, parameters, body) {
this.funs[fun_name] = [parameters, body];
Expand All @@ -22,12 +33,21 @@ class LogoParser {
this._addShortCode("polygon", ["corner", "len"],
"repeat :corner " +
"[fd :len rt 360/:corner]");
this._addShortCode("star", ["len"],
"repeat 5 " +
"[fd :len rt 144]");
this._addShortCode("tri", ["n"],
"repeat 3 " +
"[fd :n rt 120]");
this._addShortCode("cube", ["n"],
"repeat 6 " +
"[tri :n rt 60]");
this._addShortCode("fillsquare", ["size"],
"make \"tmp :size repeat :size " +
"[polygon 4 :tmp dec :tmp]");
this._addShortCode("fillpolygon", ["corner", "size"],
"make \"tmp :size repeat :size " +
"[polygon :corner :tmp-1 dec :tmp]");
"[polygon :corner :tmp dec :tmp]");
}

// push a varaible
Expand Down Expand Up @@ -72,6 +92,18 @@ class LogoParser {
}
}

// get last err
getLastErr(error) {
error = error || this.error;
error = error.trim();
let arr = error.split("\n");
console.log(arr);
if (arr.length > 0) {
return arr[arr.length - 1].trim();
}
return "";
}

// add a warning
pushWarning(cmd, x, word = '') {
if (word) {
Expand All @@ -86,7 +118,7 @@ class LogoParser {
this.vars['RANDOM'] = Math.random();
this.vars['turtlex'] = this.logo.getX();
this.vars['turtley'] = this.logo.getY();
this.vars['turtleangle'] = this.logo.getAngle();
this.vars['turtleangle'] = this.logo.getAngle();
}

// eval variables
Expand Down Expand Up @@ -245,7 +277,7 @@ class LogoParser {
this.pushErr(word, LOGO_ERR_EVAL, expr);
return false;
}
if ((second_word_word == '') || (!isNumeric(second_word_word))) {
if ((second_word_word === '') || (!isNumeric(second_word_word))) {
this.pushErr(word, LOGO_ERR_MISSING_NUMBERS, second_word_word);
return false;
}
Expand Down Expand Up @@ -445,7 +477,7 @@ class LogoParser {
this.pushErr(word, LOGO_ERR_EVAL, expr);
return false;
}
if ((second_word_word == '') || (!isNumeric(second_word_word))) {
if ((second_word_word === '') || (!isNumeric(second_word_word))) {
this.pushErr(word, LOGO_ERR_MISSING_NUMBERS, second_word_word);
return false;
}
Expand All @@ -468,7 +500,7 @@ class LogoParser {
this.pushErr(word, LOGO_ERR_EVAL, expr);
return false;
}
if ((second_word_word == '') || (!isNumeric(second_word_word))) {
if ((second_word_word === '') || (!isNumeric(second_word_word))) {
this.pushErr(word, LOGO_ERR_MISSING_NUMBERS, second_word_word);
return false;
}
Expand Down Expand Up @@ -645,6 +677,9 @@ class LogoParser {
for_step = parseInt(for_step);
// beware of endless loop ^_^
for (let for_loop = for_start; for_loop <= for_stop; for_loop += for_step) {
// update repeat count
this.addVar('repcount', for_loop - for_start + 1);
this.addVar('REPCOUNT', for_loop - for_start + 1);
if (for_var != "") {
this.vars[for_var] = for_loop;
}
Expand Down Expand Up @@ -801,6 +836,9 @@ class LogoParser {
this.pushWarning(word, LOGO_ERR_MISSING_RIGHT);
}
for (let i = 0; i < word_next; ++ i) {
// update repeat count
this.addVar('repcount', i + 1);
this.addVar('REPCOUNT', i + 1);
// recursive call repeat body
if (!this.run(s, repeat_left, find_right, depth + 1)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions js/translate.js
Expand Up @@ -21,6 +21,7 @@ const translation = (lang) => {
translate_text($('a#report_bugs'), lang, 'report_bugs');
translate_text($('h4#supported_commands'), lang, 'supported_commands');
translate_text($('h4#examples'), lang, 'examples');
translate_text($('h4#global_vars'), lang, 'global_vars');
translate_text($('div#chess_board'), lang, 'chess_board');
translate_text($('div#frac_star'), lang, 'frac_star');
translate_text($('button#setting_save_btn'), lang, 'save');
Expand Down
1 change: 1 addition & 0 deletions lang/en-us.js
@@ -1,6 +1,7 @@
'use strict';

let translation_english = {
'global_vars': 'Global Variables',
'source_code': 'Source Code',
'text_procedures': 'Global Procedures',
'frac_star': 'Fractal Stars',
Expand Down
1 change: 1 addition & 0 deletions lang/zh-cn.js
@@ -1,6 +1,7 @@
'use strict';

let translation_simplified_chinese = {
'global_vars': '全局变量',
'source_code': '源代码',
'text_procedures': '全局方法',
'frac_star': '分形五角星',
Expand Down
1 change: 1 addition & 0 deletions lang/zh-tw.js
@@ -1,6 +1,7 @@
'use strict';

let translation_traditional_chinese = {
'global_vars': '全局變量',
'source_code': '源代碼',
'text_procedures': '全局方法',
'frac_star': '分形五角星',
Expand Down
28 changes: 24 additions & 4 deletions main.html
Expand Up @@ -137,6 +137,15 @@ <h4 id='examples'>Examples</h4>
repeat 18[repeat 18[repeat 4[repeat 18[fd 10 rt 5] rt 160]rt 20] rt 20]
repeat 4[repeat 9[repeat 4[repeat 9[fd 25 rt 10] repeat 9[ fd 25 lt 10] rt 160] lt 40] rt 90]
</pre></li>
<li><pre>
repeat 100 [fd :repcount*3 rt 90]
</pre></li>
<li><pre>
repeat 36[repeat 36[fd 10 pu fd 10 pd rt 10]lt 10]
</pre></li>
<li><pre>
repeat 72[repeat 4[repeat 4[fd 10 pu fd 20 pd fd 10] rt 90]lt 5]
</pre></li>
</ul>
<h4 id='supported_commands'>Support Commands</h4>
<ul>
Expand Down Expand Up @@ -174,9 +183,8 @@ <h4 id='supported_commands'>Support Commands</h4>
<li>PENERASE, PE</li>
<li>PENPAINT, PPT</li>
<li>WAIT</li>
<li>PC, SETPC, SETCOLOR, SETPENCOLOR/li>
<li>PC, SETPC, SETCOLOR, SETPENCOLOR</li>
<li>PRINT, CONSOLE</li>
<li>:RANDOM</li>
<li>WHILE</li>
<li>DO/ELSE</li>
<li>FOR</li>
Expand All @@ -185,6 +193,14 @@ <h4 id='supported_commands'>Support Commands</h4>
<li>CLEAR</li>
<li>CLEARCONSOLE</li>
</ul>
<h4 id="global_vars">Global Variables</h4>
<ul>
<li>:random</li>
<li>:repcount</li>
<li>:turtlex</li>
<li>:turtley</li>
<li>:turtleangle</li>
</ul>
</div>
<div id="tabs-log">
<h4><span id='proudly_brought_to_you_by'>Proudly brought to you by</span> <a target=_blank href="https://steemit.com/@justyy">@justyy</a> (<a target=_blank id='report_bugs' href="https://steakovercooked.com/Contact.Mail?title=LogoTurtle">Report Bugs</a>)
Expand All @@ -195,9 +211,13 @@ <h5>
<textarea readonly class='form-control' rows=15 id='about'>
</textarea>
<BR/>
<a target=_blank href='https://www.paypal.me/doctorlai/3'><img src='images/paypal.png' style='height: 70px'></a> &nbsp;
<a target=_blank href='https://justyy.com/out/bitcoin'><img src='images/bitcoin.jpg' style='height: 70px'></a>
<a target=_blank href='https://www.paypal.me/doctorlai/3'><img src='images/paypal.png' class='banner'></a> &nbsp;
<a target=_blank href='https://justyy.com/out/bitcoin'><img src='images/bitcoin.jpg' class='banner'></a>
<a target=_blank href='https://justyy.com/out/vultr2'><img title='Free $10 VPS' src='images/vultr.jpg' class='banner'></a>
&nbsp;
<a target=_blank href='https://justyy.com/out/linode'><img title='Free $20 VPS' src='images/linode.jpg' class='banner'></a>
</div>
</div>
<div id="status"> </div>
</body>
</html>
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -3,7 +3,7 @@
"name": "Logo Turtle",
"short_name": "LogoTurtle",
"default_locale": "en",
"version": "0.0.13",
"version": "0.0.14",
"offline_enabled": true,
"browser_action": {
"default_icon": "icon.png",
Expand Down

0 comments on commit e33d654

Please sign in to comment.