LOGO

by Gordon
gordon@gsweet.fsnet.co.uk

Some may not be aware that Logo is a programming language of its own, that has actually been around for many years, even before the advent of Windows I believe. It is fairly similar to Basic, and also able to Edit, and Save complete programs. I understand at one time it found use in robotics, where the robot took the form of the Turtle used in Logo, and was quite popular for use in schools to demonstrate the principals of robotics.

However a recent search of the internet with Google shows up few references to Logo now, although I did find a couple of nice modern versions freely available from http://sourceforge.net/projects/clpp and http://www.softronix.com/logo.html

The first version uses a smaller screen. The titles of the functions with these later versions are not all the same as the earlier versions, which used such phrases as fd for forward and rt as right turn along with penup and pendown. The ancient Freeware DOS version called Ladybug Logo I have still works under Windows XP except for the Editor, but can only handle about 4 colours. The program files can easily be set to display with Notepad etc. Anyone is welcome to a copy if they contact me.

Fortuneately Carl and his friends were good enough to include some of the basic Logo graphic functions in JB and LB, though giving slightly different names to them. Below are a couple of simple examples of the early Logo, and showing how these have been adapted to run with JB/LB. Do not of course include the Logo code when attempting to run the JB code. Delays are included to allow us to see the drawing. Below this is my attempt to simulate Logo using menus and the cursor keys to control the Turtle and colours.

LOGO CODE

make "description [SPINSQUARES; from "Logo for the Apple II"]
define "spinsquares [[ :size][repeat 18 [rt 20 repeat 4 [fd :size rt 90]]]]
spinsquares

to "patns2  :side :angle :inc :turns
repeat :turns [fd :side rt :angle make side :side + :inc]
end

‘=========================================================================
nomainwin
    WindowHeight = 600 : WindowWidth = 800
    open "LOGO demo" for graphics_nsb as #l
    #l "trapclose [quit]; down"

   #l "cls; place 250 300; north"
    for r = 1 to 2
        for rep = 1 to 18
            for n = 1 to 4
                #l "turn 20"
                halt = 20 :gosub [delay]
            next n
            #l "go 400" : #l "turn 90"
        next rep
    next r
    halt = 1000 : gosub [delay]

    side = 10 : angle = 45 : inc =  1: turns = 100 : gosub [pattern]
    side = 150 : angle = 119 : inc = 2 : turns = 70 : gosub [pattern]
    side = 150 : angle = 120 : inc = 3 : turns = 70 : gosub [pattern]
    side = 100 : angle = 144 : inc = 3 : turns = 89 : gosub [pattern]
    wait

[pattern]
    #l "cls; place 350 300; north"
    for tn = 1 to turns
        #l "go ";side : #l "turn ";angle
        side = side + inc
        halt = 50 : gosub [delay]
    next tn
    halt = 1000 : gosub [delay]
    return

[delay]
    tim = time$("ms")
    while time$("ms") < tim + halt
        scan
    wend : return

[quit] close #l : end

‘=====================================================================

' Very Simple LOGO demo
    nomainwin
    WindowWidth = 800 : WindowHeight = 600
    menu #logo, "DRAWING", "PenDown", [draw], "PenUP", [move],_
 "ClearScreen", [clear], |, "QUIT", [quit]
    menu #logo, "COLORS", "Yellow", [yel], "Brown", [bro], "Blue", [blu],_
 "Red", [red], "pink", [pnk], "Green", [grn], "Cyan", [cyn], "Black", [blk]
tl$ =  "Simple LOGO - USE Arrow keys to Move or Turn. Press U=penUp,  D=penDown"
    open tl$ for graphics_nsb as #logo
    print #logo, "cls; trapclose [quit]"
    print #logo, "backcolor white; size 2; place 100 100; down"
    x=100 : y=100 : xp = x : yp = y : extra = 0
    draw=1 : col$="black" : pcol$ = "black"
    beep : gosub [show]

[loop]
    print #logo, "discard"
    print #logo, "setfocus; when characterInput [fetch]"
    scan
    goto [loop]

[fetch]
    key$ = Inkey$
    keyV = asc(right$(key$, 1))
    if keyV=38 then pixls = -20 : gosub [go]
    if keyV=40 then pixls = 20 : gosub [go]
    if keyV=39 then angl = 5 : gosub [twist]
    if keyV=37 then angl = -5 : gosub [twist]
    if key$="d" or key$="D" then draw = 1 : goto [loop]
    if key$="u" or key$="U" then draw = 0 : goto [loop]
    gosub [show]
    if draw = 1 then col$=pcol$ else col$="white"
    goto [loop]

[go] gosub [hide]
    print #logo, "line ";xp;" ";yp;" ";x;" ";y
    print #logo, "go "; pixls
    xp = x : yp = y
    print #logo, "posxy x y"
    turn = 0 : return

[twist]
    gosub [hide]
    if turn = 0 then
    print #logo, "posxy x y"
    print #logo, "line ";xp;" ";yp;" ";x;" ";y
    end if
    print #logo, "turn ";angl
    print #logo, "line ";xp;" ";yp;" ";x;" ";y
    print #logo, "goto ";x;" ";y
    turn = 1
    return

[move] draw = 0 : goto [loop]
[draw] draw = 1 : goto [loop]

[yel] pcol$ = "yellow" : goto [col]
[bro] pcol$ = "brown" : goto [col]
[blu] pcol$ = "blue" : goto [col]
[red] pcol$ = "red" : goto [col]
[pnk] pcol$ = "pink" : goto [col]
[grn] pcol$ = "green" : goto [col]
[cyn] pcol$ = "cyan" : goto [col]
[blk] pcol$ = "black"

[col] col$ = pcol$
     print #logo, "color ";col$
     gosub [hide] : gosub [show] : goto [loop]

[clear]  confirm "OK to clear the screen?"; q$
    if q$="yes" then print #logo, "cls; home"
    gosub [show] : goto [loop]

[hide]
    print #logo, "posxy x y; size 3; color white; turn -330"
    print #logo, "turn 30; go 14; turn 30; go -8"
    print #logo, "turn 240; go 8; turn 30; go -14"
    print #logo, "turn -330; place ";x;" ";y
    print #logo, "size 2; color ";col$
    return

[show]
    if draw = 0 then print #logo, "color black"
    print #logo, "turn 30; go 14; turn 30; go -8"
    print #logo, "turn 240; go 8; turn 30; go -14"
    return

[quit] close #logo : end