Turtle Programming v0.0.13: Support RGB, Add ShortCodes, Global Procedures Editor

in #utopian-io7 years ago (edited)

Introduction to Logo Turtle

LogoTurtle is currently the FIRST and 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.

repeat 18[repeat 4[repeat 18[fd 10 rt 5] rt 180]rt 20]
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]

image.png

Previous Contributions

v0.0.13 New Features

This Commit has the following changes:

  1. RGB Color Syntax
  2. Global Procedures Editor
  3. Aliases: print, pc, setpencolor, setsc, setscreencolor and label
  4. ShortCodes Defined: FillPolygon, Polygon and Fill Square
  5. UI Language: zh-tw.
  6. Add ClearConsole

Screenshots

Code/Procedures are prepended to your source code.
image.png

Random Walk with Color:

to randomwalk
ht cs
  repeat 100 [
  make "r parseInt(:random*255)
  make "g parseInt(:random*255)
  make "b parseInt(:random*255)
  pc [:r :g :b]
    make "r parseInt(:random*3)
    if :r==0 [fd 20]
    if :r==1 [rt 90 fd 20]
    if :r==2 [lt 90 fd 20]
  ]   
end
randomwalk

image.png

ShortCodes

// add a short function
_addShortCode(fun_name, parameters, body) {
    this.funs[fun_name] = [parameters, body];
}

// add some short funcs
loadShortCode() {
    this._addShortCode("polygon", ["corner", "len"], 
        "repeat :corner " + 
        "[fd :len rt 360/:corner]");
    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 dec :tmp]");
}

ShortCodes are pre-defined LOGO procedures for example: polygon is defined as

to polygon :corner :len
  repeat :corner [fd :len rt 360/:corner]
end

And you can just use it like a inbuilt command:

for [i 3 10] [polygon :i 50]

And, to fill a square, we need to draw a few smaller squares:

to fillsquare :size
   make "tmp :size
   repeat :size [ polygon 4 :tmp dec :tmp]
end

LOGO RGB Syntax Parser in Javascript

case "setpc":
case "pc":
case "setpencolor":
case "setcolor":
    if (word_next == '[') {
        find_next_body = getNextBody(s, i, U);
        if (find_next_body.right >= U) {
            this.pushErr(word, LOGO_ERR_MISSING_RIGHT);
            return false;
        }
        let rgb = s.substring(find_next_body.left + 1, find_next_body.right);
        let rgb_arr = rgb.split(' ').map(item => item.trim()).filter(x => x != '');
        if (rgb_arr.length != 3) {
            this.pushErr(word, LOGO_ERR_INVALID_RGB, rgb);
            return false;
        }
        let rgb_r = this.evalVars(rgb_arr[0]);
        let rgb_g = this.evalVars(rgb_arr[1]);
        let rgb_b = this.evalVars(rgb_arr[2]);
        this.logo.setLineColor("rgb(" + rgb_r + "," + rgb_g + ", " + rgb_b + ")");
        i = find_next_body.right + 1;
    } else {
        word_next = this.evalVars(word_next);
        if ((word_next === '') || (!isNumeric(word_next))) {
            this.pushErr(word, LOGO_ERR_MISSING_NUMBERS, word_next);
            return false;
        }
        this.logo.setPc(parseInt(word_next));
        i = y.next;
    }
    break;  

Roadmap of Chrome Extension: Logo Turtle

I believe LogoTurtle is more or less in beta now. Therefore, bug Fixes and any suggestions, please shout @justyy

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

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you very much

Hey @justyy I am @utopian-io. I have just upvoted you!

Achievements

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

I like your post because It has been approved.

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63657.90
ETH 2656.15
USDT 1.00
SBD 2.84