' ****** START INCLUDE Polygon Macro Support ******
DIM AS INTEGER StartX, StartY, PreviousX, PreviousY, LeftMostX, LeftMostY, LeftMostNear1X, LeftMostNear1Y, LeftMostNear2X, LeftMostNear2Y, LeftMostBuddyX, LeftMostBuddyY

SUB DoPostLine()
    IF POINT(0) < LeftMostX THEN
      LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostNear1X = PreviousX : LeftMostNear1Y = PreviousY : LeftMostNear2X = -1 : LeftMostNear2Y = -1
    ELSE
      IF LeftMostNear2X = -1 THEN LeftMostNear2X = POINT(0) : LeftMostNear2Y = POINT(1)
    END IF
    PreviousX = POINT(0): PreviousY = POINT(1)
END SUB
'  ****** END INCLUDE Polygon Macro Support ******

moving_x = 6
adj_x = 5
i = 0

DO
    CLS : b = INT(RND*15) + 1 : f = INT(RND*15) + 1
    
    PSET (moving_x,10)  : StartX = POINT(0) : StartY = POINT(1) : LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostNear1X = -1 : LeftMostNear1Y = -1 : LeftMostNear2X = -1 : LeftMostNear2Y = -1 : PreviousX = POINT(0) : PreviousY = POINT(1)
LINE - (500,100),b : DoPostLine()
LINE - (550, 120),b : DoPostLine()
LINE - (30,170),b : DoPostLine()
IF LeftMostNear1X = -1 THEN LeftMostNear1X = POINT(0) : LeftMostNear1Y = POINT(1) 
 LINE - (StartX, StartY) ,b : DoPostLine()

IF LeftMostNear1Y < LeftMostNear2Y THEN 

   LeftMostBuddyX = LeftMostNear1X : LeftMostBuddyY = LeftMostNear1Y 

ELSE 

   LeftMostBuddyX = LeftMostNear2X : LeftMostBuddyY = LeftMostNear2Y 

END IF 

PAINT ( (LeftMostX + LeftMostBuddyX) / 2 + IFF(LeftMostY>LeftMostBuddyY,1,-1) ,  (LeftMostY + LeftMostBuddyY) / 2 + 1 ),f,b

    CIRCLE ( (LeftMostX + LeftMostBuddyX) / 2 + IFF(LeftMostY>LeftMostBuddyY,1,-1) ,  (LeftMostY + LeftMostBuddyY) / 2 + 1 ),4,12

    IF moving_x > 634 OR moving_x < 6 THEN adj_x = - adj_x
    moving_x = moving_x + adj_x
    i = i + 1

    _DELAY 0.25
LOOP