DECLARE SUB blob (i%, j%) DECLARE SUB hop (x%) DECLARE FUNCTION look! (x%) DECLARE SUB notepoint () DECLARE SUB setgrey () DECLARE SUB turn (x%) DEFINT I-K, M-N DIM SHARED speed AS INTEGER CLS INPUT "Speed setting: 0=fast, 1=slower, 2=slowest"; speed SCREEN 13 setgrey CONST white = 15, black = 0 CONST yellow = 14 DIM SHARED d AS INTEGER, m, n, i, j, il, jl, v, istep, jstep, xold, yold DIM SHARED lightest, darkest, greyline, fade, trail, straight, diff, kk DIM SHARED here, beenthere, thresh v = 63 / 1024 'maps array value to screen shade m = 64 '32 'size of array - try 32, 64 or 100 n = 64 '32 thresh = 1024 / m * 4 v1 = 512 / m 'for setting up pattern DIM SHARED vi(7), vj(7) FOR d = 0 TO 7 READ vi(d), vj(d) NEXT DATA 1,0, 1,1, 0,1, -1,1, -1,0, -1,-1, 0,-1, 1,-1 : 'directions N, NE etc. WINDOW SCREEN (-m / 6, 0)-(7 * m / 6 - 1, n - 1) DIM SHARED pic(m, n) AS INTEGER i = 0 'build pattern to trace FOR j = 0 TO n - 1 pic(i, j) = v1 * m blob i, j NEXT FOR i = 1 TO m - 1 'diamond FOR j = 0 TO n - 1 pic(i, j) = v1 * i - 512 * (ABS(i - m / 2) + ABS(j - n / 2) < m / 2 - 1) blob i, j NEXT NEXT FOR i = m / 4 TO 3 * m / 4 'filled circle s = SQR((m / 4) ^ 2 - (i - m / 2) ^ 2) FOR j = n / 2 - s TO n / 2 + s pic(i, j) = 300 blob i, j NEXT NEXT FOR i = 3 * m / 8 TO 5 * m / 8 'another circle s = SQR((m / 8) ^ 2 - (i - m / 2) ^ 2) FOR j = n / 2 - s TO n / 2 + s pic(i, j) = 600 blob i, j NEXT NEXT ' Start searching from an arrray of points FOR ii = 1 TO m STEP m / 6 FOR jj = 1 TO m STEP n / 6 i = ii j = jj kk = 0 beenthere = 0 d = 0 here = white lightest = pic(i, j) darkest = pic(i, j) greyline = (lightest + darkest) / 2 fade = 8 DO 'This is the search algorithm IF here = white THEN 'if first point is white here = look(d) 'second point in direction d IF here = white THEN 'if it's the same, white, then turn 1 'turn clockwise for next move ELSE 'otherwise you've crossed a threshold notepoint 'so mark it END IF ELSE 'if first point was black, here = look(d - 3) 'second point in direction d-3 IF here = black THEN 'if it's the same, black, then turn -1 'turn anticlockwise ELSE 'otherwise you've crossed a threshold notepoint 'so mark it END IF END IF LOOP UNTIL beenthere > 0 'keep going until you hit an old NEXT 'marked point NEXT SUB blob (i, j) LINE (i - .5, j - .5)-STEP(1, 1), 64 + v * pic(i, j), BF END SUB SUB hop (x%) y = x% AND 7 istep = vi(y) 'N/S component of direction y jstep = vj(y) 'E/W component of direction y i = (i + istep) IF i >= m THEN i = 0 IF i < 0 THEN i = m - 1 'new i, correct if off the edge j = (j + jstep) 'new j, correct if off the edge IF j >= n THEN j = 0 IF j < 0 THEN j = n - 1 END SUB FUNCTION look (x%) 'move in direction x% and look at new point hop (x%) l = pic(i, j) 'value of new point IF l > greyline THEN 'compare with mid level look = white PSET (i, j), 4 'red dot if lighter IF speed > 1 THEN PLAY "n0e" ELSE look = black PSET (i, j), 2 'green dot if darker IF speed > 1 THEN PLAY "n0c" END IF 'update lightest and darkest to track extremes, 'fading together slowly IF l > lightest THEN lightest = l ELSE lightest = lightest - fade IF l < darkest THEN darkest = l ELSE darkest = darkest + fade greyline = (lightest + darkest) / 2 'mid level diff = lightest - darkest 'represents local gradient IF diff < thresh THEN look = here 'if too "flat" return same 'as last time END FUNCTION SUB notepoint 'middle of last step p = POINT(i - istep / 2, j - jstep / 2) IF p = yellow THEN beenthere = 1 'already marked? IF speed > 1 THEN PLAY "gfedc" END IF PSET (i - istep / 2, j - jstep / 2), yellow IF kk THEN IF ABS(i - xold) + ABS(j - yold) < 4 THEN LINE -(xold, yold), yellow END IF 'draw a line from old point END IF xold = i - istep / 2 'remember old point yold = j - jstep / 2 kk = 1 trail = -4 'allow turns IF speed THEN PLAY "n0" END SUB DEFSNG I-K, M-N SUB pause DO LOOP UNTIL INKEY$ <> "" END SUB SUB setgrey grey& = 1 + 256 + 65536 FOR i = 0 TO 63 PALETTE i + 64, i * grey& NEXT PLAY "l64ms" 'setup for 'music' delay routine END SUB DEFINT I-K, M-N SUB turn (x%) trail = trail + 1 'how far since last edge? straight = straight + 1 'how far since last turn? IF 8 * straight > trail THEN 'if far enought then d = (d + x%) AND 7 'turn in direction x% straight = 0 'and restart counting from turn END IF END SUB