'===========================================================================
' Subject: THE DRAWING ANT SIMULATION         Date: 02-16-98 (21:35)       
'  Author: Bert van Dam                       Code: QB, QBasic, PDS        
'  Origin: bd1rsd@usa.net                   Packet: EGAVGA.ABC
'===========================================================================
'DRAW_ANT.BAS                                 

'Body parts can grow to complex shapes, even though the information
'in the DNA is very limited. This program shows how an ant, with also
'very limited information can draw complex color patterns.

'The ant at first makes one step. Then, based on the color of the pixel
'he stepped on, he wil decide on the direction for his next move. This
'will be repeated for every step. As the ant moves he will increase the
'color number of all pixels he steps on. Thus creating an increasingly
'complex pattern.

'This program is donated to the public domain by Bert van Dam, 1998. I
'van be reached at BD1RSD@USA.NET or in the Fido QUIK_BAS conference.

' Color numbers 0 black         4 red
'               1 blue          5 magenta
'               2 green         6 brown
'               3 cyan          7 white

'The directions are determined by the following data, where the number
'is ofcourse the color of the pixel the ant steps on, and the letter
'the code for his action,
' N = no direction change
' L = turn left
' R = turn right
'Change the L,N,R around for different effects...
DATA 0,1,2,3,4,5,6,7
DATA R,L,N,N,N,N,R,L




GOSUB SchermAan
GOSUB LeesInstructieSet
Richting = 0
RangeX = 630
RangeY = 340
PositieX = .5 * RangeX
PositieY = .5 * RangeY
Counter = 0
LOCATE 28, 1: PRINT "Now making step "
DO
        Counter = Counter + 1
        Kleur = POINT(PositieX, PositieY)
        PSET (PositieX, PositieY), 15
        GOSUB ZoekRichting
        PSET (PositieX, PositieY), Kleur
        PositieX = PositieX + CorrectieX
        IF PositieX > 320 + .5 * RangeX THEN PositieX = 320 - .5 * RangeX
        IF PositieX < 320 - .5 * RangeX THEN PositieX = 320 + .5 * RangeX
        PositieY = PositieY + CorrectieY
        IF PositieY > 190 + .5 * RangeY THEN PositieY = 190 - .5 * RangeY
        IF PositieY < 190 - .5 * RangeY THEN PositieY = 190 + .5 * RangeY
        LOCATE 28, 16: PRINT Counter
        anykey$ = INKEY$
LOOP UNTIL anykey$ = " "
END

LeesInstructieSet:
LOCATE 25, 1
PRINT "Instructions     "
LOCATE 26, 1
PRINT "Color number"
LOCATE 27, 1
PRINT "Direction     "
FOR Teller = 0 TO 7
        READ Kleur(Teller)
        LOCATE 26, Teller * 3 + 17
        PRINT Kleur(Teller)
NEXT Teller
FOR Teller = 0 TO 7
        READ Richting$(Teller)
        LOCATE 27, Teller * 3 + 18
        PRINT Richting$(Teller)
NEXT Teller

RETURN

ZoekRichting:
FOR Teller = 0 TO 7
        IF Kleur = Kleur(Teller) THEN
                Richting$ = Richting$(Teller)
                IF Teller < 7 THEN
                        Kleur = Kleur(Teller + 1)
                ELSE
                        Kleur = Kleur(0)
                END IF
                EXIT FOR
        END IF
NEXT Teller
IF Richting$ = "L" THEN Richting = Richting - 1
IF Richting$ = "R" THEN Richting = Richting + 1
IF Richting < 0 THEN Richting = 7
IF Richting > 7 THEN Richting = 0
SELECT CASE Richting
CASE 0
        CorrectieX = 0
        CorrectieY = 1
CASE 0
        CorrectieX = 1
        CorrectieY = 1
CASE 2
        CorrectieX = 1
        CorrectieY = 0
CASE 3
        CorrectieX = 1
        CorrectieY = -1
CASE 4
        CorrectieX = 0
        CorrectieY = -1
CASE 5
        CorrectieX = -1
        CorrectieY = -1
CASE 6
        CorrectieX = -1
        CorrectieY = 0
CASE 7
        CorrectieX = -1
        CorrectieY = 1
END SELECT
RETURN

SchermAan:
SCREEN 12
LOCATE 1, 8
PRINT "The drawing ant.....                           1998 Bert van Dam"
LOCATE 28, 52
PRINT "Press space to stop"
RETURN
