Introducing Turtle Graphics for MoI

Next
 From:  scott (SSHWARTS)
7515.1 
Hi All. On a whim I've written a turtle graphics script (working on top of the work of others). This script installs as a shortcut and when invoked, pops up a window where you can type (or paste) javascript.

Here's some examples. This script:

var sierpinski = function(n,length){
if(n == 0) return;
for(var i = 0; i < 3; ++i){
sierpinski(n-1,length/2);
move(length);
turn(-120);
}
}
sierpinski(7,200);

Yields:



Or this script:

var snowFlake = function(length, iterations){
turn(120);
koch(length, iterations);
turn(-120);
koch(length, iterations);
turn(-120);
koch(length, iterations);
}

var koch = function(length,iterations){
if(iterations==1)
move(length);
else{
koch(length, iterations-1);
turn(60);
koch(length, iterations-1);
turn(-120);
koch(length, iterations-1);
turn(60);
koch(length, iterations-1);
}
};
snowFlake(3,5);

Gets you:


This script:

for (var i = 0; i < 300; i++) {
move (i);
turn (100);
}

Gets you:




The commands are:

move(d); -- moves d units drawing a line
jump(d); -- jump d units without drawing
turn(a); -- turn 'a' degrees (CW)
pitch(a); -- pitch 'a' degrees downwards (CCW)
circle(d); -- draws a circle of d diameter at current position. Not turtle per se, but useful.
print(var); -- prints to the console useful for debugging

Currently, I do not join the line segments so you can end up with a lot of them. Let me know if it would be better to join them.
You can find some useful scripts to modify and use here: http://spencertipping.com/beta/cheloniidae-live-b1/
I based the commands on the ones used there and the examples come from there as well (note that there's no 'bank' command).

Enjoy and give some feedback or help me improve the script please. There's probably lots of bugs or better ways to do something. I wrote it to help me design some patterned panels to be lasercut.

Scott

EDITED: 26 Jul 2015 by SSHWARTS


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7515.2 In reply to 7515.1 
Cool stuff Scott, thanks for sharing it!

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Mike K4ICY (MAJIKMIKE)
7515.3 
Turtle was one my most favs when I was growing up. It was standard on the Apples at school but we had it at home on both our Timex Sinclair ZX81 (very rudimentary, and in BASIC) and Texas Instruments TI-99/4a
Can't really remember all of the commands now, but I remember doing some fantastic stuff.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  scott (SSHWARTS)
7515.4 
Slight revision. Turn(90) now turns to the right as it should. Added home() command to reset orientation and position.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Frenchy Pilou (PILOU)
7515.5 
Logo? ;)
---
Pilou
Is beautiful that please without concept!
My Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All