perhaps you will see better what is happening if I were to rewrite the code like this
' DOUBLE BUFFERING!
' SMOOTH MOVEMENT IN FREEBASIC WITHOUT HAVING TO USE "SLEEP"
'
' THIS PROGRAM SHOWS HOW TO FIX FLICKERING GRAPHICS.
'
'-------------------------------------------------------------------------------
' OPEN A SCREEN 800 PIXELS WIDE 600 PIXELS HIGH
SCREEN 19,,2,
' DECLARE VARIABLES THAT WILL BE USED (REQUIRED BY MY VERSION OF FB NOTHING TO WORRY ABOUT)
dim as integer X1,Y1,X2,Y2,XF1,XF2,YF1,YF2, RIGHTEDGE,LEFTEDGE,TOPEDGE,BOTTOMEDGE
LEFTEDGE=0
RIGHTEDGE=800
TOPEDGE=0
BOTTOMEDGE=600
X1=0:' X POINT 1
Y1=10:' Y POINT 1
X2=100:' X POINT 2
Y2=100:' YPOINT 2
XF1=1:' X MOVEMENT FLAG FOR POINT 1
XF2=1:' X MOVEMENT FLAG FOR POINT 2
' YF1=0:' Y MOVEMENT FLAG FOR POINT 1
YF1=-1:' Y MOVEMENT FLAG FOR POINT 1
YF2=-1:' Y MOVEMENT FLAG FOR POINT 2
SCREENSET 1,0:' SET WORKPAGE 1, VISIBLE PAGE 0 (DONT WORRY!)
DO
' DRAW A LINE
LINE(X1,Y1)-(X2,Y2)
'-------------------------------------------------------------------------------
' MOVE POINT 1
'-------------------------------------------------------------------------------
X1 = X1 + XF1 ' MOVE POINT 1 LEFT AND RIGHT
IF (X1>=RIGHTEDGE) OR (X1<=LEFTEDGE) THEN
XF1 = -XF1' REVERSE MOVEMENT WHEN WE REACH LEFT OR RIGHT
END IF
Y1 = Y1 + YF1 ' MOVE POINT 1 UP AND DOWN
IF (Y1>=BOTTOMEDGE) OR (Y1<=TOPEDGE) THEN
YF1 = -YF1 ' REVERSE MOVEMENT WHEN WE TOP OR BOTTOM
END IF
'-------------------------------------------------------------------------------
' MOVE POINT 2
'-------------------------------------------------------------------------------
X2 = X2 + XF2 ' MOVE POINT 1 LEFT AND RIGHT
IF (X2>=RIGHTEDGE) OR (X2<=LEFTEDGE) THEN
XF2 = -XF2' REVERSE MOVEMENT WHEN WE REACH LEFT OR RIGHT
END IF
Y2 = Y2 + YF2 ' MOVE POINT 1 UP AND DOWN
IF (Y2>=BOTTOMEDGE) OR (Y2<=TOPEDGE) THEN
YF2 = -YF2 ' REVERSE MOVEMENT WHEN WE TOP OR BOTTOM
END IF
SCREENCOPY ' UPDATE SCREEN WITH NEW IMAGE
'-------------------------------------------------------------------------------
'
'-------------------------------------------------------------------------------
SLEEP 2 ' WAIT FOR A SHORT TIME FOR SCREEN UPDATE TO COMPLETE THIS AVOIDS FLICKER
CLS ' CLEAR THE SCREEN SO THAT WE CAN DRAW THE NEXT IMAGE
LOOP UNTIL INKEY$<>"" ' ETERNAL LOOP UNTIL USER PUSHES ANY KEY
As stormbringer mentioned this code draws a line between X1,Y1 and X2,Y2. these variables are co-ordinates within the screen. the movement is cotrolled by the variables XF1,YF1,XF2,YF2. the values kept in the movement variables is added to X1,Y1,X2,Y2 respectively. a test is perfomed to see if either point has reached the edge of the sceen. and if so the movement values are reversed. this means that instead of continuing to move right past the edge instead the point will begin to move left until it reaches the left edge of the screen then the movement values are reversed yet again and the whole process starts repeats
do you understand what is happening here?
SCREENCOPY
SLEEP 2
CLS
LOOP UNTIL INKEY$<>""
the screen copy updates the screen with the new image (the line that you drew from X1,Y1 to X2,Y2)
sleep waits for a short moment to allow the screen to update with the new image
cls clears the screen so that when we draw the next line the old line will be erased
just for fun try commenting out cls so that it reads like this -
'CLS
the result is intersting. Is there anything that is unclear?