Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyrocat101/logoscript
Unfancy Logo Programming Language.
https://github.com/pyrocat101/logoscript
Last synced: 3 months ago
JSON representation
Unfancy Logo Programming Language.
- Host: GitHub
- URL: https://github.com/pyrocat101/logoscript
- Owner: pyrocat101
- License: mit
- Created: 2012-05-19T17:50:13.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-02T23:59:11.000Z (over 10 years ago)
- Last Synced: 2024-04-15T02:48:59.326Z (9 months ago)
- Language: JavaScript
- Homepage: http://pyrocat101.github.io/LogoScript/
- Size: 544 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LogoScript
TL;DR: [Demo][demo]
[demo]: http://pyrocat101.github.io/LogoScript/
LogoScript is a dialect of Logo programming language with ECMAScript-like syntax.
[Logo][logo] is an educational language designed by Seymour Papert and Wally Feurzeig that has its root in LISP.[logo]: http://en.wikipedia.org/wiki/Logo_(programming_language)
Please check out my [post][blog-post] for an overview (in Chinese). Also take a look at code snippets in `examples/`.
# Showcase
The following code:
``` javascript
function getColor(theta) {
return round(abs(255 * cos(theta)));
}function width(angle, radius) {
seth2(radius * sin(angle), radius * cos(angle));
return 2 * (1.5 + sin(45 + 2 * geth()));
}function spiral(angle, twist) {
// Twisted Rose Curves
radius = 180 * sin(4 * angle);
angle = angle + 20 * sin(twist * angle);
setpw(width(angle, radius));
setpc('rgb(' + getColor(30 + 3 * angle) + ',0,255)');
setxy(radius * sin(angle), radius * cos(angle));
pd();
}clear('black');
pu();for (angle = 0; angle < 360; angle++) {
spiral(angle, 6);
}
```Produces the following image:
![rose](rose.png)
# Features
LogoScript is designed to be uber simple. However, it supports functions, recursion and a number of control structures. The built-in data type of LogoScript does not include array and dictionary due to the simplicity of implementation. Yet you can still draw fancy images without limit of the language.
# Implementation
The most part of LogoScript source code is written in CoffeeScript and is compiled into JavaScript(node.js). Note that it is only a toy language compiler, so I have barely applied any optimizations.
A parser is generated using peg.js to translate source code into AST (Abstract syntax tree), upon which two passes are adapted to convert AST into bytecode. Without complicated data type manipulation and closure support, the number of opcodes are less than 50.
The LogoScript bytecode runs on a stack-based virtual machine, where the expressions are evaluated. By calling built-in functions, which are backed up by Canvas API, our scripting language can draw image in the browser.
[blog-post]: http://pyroc.at/blog/2012/05/19/introducing-logoscript/