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 > Introduction to Turtle Graphics

Introduction to Turtle Graphics

LOGO

PDF MicroWorlds 2.0 User's Guide (77 Pages) 462KB

See my MicroWorlds Logo Notes

Useful LOGO commands

pd        ; pen down so the turtle
           ; draws a line when it moves.


cg        ; clear the screen


fd 100    ; forward 100

setpensize 2  ; draw with a
               ;
thicker line

            

setpensize 5  ; draw with a
               ;
thicker line

rt 90         ; turn right 90
               ;
degrees

pd
fd 100
rt 90
fd 50

pd
fd 100
rt 90
fd 50
rt 90
fd 100
rt 90
fd 50

 

cg
pd
fd 50
rt 90
fd 50
rt 90
fd 50
rt 90
fd 50

cg
pd
repeat 4 [ fd 50 rt 90 ]

cg
pd
repeat 8 [ repeat 4 [ fd 50 rt 90 ] rt 45 ]

cg
pd
repeat 36 [ repeat 4 [ fd 50 rt 90 ] rt 10 ]

cg
pd
repeat 100 [ fd random 10 lt random 30 ]

cg
setshape "girl
setshape "boy

cg
repeat 3 [ setshape "lion1 wait 10 setshape "lion2 wait 10 ]

Note so far we have been typing commands one line at a time into the command center now we will look at typing commands into a procedure.

A procedure is a list of commands typed into the procedures page. All procedures start with the word to and end with the word end. Note all procedures must have unique names. eg to circle.

To switch to the procedures page select Pages | Procedures
or use the keyboard shortcut CTRL + F

At first the procedures page will be blank

Copy a procedure from the example below or type your own.

; Note these comments are only to help explain the program.
; You don't
have to type the comments for the program to work.

to circle              ; start of a procedure called circle
  repeat 360 [         ; repeats all commands within the square                          ; brackets [ ] n times
    fd 1               ; move forward one turtle step
    rt 1               ; right turn 1 degree
  ]                    ; end of repeat
end                    ; end of procedure

Close the procedures page by typing CTRL + F

Type the name of the procedure in the command center eg circle.

circle

The power of procedures comes from using one procedure again and again.

to circle
  pd
  repeat 180 [ fd 2 rt 2 ]
end

to torus
  cg
  repeat 36 [ circle rt 10 ] ; draw 36 circles each 10 degrees apart
end

 

 

Some shapes using procedures

to circle           ; start of a procedure                       ; called circle
  pd                ; pen down
  repeat 360 [      ; repeats all commands                       ; within the square                       ;  brackets n times
    fd 1            ; move forward one step
    rt 1            ; right turn 1 degree
  ]                 ; end of repeat
end                 ; end of procedure
to triangle         ; start of a procedure called                       ; triangle
  pd                ; pen down
  repeat 3 [        ; repeats all commands                       ; within the square                       ;  brackets n times
    fd 200          ; move forward 200 turtle steps
    rt 120          ; right turn 120 degree
  ]                 ; end of repeat
end                 ; end of procedure
to square           ; start of a procedure called                       ; square
  pd                ; pen down
  repeat 4 [        ; repeats commands n times
    fd 100          ; move forward 100 turtle steps
    rt 90           ; right turn 90 degrees
  ]                 ; end of repeat
end                 ; end of procedure

 

to octagon                  
  pd                  
  repeat 8 [        ; repeats all commands n times
    fd 90           ; move forward 90 turtle steps
    lt 360 / 8      ; left turn 360 divided by 8                       ; degrees
  ]                    
end                    

to polygon
  cg
  pu
  setpos [ 20 -60 ] ; move the turtle
  pd
  repeat sides [    ; repeats sides times
    fd 800 / sides  ; move 800 / sides
    lt 360 / sides  ; left turn 360 / sides degrees
  ]
end

Note this procedure uses a slider named sides to change the number of sides in the polygon.

Use a button to run a procedure or type the name of the procedure in the command center.

Use sliders to change the value of a variable within a procedure.

To insert a slider 1 click on the slider tool 2 type the name of the slider ~ sides ~
3 enter the Minimum: and Maximum: vaues for the slider 4 click OK

 


APA citation:
Russell, R. (2016, July 04, 02:14 pm). Microworlds intro.
     Retrieved December 23, 2024, from http://www.rupert.id.au/microworlds/intro.php


Last refreshed: December 23 2024. 06:50.06 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.


1535 visits since November 11, 2004