Thursday, December 4th, 2008

CanvasTurtle

Category: Canvas, JavaScript

Eiten Suez, author of jMatter, has been up to some fun hacking recently. He just released CanvasTurtle a JavaScript and Canvas version of the old favourite TurtlePascal.

You can build snow flakes with code like this:

javascript

  1. function side(size, level) {
  2.     if (level==0) {
  3.         fd(size);
  4.         return;
  5.     }
  6.     side(size/3, level-1);
  7.     lt(60);
  8.     side(size/3, level-1);
  9.     rt(120);
  10.     side(size/3, level-1);
  11.     lt(60);
  12.     side(size/3, level-1);
  13. }
  14.  
  15. function snowflake(size, level) {
  16.     (3).times(function() {
  17.         side(size, level);
  18.         rt(120);
  19.     });
  20. }
  21.  
  22.  
  23. clean();
  24. lt(30);
  25. setPos(0,-100);
  26. snowflake(250, 4);

Or a pretty garden like this.

Posted by Dion Almaer at 6:15 am
3 Comments

+++--
3.7 rating from 21 votes

3 Comments »

Comments feed TrackBack URI

Reminds me of the work by David Jones (drj11) on Curly Logo

Comment by TNO — December 4, 2008

Isn’t TurtlePascal just a copy of the original based on the Logo (Wikipedia). It’s what we used when I was in elementary school on Apple IIGS (or something like that). I’ve been wanting to make a tshirt based on it.

Comment by JonBad — December 4, 2008

Oooh, Eiten branching out towards js? This is an exciting start…

Comment by ilazarte — December 4, 2008

Leave a comment

You must be logged in to post a comment.