Line Drawing - use of LINE and INPUT - Tutorial
009
The following program allows you to input a number by typing it in at the
flashing prompt and then pressing the return/enter key. In this case the number
specifies the number of randomly coloured and positioned lines on the screen.
If you choose a suitable number, the result can be quite pleasing. The command
line needs four parameters to specify its position on the screen :
e.g. LINE 10, 50, 1000, 900 would draw a line from x = 10, y = 50 (near
the bottom left) to x = 1000, y = 900 (near top right on the screen).
REM Lines by R.G.Weston
MODE8
REPEAT
INPUTTAB(15,12)"How many lines
would you like to draw : "no_lines
CLS : OFF
FOR n=1 TO no_lines
PRINTTAB(0,0);n
GCOL0, RND(15)
x1=RND(1279):y1=RND(1024)
x2=RND(1279):y2=RND(1024)
LINE x1,y1,x2,y2
delay=INKEY(20)
NEXT n
delay=INKEY(300)
CLS : COLOUR RND(7)
UNTIL FALSE
Annotated listing :
REM Lines by R.G.Weston
MODE8
REPEAT
INPUTTAB(15,12)"How many lines
would you like to draw : "no_lines
*** the TAB(15,12) causes
the message to appear 15 spaces in and 12 lines down the screen ***
***"no_lines" is the variable
value you input ***
CLS : OFF
FOR n=1 TO no_lines
PRINTTAB(0,0);n ****Shows
how many lines have been drawn - interesting if you put in a very large number
****
GCOL0, RND(15) ****
varies the line colour *****
x1=RND(1279):y1=RND(1024)
**** one end of line ****
x2=RND(1279):y2=RND(1024)
**** other end ******
LINE x1,y1,x2,y2
*** draws the line ****
delay=INKEY(20) ***
waits for 20 centiseconds before drawing the next line ***
**** note you can speed up the
display by pressing a key such as the space bar ****
*** INKEY(20) waits 20 hundredths
of a second unless a key is first pressed, so you can speed things up if
you do so
NEXT n
delay=INKEY(300) *** waits for
three seconds unless a key is pressed ... ***
CLS : COLOUR RND(7) ***
varies the print colour for jollity's sake ***
UNTIL FALSE *** Repeats the program indefinitely
***
Next Tutorial
Richard Weston's Homepage