Login   Register  
PHP Classes
elePHPant
Icontem

File: sample.lgo

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Dr Zhihua Lai  >  Logo Interpreter  >  sample.lgo  >  Download  
File: sample.lgo
Role: Auxiliary data
Content type: text/plain
Description: Sample Logo Source Code
Class: Logo Interpreter
Logo language interpreter
Author: By
Last change: minor update
Date: 2 years ago
Size: 2,260 bytes
 

Contents

Class file image Download
/* PHP Online Interpreter
   By Dr Zhihua Lai
   doctor@zhihua-lai.com
   http://www.zhihua-lai.com/?do=Software.Logo
   note: case - insensitive
   and expressions should not contain spaces ~
*/

#  this is a comment.
;  this is also a comment.
// this is also also a comment.

//////////////////////////   Global Vars Defined ///////////////////
make "T 220     // Global Variable

//////////////////////////   Procedures ////////////////////////////
# Spiral
to spiral :size :angle // recursive function with two parameters 
  if (:size>:T) [stop]
  forward :size
  right :angle
  spiral :size+2 :angle // recursive call
end 

# Tree
to tree :size // with one parameter
  if (:size<10) [stop]
  fd :size
  lt 30 tree :size*0.7  ; left branch, recursive
  rt 60 tree :size*0.7  ; right branch, recursive
  lt 30 
  bk :size
end

to spiral2 :size
  if (:size>30) [stop]  ; an exit condition
  fd :size rt 15        ; many lines of action
  spiral2 :size*1.02    ; the tailend recursive call
end

# Circles
to n_eck :ne :sz
  repeat :ne [rt 360/:ne fd :sz]
end

# Circles
to mn_eck :ne :sz
  repeat :ne [rt 360/:ne n_eck :ne :sz]
end

# Circles, Faster
to anothercircle
  repeat 36 [jump 100 arc 360 100 jmp -100 turn 10]
end

//////////////////////////   Entry Program ////////////////////////////
window           ; set the window mode
setfc yellow     ; set flood colour
fill             ; fill the background
penup            ; pen up
setxy 200 -150   ; set turtle position
pd               ; pen down
setpc black   
spiral 0 91      ; do the work
setpc blue
pu
setxy 80 130
pd
spiral2 10
pu               ; pen up
setpc red; 
setxy -180 -100  ; set the location
lt  degree       ; degree is a global variable
pd               ; pen down
tree 100         ; draw a tree
hideturtle       ; ht = hide the turtle, it is actually a small circle
pu
home
pd
setpc green
// mn_eck 36 20  ; very slow compared to the following line
anothercircle
setpc black
pu
setxy -250 -200
pd
repeat 4 [fd 100 rt 90]
pu
setxy -200 -150
setfc red
fill
setpc blue       ; last pc command sets the color of text
////////////////////////////  End  //////////////////////////////////////////