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

Rotate Source Code

rotate.txt 5 KB


;  Purpose: To play with translating and rotating a turtle.
;  Copyright © 2004 by Rupert Russell
;  e-mail: rupert.russell1@gmail.com
;  URL: http://www.rupert.id.au/microworlds/index.html
;  Created: October 16, 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 clear
   startup
end

to startup

  cg
  setsh "r_0
  make "status "fliped_false
  cc
  t_a_r, setshape "a_r
  t_a_r, setpos [-38 -166 ]
  t_a_l, setshape "a_l 
  t_a_l, setpos [-307 -166]
  t_flip, setshape "flip
  t_flip, setpos [-173 -166 ]

  talkto "t_horse
  setsh "r_0
  cg

  set  "button6 "size [135 27]
  set  "button10 "size [135 27]
  set  "button2 "size [135 27]

  set  "button10 "pos [42 -126]
    set  "button6 "pos [42 -155]
  set  "button2 "pos [42 -184]

end

to flip

  talkto "t_horse
  if :status = "fliped_false [
    setsh "f_r_0
    make "status "fliped_true
    stop]

  if :status = "fliped_true [
    setsh "r_0
    make "status "fliped_false
    stop
  ]
end

to animate_clockwise


  if :status = "fliped_true [ a_f_r ]

  if :status = "fliped_false [ a_r  ]

end

to animate_counterclockwise

  if :status = "fliped_true [ a_f_l ]

  if :status = "fliped_false [ a_l  ]
end

to a_r

   ; animate turning right
   talkto "t_horse
   setshape [r_10 r_20 r_30 r_40 r_50 r_60 r_70 r_80 r_90 r_100 r_110
      r_120 r_130 r_140 r_150 r_160 r_170 r_180 r_190 r_200 r_210 r_220
      r_230 r_240 r_250 r_260 r_270 r_280 r_290 r_300 r_310 r_320 r_330
      r_340 r_350 r_360]

   forever  [talkto "t_horse fd 0 wait 0.1]

end

to a_l

   ; animate turning left
   talkto "t_horse
   setshape [r_360 r_350 r_340 r_330 r_320 r_310 r_300 r_290 r_280 
      r_270 r_260 r_250 r_240 r_230 r_220 r_210 r_200 r_190 r_180 
      r_170 r_160 r_150  r_140 r_130 r_120 r_110  r_100 r_90 r_80 
      r_70 r_60 r_50 r_40 r_30 r_20 r_10]

   forever  [talkto "t_horse fd 0 wait 0.1]

end

to a_f_r

   ; animate fliped right
   talkto "t_horse
   setshape [f_r_0 f_r_15 f_r_30 f_r_45 f_r_60 f_r_75 f_r_90 f_r_105
      f_r_120 f_r_135 f_r_150 f_r_165 f_r_180 f_r_195 f_r_210 f_r_225
      f_r_240 f_r_255 f_r_270 f_r_285 f_r_300  f_r_315 f_r_330 f_r_345]

   forever  [talkto "t_horse fd 0 wait 0.3]

end

to a_f_l

   ; animate Fliped left
   talkto "t_horse
   setshape [f_r_0 f_r_345 f_r_330 f_r_315 f_r_300 f_r_285 f_r_270
      f_r_255 f_r_240 f_r_225 f_r_210 f_r_195 f_r_180 f_r_165 f_r_150
      f_r_135 f_r_120 f_r_105 f_r_90 f_r_75 f_r_60 f_r_45 f_r_30 f_r_15]

   forever  [talkto "t_horse fd 0 wait 0.3]

end

to spin_right

   ; animate turning right & stamp each time the turtle moves 
   ; this way it leaves a trail showing where it has been.
   talkto "t_horse
   seth 90
   setshape [r_10 r_20 r_30 r_40 r_50 r_60 r_70 r_80 r_90 r_100 r_110
      r_120 r_130 r_140 r_150 r_160 r_170 r_180 r_190 r_200 r_210 r_220
      r_230 r_240 r_250 r_260 r_270 r_280 r_290 r_300 r_310 r_320 r_330
      r_340 r_350 r_360]

   forever [fd 10 wait 0.1 stamp]
end

to spin_left

  ; animate fliped left
   talkto "t_horse
   seth 270
   setshape [f_r_0 f_r_345 f_r_330 f_r_315 f_r_300 f_r_285 f_r_270
      f_r_255 f_r_240 f_r_225 f_r_210 f_r_195 f_r_180 f_r_165 f_r_150
      f_r_135 f_r_120 f_r_105 f_r_90 f_r_75 f_r_60 f_r_45 f_r_30 f_r_15]
   forever  [talkto "t_horse fd 10 wait 0.1 stamp]
end


APA citation:
Russell, R. (2016, July 04, 04:17 pm). Rotate source code.
     Retrieved April 19, 2024, from http://www.rupert.id.au/microworlds/code/rotate.php



406 Visits since October 7, 2004