Example Turtle Graphic Programs

The next two examples are from Maximilian Zollbrecht:

    COLOR 1 0 0;

    VAR corners=4, size=100, angle=360/corners+0.5;
    WHILE size>0 
        BEGIN
        GO size;
        TURN angle;
        size = size-0.5;
        END

   
    COLOR 0 1 0;

    VAR corners=6, size=200, angle=360/corners+0.5;
    WHILE size>0 
        BEGIN
        GO size;
        TURN angle;
        size = size-0.5;
        END

The next two examples are from Leo Balduf:

 
COLOR 1 0 0;

VAR x;
VAR y;
VAR startx;
VAR var;

EAST;
TURN -15;
startx = 7;
x = startx;
WHILE x > 0 
BEGIN
    y = 100;
    var = abs ((startx/2 + 0.5) - x);
    WHILE y > 0 
    BEGIN   
        TURN 30 * cos (y/100*(2*pi));
	GO var;
        GO 5;
        y = y - 1;
    END

    x = x-1;
END

   
COLOR 0.5 0 1;
POSITION 100 100;

// Different values for startx produce different, nice images.
// Higher values for startx tend to produce bigger images.

VAR x;
VAR y;
VAR startx;
VAR var;

startx = 3;
x = startx;
EAST;
TURN -101*(startx/2+0.5-(startx*(startx+1)/2))/2;
WHILE x > 0 
BEGIN
    y = 100;
    var = abs ((startx/2 + 0.5) - x);
    WHILE y > -1 BEGIN
        TURN 30 * cos (y/100*(2*pi));
	TURN var;
	GO var;
        GO 5;
        y = y - 1;
    END

    x = x-1;
END

Some more recursive examples.

The Dragon curve:
PROCEDURE left(level, dist)
{ IF (level < 1) THEN GO dist;
  ELSE {
    TURN 45; left(level-1,dist/sqrt 2);
    TURN -90; right(level-1,dist/sqrt 2); TURN 45;
  }
}

PROCEDURE right(level, dist)
{ IF (level < 1) THEN GO dist;
  ELSE {
    TURN -45; left(level-1,dist/sqrt 2);
    TURN 90; right(level-1,dist/sqrt 2);
    TURN -45;
  }
}

left(14,300);

The Koch Snowflake:
PROCEDURE koch(level, dist)
{ IF (level < 1) THEN GO dist;
  ELSE 
  { koch (level-1,dist/3);
    TURN -60;
    koch (level-1,dist/3);
    TURN 120;
    koch (level-1,dist/3);
    TURN -60;
    koch (level-1,dist/3);
  }
}

UP; NORTH; GO 100;EAST; GO 100; DOWN;

koch (0,400); TURN 120;
koch (1,400); TURN 120;
koch (2,400); 

UP; NORTH; GO 400;EAST; DOWN;

koch (4,200); TURN 120;
koch (4,200); TURN 120;
koch (4,200); 

The Cesaro curve
PROCEDURE cesaro(level, dist, angle)
{ IF (level < 1) THEN GO dist;
  ELSE 
  { cesaro (level-1,dist/2, angle);
    TURN angle;
    cesaro (level-1,dist/2, angle);
    TURN -2*angle;
    cesaro (level-1,dist/2, angle);
    TURN angle;
    cesaro (level-1,dist/2, angle);
  }
}

cesaro (7,400,85); 

Rekursive plants ...
PROCEDURE tree(level, dist, angle, shrink)
{ IF (0 < level ) THEN
  { TURN -angle/2;
    GO dist;
    tree(level-1,dist*shrink,angle,shrink);
    TURN 180;
    GO dist;
    TURN 180+angle;
    GO dist;
    tree(level-1,dist*shrink,angle,shrink*9/10);
    TURN 180;
    GO dist;
    TURN 180 - angle/2;
  }
}

tree(11,50,35,9/10); 

The Quad curve:
PROCEDURE quad(level, dist, angle)
{ IF (level < 1) THEN GO dist;
  ELSE 
  { quad (level-1,dist/3, angle);
    TURN angle;
    quad (level-1,dist/3, angle);
    TURN -angle;
    quad (level-1,dist/3, angle);
    TURN -angle;
    quad (level-1,dist/3, angle);
    TURN angle;
    quad (level-1,dist/3, angle);
  }
}

quad (6,400,90);