# Using LOGO commands in QBasic source code...

January 21 2002 at 7:51 PM

' ********** COOLLOGO.BAS **********

DECLARE SUB Dragon ()
DECLARE SUB BK (a!)
DECLARE SUB Start (x!, y!)
DECLARE SUB PenUp ()
DECLARE SUB Fill ()
DECLARE SUB StepbyStep ()
DECLARE SUB Coollogo ()
DECLARE SUB PenDown ()
DECLARE SUB rt (a!)
DECLARE SUB lt (a!)
DECLARE SUB fd (a!)

' *** USING LOGO COMMANDS IN QBASIC ***
' Why? Because it is the easiest way to create amazing geometrical
' structures. Logo is the programming language for all age 3 and up,
' it teaches the basics of proceural programming as well as geometry.
' And it is easy!

' Although Qbasic has the DRAW statement, it doesn't use true turtle-
' graphics, and that's a pity because it would make graphics programming
' a whole lot easier. Just try making a hexagon with the Draw statement
' and then try it with the LOGO commands... Then you'll understand.

' How? Think about it like you are programming a small robot that rolls
' over a large piece of paper. It has a small pen in the middle of it,
' and when it puts the pen down on the paper it will leave a trail...
' You can steer the robot with simple commands:

' The Most Basic Commands:
' FD pixels = Go FORWARD a number of pixels
' LT degree = Turn LEFT a number of degrees (1-360)
' RT degree = Turn RIGHT a number of degrees (1-360)
' BK pixels = Go BACKWARDS a number of pixels

' (Most Logo commands are only used in their
' abbreviated form, because the English versions of them
' contain QBasic keywords.)

' Usefull extra commands
' PenUp = Take Pen off Paper, don't draw anything
' PenDown = Put Pen on Paper, start drawing
' Fill = Fill up the area around current position with color
' the current position
' StepByStep = Slowdown drawing to show how the figure is formed
' StepOff = Go back to normal speed (as fast as possible)
' Start x,y = Start drawing at x,y coordinate

' The following commands are not supported:
' TO Subprogram : Use SUB... END SUB instead
' REPEAT Counter: Use FOR... NEXT, DO... LOOP or WHILE... WEND instead
' (QBASIC is much more flexible with LOOPS anyway)

' Colors are not supported yet. But you can easily get around that using
' standard Qbasic commands...

' Some sample LOGO programs:
' Square Side : draws a square with a specified Sidelength
' Prog6
' Prog7
' Coollogo : Try 'em!
' Dragon : Really showing off! A scalable, rotatable dragoncurve!

SCREEN 9, , 0, 1 ' Starting Graphics Mode
DIM SHARED LogoPen ' Defining Some Variables
DIM SHARED Stap
CONST True = -1
CONST False = 0
PenDown ' Put the Pen Down to start Drawing
'StepbyStep

' ********* Your LOGO program starts here! *********

Dragon

SUB BK (a)
IF LogoPen = True THEN DRAW "d" + STR\$(a) ELSE DRAW "bd" + STR\$(a)
IF Stap = True THEN SLEEP
END SUB

END SUB

SUB Coollogo

FOR k = 1 TO 6
FOR n = 1 TO 6
fd 50
lt 60
NEXT n
rt 60
FOR n = 1 TO 5
fd 50
rt 60
NEXT n
lt 120
NEXT k

END SUB

SUB Dragon
rot = 0
leng = 10
DO
DRAW "s2c14"
rt rot
pi = 4 * ATN(1): p = 10: h = 2 ^ (-p / 2): xa = 0: ya = h
xb = 0: yb = 0: xs = xa: ys = ya: c1 = .3: c2 = 1 - c1
FOR n = 1 TO 2 ^ p - 1: m = n: DO: IF m MOD 2 = 0 THEN m = m / 2
LOOP UNTIL m MOD 2 = 1
IF m MOD 4 = 1 THEN d = 1 ELSE d = -1
s = s + d
IF d = 1 THEN
lt 90
fd leng
ELSE
rt 90
fd leng
END IF
NEXT
PCOPY 0, 1
DEF SEG = 0: POKE &H41A, PEEK(&H41C): DEF SEG
toets = INP(96)

CLS
rot = rot + (toets = 75)
rot = rot - (toets = 77)
leng = leng + (toets = 80)
leng = leng - (toets = 72)
IF rot > 360 THEN rot = rot - 360
IF rot < 0 THEN rot = rot + 360
IF leng < 2 THEN leng = 2
IF leng > 100 THEN leng = 100
lt 270
LOOP UNTIL toets = 1

END SUB

SUB fd (a)
IF LogoPen = True THEN DRAW "u" + STR\$(a) ELSE DRAW "bu" + STR\$(a)
IF Stap = True THEN SLEEP
END SUB

SUB Fill
DRAW "p15,15"
END SUB

SUB lt (a)
STATIC b
b = b + a
IF b > 360 THEN b = b - 360
IF b < -360 THEN b = b + 360
IF LogoPen = True THEN teken\$ = "ta" + STR\$(b) ELSE teken\$ = "bta" + STR\$(b)
DRAW teken\$
IF Stap = True THEN SLEEP
END SUB

SUB PenDown
LogoPen = True
END SUB

SUB PenUp
LogoPen = False
END SUB

SUB Prog6

FOR k = 1 TO 10
lt 20
FOR n = 1 TO 2
lt 90
fd 90
NEXT n
Circ 100
NEXT k

END SUB

SUB Prog7

FOR n = 1 TO 11
lt 20
fd 90
lt 90
fd 90
lt 90
fd 90
lt 90
fd 90
NEXT n

END SUB

SUB rt (a)
lt -a
END SUB

SUB SQUARE (side)
FOR n = 1 TO 4
fd side
rt 90
NEXT n
END SUB

SUB Start (x, y)
DRAW "bm" + STR\$(x) + "," + STR\$(y)
END SUB

SUB StepbyStep
Stap = True
END SUB

SUB StepOff
Stap = False
END SUB

 Respond to this message