Skip to content

Welcome to jQuery turtle

davidbau edited this page May 2, 2013 · 9 revisions

CoffeeScript together with jQuery-turtle make a "LOGO for the Internet era".

Here is a complete working example that uses jquery turtle:

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//raw.github.com/davidbau/jquery-turtle/master/jquery-turtle.js"></script>
<script src="//raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"></script>
<script type="text/coffeescript">
eval($.turtle())

pen 'red'
for x in [1..4]
  lt 90
  fd 50

</script>
</head>
</html>

Explanation: The first line of the script, eval($.turtle()), initializes the (optional) interactive console and creates the (optional) default global turtle.

The rest of the script just draws a square with this global turtle: pen controls the color, lt turns left, fd moves forward. Indents are significant in CoffeeScript and punctuation is minimal.

Clone this wiki locally