header

 

More links

AutoHotkey | Android | Arduino | COMM140Fractals | Grammar Checkers | Knots | A Million Dots Activity |  Processing | Processing for Scratch Users | Redbubble | Tutorials | Weather | World Time Meeting Planner | Favicon Generator.

Home > MicroWorlds Logo (Turtle Graphics) Links & Examples > Examples >Turtle Graphics Examples

Turtle Graphics Examples

The following programs are a collection of examples most of which I have created for my own amusement or as
teaching aids. You are welcome to download copies and play with them. You may also place copies on your website as long as you add a link to this page and e-mail me details of where you are using them.

If you switch to the procedures page using Ctrl + F or Pages | Procedures you will see that most of these examples use procedures. if the example has no procedures then right click on the turtle and see if there is any code programmed directly into the turtle.

Colours can also have code associated with them. Click on the Paint Brush button to view the colour pallet.
any colours with a black dot in the center of the colour has logo code programmed into it. Double click on the colour to view the associated code.Note: these example programs are written using MicroWorlds Version 2.05

 

The Following MicroWorlds programs are free software; you can redistribute and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

These programs are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

random-lines.mw2 428 KB
random-lines.zip 127KB Ziped with Winzip  from www.winzip.com use winzip to unzip
random-lines.exe 188 KB
Get MicroWorlds Web Player Plugin version
GNU License.txt

In this example each turtle is programmed directly.

Simple programs like this do not require writing procedures.

This is an interesting example as it produces images that have a fractal nature not unlike the worl of Jackson Pollock. see: Fractal Expressionism
http://materialscience.uoregon.edu/taylor/art/info.html

house&sun.mw2 30 KB
house&sun.zip 14 KB Ziped with Winzip  from www.winzip.com use winzip to unzip
house&sun.exe 76 KB
Get MicroWorlds Web Player Plugin version
GNU License.txt

Draws a house with a sunrise

MicroWorlds fun3

fun3.mw2 94 KB
fun3.zip 27.KB Ziped with Winzip  from www.winzip.com use winzip to unzip
fun3.exe 88 KB
Get MicroWorlds Web Player Plugin version
GNU License.txt

An example of using sliders to change variables

to fun3
   pd
   repeat rep [
      lt sharp      
; sharp is set from a slider
      fd scale      
; scale is set from a slider 
      rt sharp
      fd scale
      rt 360 / rep
    ]      

end

MicroWorlds Chaos

A example of using the random function

chaos.mw2 229 KB

Get MicroWorlds Web Player Plugin version

to filler_t
   ht             ; hide turtle for faster drawing
   pu             ; do not draw lines
   fd random 70   ; forward a random number of steps
    rt random 30    ; right turn a random number of
                  ; degrees from 0 to 30

  setc random 50  ; set the fill colour to a random value
   fill               ; fill with the random colour
end

to lines_t
   pd setc "black  ; draw with black lines
   fd random 70     ; forward a random number of steps
   rt random 30     ; right turn a random number of
                   ; degrees from 0 to 30

end

MicroWorlds tours.zip

torus.mw2 11KB
torus.zip 27 KB
torus.exe 88KB

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

Draws a torus consisting of 180 circles.

MicroWorlds poster1.zip page 1
MicroWorlds poster1.zip page 2
MicroWorlds poster1.zip page 3

poster1.zip 30KB Ziped with Winzip  from www.winzip.com use winzip to unzip

to fun3 :rep :step :deg
   snapshot ; takes a picture of the screen
            ; use restore to restore the            
            ; screen to the snapshot version
   pd
   repeat :rep [lt :deg
     fd :step
     rt :deg
     fd :step
     rt 360 / :rep]
end

MicroWorlds dothing.zip

dothing.zip 10KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Just a thing.

This example uses sliders to pass values to a procedure.

MicroWorlds example1.zip page 1

MicroWorlds example1.zip page 2

MicroWorlds example1.zip page 3

MicroWorlds example1.zip page 4

MicroWorlds example1.zip page 5

example1.zip 5 KB Ziped with Winzip  from www.winzip.com use winzip to unzip

example1.mw2 62 KB

A collection of examples to use when introducing MicroWorlds

MicroWorlds polyspiral.zip

polyspiral.zip 7KB Ziped with Winzip  from www.winzip.com use winzip to unzip

A Polyspiral

