LogoTurtle: Make Variables and Comments

Words
261
Reading
2 min
Listen
Play
9y

Introduction to Logo Turtle

LogoTurtle is the first and currently only one Chrome Extension for Turtle Graphics. I have also written a PHP version of Logo Interpreter in 2006 but that runs only on the server.

Previous Contributions

v0.0.4 New Features

This Commit supports the Make command which declares a variable in LOGO programming. Also, a single line comment starts with a semi-colon.

Screenshots

With variable support, you'll see how powerful the turtle is.
image.png

image.png

How to Store Variables in Javascript for Logo Turtle?

We use the dictionary to store a global key-pair values for variables. In future versions, it will be improved to support variables of different scopes.

Getter and Setter:

    // push a varaible
    addVar(name, value) {
        this.vars[name] = this.evalVars(value);
    }

    // find a variable
    getVar(name) {
        if (name in this.vars) {
            return this.vars[name];
        }
        return null;
    }

To evaluate the value of a expression:

    // eval variables
    evalVars(s) {
        let var_arr = parseVarName(s);
        let varlen = var_arr.length;
        for (let i = 0; i < varlen; ++ i) {
            let var_name = var_arr[i].substring(1);         
            let local = this.getVar(var_name);
            if (local) {                    
                s = s.replaceAll(":" + var_name, local);
                break;
            }
        }
        return s;
    }

where the parseVarName looks for :var

// parse var name
const parseVarName = (s) => {
    let pat = /(:[a-zA-Z]+[a-zA-Z0-9]*)/g;
    let arr = [];
    let matches;
    while (matches = pat.exec(s)) {
        arr.push(matches[1]);       
    }
    return arr;
}

Roadmap of Chrome Extension: Logo Turtle

  1. Add Functions
  2. Add IF/THEN/ELSE
  3. Add Variables
  4. Add Colors
  5. Add MoveTo
  6. Add PrintText
  7. Add Circle
  8. Add Arc
  9. Add Eraser
  10. Add Fill
  11. Save As Picture
  12. Save As Program
  13. Comments
  14. Add Recursion Support
  15. Add Global/Local Scopes
  16. etc. etc.

Technology Stack

If an App can be written in Javascript, eventually it will be written in Javascript.

Chrome Webstore

Install the Turtle Programming for Kids Now!

Contribution Welcome

Github: https://github.com/DoctorLai/LogoTurtle

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.



Posted on Utopian.io - Rewarding Open Source Contributors

LogoTurtle: Make Variables and Comments | Ecency