Home > MicroWorlds Logo Links & Examples > MicroWorlds Code Pages > move_turtle0 Code

move_turtle0 Code

move_turtle0.txt 2 KB


; Purpose: To play with keyboard controls
; Copyright © 2004 by Rupert Russell
; e-mail: rupert.russell1@gmail.com
; URL: http://www.rupert.id.au/microworlds/
; Created: October 21, 2004
;
; This program is free software; you can redistribute it and/or modify
; it 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.
;
; This program is distributed in the hope that it 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.
; ----------------------------------------------------------------------


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


APA citation:
Russell, R. (2016, July 04, 04:17 pm). Move_turtle0 code.
     Retrieved December 22, 2024, from http://www.rupert.id.au/microworlds/code/move_turtle0.php



566 Visits since October 22, 2004