MicroWorlds squares.zip

squares.zip 7KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Squares

Original idea from:
Abelson, H. (1982). Apple Logo. Peterborough, NH: BYTE/McGraw-Hill.

to square :size              ; draw a square with sides
                             ; :size long
  pd                         
  repeat 4 [ fd :size rt 90] ;repeat 4 times                              ; moving forward                              ; and turning right
end

to go :number_of_times :size
  repeat :number_of_times
    [square :size            ; draw a square with sides                              ; :size long

    make "size :size + 2    ; make the size of :size 2 step bigger
    rt 15]                  
; turn to the right 15 degrees
                           
; between each square
end

MicroWorlds art1.zip

art1.zip 36KBZiped with Winzip  from www.winzip.com use winzip to unzip

See: Art2 below

An example of playing with drawing "brushes"

 

MicroWorlds target.zip

target.zip 5KB Ziped with Winzip  from www.winzip.com use winzip to unzip

to target

   ; ----- Note the values for the angles eg
   ;       1.9, 1.27, 0.958 etc were determined by
   ;       trial and error. If you know a better
   ;       way to do this can you please let me know.

   cg
   setpensize 1
   ht ; hide the turtle for faster results
   concentric 30  1.9   "red
   concentric 45  1.27  "lime
   concentric 60  0.958 "lime
   concentric 75  0.762 "red
   concentric 90  0.635 "red
   concentric 105 0.545 "lime
   concentric 120 0.478 "red
end

to concentric :size :angle :colour
  pu
  home
  fd :size
  rt 90
  pd
  setc :colour      ; use set colours
  ; setc random 500 ; use random colours
  repeat 360 / :angle [ fd 1 rt :angle]
  fill_circle
end

Draws a series of concentric circles each filled with colour

MicroWorlds Electro Lights

circles4.zip 4KB Ziped with Winzip  from www.winzip.com use winzip to unzip

To reproduce the type of patterns created by "Electro Lights" #02820

Produced by Maui Toys www.MauiToys.com made in China

;Note this is still a work in progress.
;version 0.2

MicroWorlds Etch-a-sketch

etch-a-sketch2.zip 4KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Etch-a-sketch

a work in progress

MicroWorlds Circle

circles1.zip 8KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

MicroWorlds Circle

circles2.zip 4KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Note this version of circles1.zip uses:

talkto [t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36]
repeat 30 [fd 4]

instead of:

everyone [repeat 30 [fd 4]]

because each turtle moves forward at the same time. Using everyone [repeat 30 [fd 4]] moves each turtle one after the other which spoils the effect.

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/circles.html

MicroWorlds Lost in the Desert

lost_in_the_desert.zip 4KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/desert.html

MicroWorlds One Good Turn Check Boxes

Updated January 24, 2005

one_good_turn.mw2 27 KB
one_good_turn.zip 13 KB
one_good_turn.exe 76 KB

Demonstrates the use of radio buttons

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/onegoodturn.html

MicroWorlds on a tangent

on_a_tangent.zip 9KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/tangent.html

MicroWorlds ring-around-a-rosie

ring-around-a-rosie.zip 5KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/rosie.html

MicroWorlds Harmonic Convergance

harmonic.zip 5KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/harmonic.html

MicroWorlds Cornered

cornered.zip 5KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Inspired by the online essay going in circles
http://llk.media.mit.edu/projects/circles/

http://llk.media.mit.edu/projects/circles/cornered.html

MicroWorlds Spiral

MicroWorlds Spiral

spiral.zip 4KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Get MicroWorlds Web Player Plugin version

to spiral
   ; clear the screen if the
   ; spiral is already completed

   if :completed = "true [
      make "completed "false
      pu
      clear
      pd
      cc
   ]

   ; ----- if the turtle is not
   ;       at the edge of the square
   ;       keep drawing the spiral
   ;       otherwise stop drawing the
   ;       spiral and set
   ;       "completed to "true

   ifelse (distance "turtle_@_center) < 170 [
     fd :step
      rt 5
      make "step :step + 0.007
   ][
      make "completed "true

      ; turn off the spiral button
      set "button1 "on? "false
   ]
end

Draws a nice spiral and some weird variations as well.

star-moon-star

star-moon-star.zip 61KB Ziped with Winzip  from www.winzip.com

use winzip to unzip

 

A similar program to random_tri_sq.zip

