DEV Community

Cover image for Turtle graphics in JavaScript the goofball way
wiki-javascript
wiki-javascript

Posted on

Turtle graphics in JavaScript the goofball way

http://slicker.me/javascript/turtle.htm

Turtle graphics is available for example in Logo (since 1960s) and Python, but not in JavaScript.
Or is it? It dawned on me that context.rotate basically emulates 'turn left/right' and context.translate combined with moveTo/drawTo behaves just like 'move forward/back'.
This is definitely not an elegant or scalable way of programming graphics - kind of like tying your shoe with an earthworm: it looks cool, but only works in certain conditions. Just another gizmo in my collection of weird code. If you to play with real turtle graphics, I suggest you use one of the many available JS libraries, Python or Logo. Or at least create actual functions that move and rotate the turtle to make your code readable.

Top comments (0)