Turtle Programming v0.0.8: /* */ comments, dotxy, and javascript!

in #utopian-io8 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.

Previous Contributions

v0.0.8 New Features

Along with bug fixes and code tweaks, This Commit has added the support of the following features:

  1. Ignore Multi-line comments /* */ pairs like other high-level modern programming languages.
  2. dotxy takes two parameters that allow you to place a dot without moving the turtle anywhere.
  3. js that allows you to run the javascript code that handles the canvas directly!.

Screenshots

Classic Logo, Source code:

# Spiral 
/*
  draw a spiral
*/
cs
to spiral :size :angle
  if (:size>:T) [stop] ; size too big
  forward :size
  right :angle
  spiral :size+2 :angle 
end 
spiral 1 91 ; call the function

image.png

Drawing a line using dotxy

cs width 2 make "x 1 make "y 1
repeat 80 [
  dotxy :x :y 
  make "x :x+1 
  make "y :y+1
]

image.png

You can control the Turtle using Javascript via JS

cs js [
  for (let i = 0; i < 5; i ++ ) {
   this.logo.fd(100);
   this.logo.rt(144);
  }
]

image.png

Javascript Parser to Skip Comments, Whitespaces and New Lines

    // jump comments and white spaces
    skipTo(s, i, U) {
        // skip for white spaces and newlines
        while ((i < U) && (isSpace(s[i]) || s[i] == '\n')) {
            i ++;               
        }
        if (i >= U) { // reach block end
            return i;
        }
        // skip comments till the end
        if ((s[i] == ';') || (s[i] == '#')) {
            i ++;
            while ((i < U) && (s[i] != '\n')) {
                i ++;
            }
            i ++;
        }
        // skip // comments
        if (i + 1 < U) {
            if ((s[i] == '/') && (s[i + 1] == '/')) {
                i += 2;
                while ((i < U) && (s[i] != '\n')) {
                    i ++;
                }
                i ++;
            }
        }
        // skip /* */ comments
        if (i + 1 < U) {
            if ((s[i] == '/') && (s[i + 1] == '*')) {
                i += 2;
                while ((i < U) && ((s[i] != '*') || (s[i + 1] != '/'))) {
                    i ++;
                }
                i += 2;             
            }
        }       
        return i;   
    }

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. Sleep
  17. 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

Sort:  

nice!

没有看懂啥意思

Thank you for the contribution. It has been approved.

I will recommend you to put in more work in one contribution.

Thanks! :)

You can contact us on Discord.

[utopian-moderator]

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

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.074
BTC 63499.35
ETH 1673.21
USDT 1.00
SBD 0.41