MicroWorlds Triangles and Squares

random_tri_sq.zip 38KB Ziped with Winzip  from www.winzip.com

use winzip to unzip

Get MicroWorlds Web Player Plugin version

Draws random triangles & squares, Produces nice 50's style table top designs. Demonstrates one way to implement push button controls using turtles.

to click_switch
   if :click_switch = "false [
      ; ----- if the switch was off turn it on
      ;       turn the variable click_switch to true

      make "click_switch "true
      make "fill_shapes "true
      check_switches
      
stop                        ; stop the procedure
   ]

   if :click_switch = "true [
      ; ----- if the switch was on turn it off and...
      ;       change the value of click_switch

      make "click_switch "false
      make "fill_shapes "false
      check_switches              ; call check_switches
   ]

end

to check_switches
   ; ----- show the value of fill in the text box
   ifelse :fill_shapes = "true [
      set "text1 "text (se [fill is true])
      tr_click, setsh "click_on  ; turn on the click switch
      tr_push, setsh "push_on    ; turn on the click switch
   ]
      make "fill "false
      set "text1 "text (se [fill is false])
      tr_click, setsh "click_off ; turn off the click switch
      tr_push, setsh "push_off   ; turn off the click switch
   ]
end

 

MicroWorlds making turtles
August 9, 2004

make_turtles.mw2 52 KB

make_turtles.zip 10 KB Ziped with Winzip  from www.winzip.com use winzip to unzip

Make and remove turtles using procedures

based on code from: http://www.microworlds.com/library/math/geoboard/geoboard.zip

to remove_all_turtles

  newturtle "create_a_dummy_turtle ; this is necessary
                                   ; to make sure that there
                                   ; is a current turtle

  make "number_of_turtles count get first pagelist "turtles
  repeat :number_of_turtles [
    carefully [remove who][]       ; remove current turtle
    ]
end

MicroWorlds Headings
August 10, 2004

headings.mw2 75 KB

headings.zip 15 KB Ziped with Winzip  from www.winzip.com use winzip to unzip

The heading names were created using Paint Shop Pro.
Create the text as a vector, copy it and paste as a new turtle into MicroWorlds.

Headings


August 16, 2004

lissajous.mw2
lissajous.zip

lissajous.exe

GNU License.txt

Published under the GNU GPL

to play1
   make "first_move 1
; remember we have not moved yet
   pu ; pick up the pen before we move
   ht
   make "p1_count 0
