Friday 1 June 2012

Basic Programming Tutorials (5)

Color Statement In Basic


The screen statement does not clear the screen (except it is used first time) so to clear the screen use CLS when color monitor  is used.
Next is to tell the computer about the background colors you want for the screen using the color statement. The format of the color statement on the screen mode. Color will not function in high resolution graphics mode i.e., in SCREEN 2. In the text mode (Screen 0), the format of the statement will be :-

Line # COLOR [foreground], [background]
The foreground color must be an integer from 0 to 31. The color numbers 16 to 31 are the blinking versions of the colors from 0 to 15 and are found by adding 16 into the corresponding color number from 0 to 15. For example if the foreground color number is 2 (for green), then blinking green will be 18 (i.e., 2+16)


The background color must be an integer from 0 to 7. Note that if the background color is the same as that of the foreground, then the characters displayed on the screen will not be visible. (Blinking colors in background are not permitted). Consider the following statements :-

20 Screen 0

30 Color 13,2,4

Statement in line number 20 sets the screen in text mode, and the statement in line number 30 sets the text light magenta in green background.
___________________________________________________________________________________

Graphics in Basic: Making A red and white letter on the screen with blue background

Medium Resolution Graphics:

Pset statement is used to specify the co-ordinates X,Y of the point, where it appears on the screen.
The following program illustrates a red and white letter on the screen  with blue background.

Program:


10 REM**red verticle lines of 5 pixels**

20 CLS

30 Screen 1,0

40 Color 1,0

50 Pset (40,10),2

60 Pset (40,11),2

70 Pset (40,12),2 

80 Pset (40,13),2

90 Pset (40,14),2

100 REM**White horizontal line of height 4 pixels**

110 Color 1,1

120 Pset (41,14),3

130 Pset (42,14),3

140 Pset (43,14),3

150 Pset (44,14),3

160 END

Output:

Write the program in your GW-Basic Compiler, you will see a Red verticle line of 5 pixels and white horizontal line of height 4 pixels

_______________________________________________________________________________________

A Basic Program:Drawing a line using for..next loops

Program:


10 REM**draw a line using for..next loop**

20 Screen 1,0

30 Color 2,0

40 For a=0 to 60

50 X=80+2*a

60 Y=50+a

70 Pset (X,Y),2  

80 Next a

90 END

Output:

Write the program in your GW-Basic Compiler, you will see a horizontal vertical line.

_____________________________________________________________________________________

High resolution Graphics In Basic


High resolution mode allows to draw more finely detailed shapes than those possible on medium resolution graphics.

This is because the number of rows and coloumns are twice the number available in medium resolution. A slightly different screen instruction must be given to do high resolution.

The instruction screen 2 instead of screen 1 or 0 either on immediate mode or program mode.


The statement sets up the screen for high resolution graphics.


The Pset and line statements are used to draw points and lines in high resolution graphics

Further below you will see some programs in graphic mode to draw different lines and shapes using line statement
_____________________________________________________________________________

Graphics in Basic: Making A red and white letter on the screen with blue background

Medium Resolution Graphics:

Pset statement is used to specify the co-ordinates X,Y of the point, where it appears on the screen.
The following program illustrates a red and white letter on the screen  with blue background.

Program:


10 REM**red verticle lines of 5 pixels**

20 CLS

30 Screen 1,0

40 Color 1,0

50 Pset (40,10),2

60 Pset (40,11),2

70 Pset (40,12),2

 

 

No comments:

Post a Comment