[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Logo teaching program






There was some discussion here about making Logo more immediately useful
to a beginner without a teacher by adding some step-by-step demos.  The
following is a UCBLogo program that's meant to further that discussion.
It's probably not ready for prime time, but it does have the nice feature
that the demonstration mechanism is decoupled from the particular program
being demonstrated.  Basically, you write a program that draws a picture,
and this program will allow examples to be displayed and stepped through.
Recursion is handled, but not mutual recursion -- subprocedures of the
procedure being demoed are treated as atomic black boxes.

This is an unusual venture for me in that it's turtle-centric; I haven't
made any text demos, so I don't know what infrastructure is needed for that.

If anyone actually reads the code, the otherwise incomprehensible
        run se ... []
is a workaround for a Berkeley Logo bug I discovered enroute.  (Classes
have ended so I'll try to put in a few days on Logo soon!)

Included are two demo pictures, of intermediate difficulty.  Of course
there should be more examples before and after these.

To run this, just say TEACH.

-----------------------------

to teach
localmake "globals []
localmake "varposn [-300 -120]
localmake "depthcolors [6 1 4 14 2 8 13 9]
localmake "stepfast "false
clearscreen
wait 60
catch "picture [flagdemo]
clearscreen
catch "picture [treedemo]
end

to treedemo
localmake "varposn [0 -120]
hideturtle
pendown setpencolor 7
tree 5 150
showturtle
catch "demo [user]
demo [tree 1 150]
demo [tree 2 150]
demo [tree 3 150]
end

to flagdemo
hideturtle
pendown setpencolor 7
flags 15 22 1 43 1
showturtle
catch "demo [user]
demo [flag]
demo [fillflag 4]
demo [flags 15 22 1 5 1]
end

to user
if :stepfast [wait 20 stop]
pr [Press spacebar to continue, F to continue Fast (without asking each step),]
type [D to skip to next Demo, or P for a different Picture:\ ]
localmake "char uppercase readchar
cleartext
if :char = "F [make "stepfast "true]
if :char = "D [throw "demo]
if :char = "P [throw "picture]
end

to demo :command
clearscreen
type "|? |
settextcolor 6 0
print :command
settextcolor 7 0
run :command
display first :command
catch "demo [
 user
 clearscreen
 localmake "linecolors map [(list 0 7)] butfirst text first :command
 localmake "walkdepth 0
 walk :command
]
make "stepfast "false
end

to display :procname
localmake "oldpos pos
localmake "oldheading heading
localmake "text fulltext :procname
localmake "height 180
foreach :text [
  penup   setpos list -300 :height  setheading 0
  make "height :height-18
  pendown   label ?
]
penup   setpos :oldpos   setheading :oldheading   pendown
end

to walk :command [:dpy "true] [:walkdepth :walkdepth+1]
localmake "stepfast :stepfast
localmake "text text first :command
localmake "fulltext fulltext first :command
localmake "oldvalues map [ifelse namep ? [thing ?] ["none]] first :text
localmake "variables first :text
local :variables
(foreach :variables :oldvalues "make)
local "values
run (sentence "make ""values "\( "list butfirst :command "\) )
(foreach :variables :values "make)
if :dpy [display first :command]
showvariables
commands butfirst :text butfirst :fulltext 180-18 :linecolors
end

to commands :text :fulltext :height :somecolors
if empty? :text [stop]
localmake "pos pos
localmake "head heading
localmake "pen pendown?
localmake "pc pencolor
penup  setpos list -300 :height  setheading 0
setpencolor item :walkdepth :depthcolors
pendown  label first :fulltext
.setbf first :somecolors fput pencolor butfirst first :somecolors
penup  setpos :pos  setheading :head
if :pen [pendown]
setpencolor :pc
if equalp first first :text "localmake [
  run sentence first :text []
]
localmake "runresult runresult [commands1]
if emptyp :runresult [user]
make "pos pos
make "head heading
make "pen pendown?
make "pc pencolor
penup  setpos list -300 :height  setheading 0
.setbf first :somecolors butfirst butfirst first :somecolors
setpencolor first butfirst first :somecolors
pendown  label first :fulltext
penup  setpos :pos  setheading :head
if :pen [pendown]
setpencolor :pc
if emptyp :runresult [stop]
if not equalp first :runresult "command-completed-without-stopping ~
   [output first :runresult]
commands butfirst :text butfirst :fulltext :height-18 butfirst :somecolors
end

to commands1
ifelse equalp first first :text first :command ~
  [(walk sentence first :text [] "false)
    if not emptyp butfirst :text [showvariables]] ~
  [run sentence first :text []
   if equalp first first :text "make [walkmake "globals]
   if equalp first first :text "localmake [walkmake "variables]
   user]
output "command-completed-without-stopping
end

to walkmake :varlist
local "makevalues
run (sentence "make ""makevalues "\( "list butfirst first :text "\) )
localmake "varname first :makevalues
if not memberp :varname (sentence :globals :variables) ~
   [make :varlist sentence thing :varlist :varname]
showvariables
end

to showvariables
localmake "oldpos pos
localmake "oldheading heading
localmake "oldpc pencolor
penup   setpos :varposn  setheading 0   pendown
foreach (sentence :globals :variables) ~
  [setpc 7  label (word ? "=)  
   penup right 90 forward 10*(1+count ?) left 90 pendown
   setpc item :walkdepth :depthcolors  label (list thing ? "|   |)
   penup right 90 forward 30  left 90 pendown]
penup   setpos :oldpos   setheading :oldheading   pendown  setpc :oldpc
end

to flag
forward 100
localmake "p pos
back 32
right 90
forward 24
left 90
setpos :p
end

to fillflag :color
flag
penup back 20 right 90 forward 5
setpencolor remainder :color 16
fill
setpencolor 7
back 5 left 90 back 80 pendown
end

to flags :distance :angle :increment :number :fillcolor
if :number=0 [stop]
fillflag :fillcolor
forward :distance
right :angle
flags :distance+:increment :angle :increment :number-1 :fillcolor+1
end

to tree :number :size
if :number=0 [stop]
fd :size/3
lt 20
tree :number-1 :size*0.7
rt 20
fd :size/6
rt 25
tree :number-1 :size*0.55
lt 25
fd :size/2
lt 30
tree :number-1 :size*0.2
rt 50
tree :number-1 :size*0.25
lt 20
bk :size
end
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home