; Set initial value for "p1_count
   make "new_scale scale
   
   forever [
      make "p1_count :p1_count + 0.001
      setx (sin (xx * :p1_count)) * :new_scale
      sety (sin (yy * :p1_count)) * :new_scale

                        ; don't start drawing until until
                        ; we are in the right place

                        
; then remember we have moved
      if :first_move = 1 [make "first_move 0 pd]
      make "new_scale :new_scale * 0.999999
      setc :p1_count / 1.5
   ]
end

September 4, 2004

triangles1.mw2 22 KB
triangles1.zip 12 KB
triangles1.exe 72 KB

Get MicroWorlds Web Player Plugin version
GNU License.txt


Published under the GNU GPL


Draws sets of triangles. Uses simple checkboxes to toggle between B/W & colour triangles and Automaitc or Manual positioning of turtles.


October 7, 2004

spirals2.mw2 61 KB
spirals2.zip 21 KB
spirals2.exe 84 KB

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

to spiral :size :angle
   ht
   if :size > ( last  projectsize ) - 140 [stop]
; recursive stop
   if :size > ( first projectsize ) - 140 [stop]
; recursive stop
   forward :size
   right :angle
   make "size :size + 2         
; increase the size
   spiral :size :angle
         ; recursive call
end



October 13, 2004

art2.mw2 33KB
art2.zip 17 KB
art2.exe 80KB

art2 source code

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

See Art1 above


October 14, 2004

spirals3.mw2 135 KB
spirals3.zip 29 KB
spirals3.exe 92 KB

spirals3 source code

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

see: spirals2 above

based on code from: A Logo Primer

http://el.media.mit.edu/logo-foundation/logo/turtle.html

to curve :size deg
   ; this is the heart of the program
   pd
   ifelse (and ((first pos) < 200 ) ((last pos) < 200) ) [
      fd :size
      rt :deg
      make "size :size + 0.3
      curve :size deg                      ; recursive call
   ][pu fd 2 setc "yellow fill ht stop]    ; recursive stop
end


October 21, 2004

move_turtle1.mw2 29 KB


to startup
   make "step 50
   make "line_size 1
   move_turtle
end

to move_turtle
   pd
   ; read the key pressed
   make "ch ascii readchar

   if :ch = 38 [t1, seth 0 fd :step]    ; north
   if :ch = 40 [t1, seth 180 fd :step]  ; south
   if :ch = 39 [t1, seth 90 fd :step]   ; east
   if :ch = 37 [t1, seth 270 fd :step]  ; west

   ; < or , reduce step size
   if (or :ch = 46 :ch = 62 )[
   make "step (:step + 1)
   cc
   show (se "step "size :step)
   show se "pensize :pensize
   ]

   ; > or . increase step size
   if (or :ch = 44 :ch = 60) [
      if :step > 1 [
         make "step (:step - 1)
         cc
         show (se "step "size :step)
         show se "pensize :pensize
      ]
   ]

   ; x or X increase pensize
   if (or :ch = 120 :ch = 88) [
      if :line_size < 100[
         make "line_size :line_size + 1
         cc
         show (se "step "size :step)
         show se "line_size :line_size
      ]
   ]

   ; z or Z decreade pensize
   if (or :ch = 122 :ch = 90)[
      if :line_size > 1 [
         make "line_size :line_size - 1
         cc
         show (se "step "size :step)
         show se "line_size :line_size
      ]
   ]

   setpensize :line_size

   setc (random 15) + 125 ; add some colour
   move_turtle ; repeat the whole process again
end


October 21, 2004

move_turtle2.mw2 29 KB

 

Move the turtle using the cursor keys

Yet another more complex version of move_turtle0

This is an example of creeping featurisim. I could not help adding the ability to lift the turtle using U for pu and then I had to have D for pd and then I had to be able to see the diffierence between when the turtle was up and down. And then I added colours and then I though what about white...

This is always a risk when writing programs. Creeping featurisim is also known as program bloat.


October 21, 2004

move_turtle3.mw2 82 KB
move_turtle3.zip 36 KB
move_turtle3.exe 96 KB

move_turtle3 source code

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

 

Another more complex version of move_turtle0

This version uses features from Art2 to colour the turtle as it moves

 


October 21, 2004

move_turtle0.mw2 18 KB
move_turtle0.zip 11 KB
move_turtle0.exe 72 KB

move_turtle0 source code

Get MicroWorlds Web Player Plugin version
GNU License.txt

Published under the GNU GPL

Move the turtle using the cursor keys

to startup
   make "step 50
   setpensize 5
   move_turtle

end

to move_turtle

   pd

   ; read the key pressed
   make "ch ascii readchar

   if :ch = 38 [t1, seth 0 fd :step]   ; north
   if :ch = 40 [t1, seth 180 fd :step] ; south
   if :ch = 39 [t1, seth 90 fd :step]  ; east
   if :ch = 37 [t1, seth 270 fd :step] ; west

   ;setc (random 15) + 125 ; add some colour
   setc "black

   move_turtle ; repeat the whole process again

end


January 23, 2005

harmonograph.mw2 90KB

GNU License.txt

Published under the GNU GPL

Draws harmonographs

Based on code from http://www.mulawa.net/mulawa/projects/index.html

Andrew Purdam has produced equations that allow one to explore the beauty of the harmongraph without building one....not that building one is any less satisfying. His equations are:
x(t) = Ax(t) sin(wx + px) + As(t) sin(ws + ps)

y(t) = Ay(t) sin(wy + py)

All initial amplitudes, frequencies (w) and phases (p) should be different and not integer multiples for the most complicated (interesting) patterns.

In order for the amplitude to decay (not necessary but occurs in the real harmonograph) the amplitudes can decay as follows, where d is typically a suitable small positive number. This gives an exponential decay function.
A(t) = A(t-1) (1 - d)

APA citation:
Russell, R. (2018, December 03, 11:05 am). Turtle graphics examples.
     Retrieved October 08, 2024, from http://www.rupert.id.au/microworlds/trutlegraphics.php

Last refreshed: October 08 2024. 01:39.49 am

rupert dot russell at acu dot edu dot au Support Wikipedia

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.


2293 Visits since November 16, 2004