BASIC Programming
On micro computers it is possible to produce graphics output in addition to printing letters, numbers and other usual characters. The computers can draw fine dots called pixels on the screen at any location you specify.14.1 Screen Function
The screen function can be set to either of the following
modes.
·
Text mode (Screen
0)
·
Medium resolution mode (Screen 1)
·
High resolution mode (Screen 2)
The format of the Screen statement is
Line # Screen mode
Text Mode:- in the Text mode the characters are
displayed on the screen in 40 columns and 25 rows (40×25) or 80 columns and 25
rows (80×25) depending upon the selection of screen width.
Medium Resolution Mode:- in the Medium resolution
mode the screen in divided into 320 columns and 200 rows. The individual point
on screen is referenced by specifying the column(0 to 319) and row(0 to 199).
High Resolution Mode:- in high resolution mode the
screen in divided into 640×200 points.
14.2 Color Statement:-
the format of the Color statement
depends on the screen mode. Color will not function in high resolution. In the
text mode resolution the format of color statement is;
Line # Color [foreground], [background]
The foreground color number must be an integer from 0 to 31.
The color numbers from 16 to 31 are blinking versions of the colors from 0 to
15.
The background color must be an integer 0 to 7.
In the medium resolution mode Screen 1, the color statement
has the following format;
Line # Color [background], [palette]
16 background colors are available having code from 0 to
15.after selecting a background color, select a palette( a palette is the range
of colors used by an artist in painting). The palettes are numbered 0 and 1
each with four colors.
Color
|
Code
|
Color
|
Code
|
Black
|
0
|
Gray
|
8
|
Blue
|
1
|
Light blue
|
9
|
Green
|
2
|
Light green
|
10
|
Cyan
|
3
|
Light cyan
|
11
|
Red
|
4
|
Light red
|
12
|
Magenta
|
5
|
Light magenta
|
13
|
Brown
|
6
|
Yellow
|
14
|
white
|
7
|
Bright white
|
15
|
Color
|
Code
|
|
Palette 0
|
Background
|
0
|
Green
|
1
|
|
Red
|
2
|
|
Brown
|
3
|
|
Palette 1
|
Background
|
0
|
Cyan
|
1
|
|
Magenta
|
2
|
|
White
|
3
|
|
14.3 Medium Resolution Mode:-
Pset statement is used to
specify the coordinates X, Y of the point where it appears on the screen.
Program
10 Rem *Red vertical line of 3 pixels*
20 Screen 1,0
30 Color 1,0
40 Pset (40, 10), 2
50 Pset (40, 11), 2
60 Pset (40, 12), 2
70 Rem * white horizontal line of 3 pixels*
80 Color 1,1
90 Pset (41, 14), 3
100 Pset (42, 14), 3
110 Pset (43, 14), 3
120 end
14.4 High Resolution Mode:-
High resolution mode allows to
draw more fine shapes than those possible on medium resolution mode.
The Pset and Line statements are used to draw points and
lines in high resolution graphics. These statements have the same form as in
medium resolution except that the number 1 at the end of either statement
indicates a white point or line and the number 0 indicates a black point or
line.
Program
10 Rem * program to draw a plus shape symbol*
20 screen 2
30 Line (100, 100) – (300, 100), 1
40 Line (200, 50) – (200, 150), 1
50 end
Rectangles or square box can be drawn by adding B using Line
statement with points of upper left and lower right corners of the square or
rectangle.
10 Rem * Red square box inside a green box*
20 screen 1
30 Line (50,50) – (110,110), 1, B
40 Line (55,55) – (105,105), 2, B
50 End
14.5 Draw Statement:-
Draw statement is used to draw lines
and other shapes. It has the following format;
Line# Draw string
A string consists of single character command followed by a
prefix that controls the size, direction etc. of the line and is enclosed in
the quotation marks for example :-
50 Draw “E30”
The drawing commands that may be used are given below with
the digit “n” as the prefix to describe the number of points moved by command.
Command Purpose
↑ Un Upward move through n points.
↓ Dn Downward move through n points.
→ Rn Rightward move through n points.
← Ln Leftward move through n points.
↗ En Diagonally Right Upward move through
n points.
↘ Fn Diagonally Right Downward move
through n points.
↙ Gn Diagonally Left Downward move through
n points.
↖ Hn Diagonally Left Upward move through n
points.
Program
10 Rem *Rectangle*
20 Screen 1
30 Draw “U80 R80 D80 L80”
40 End
14.6 Circles and Ellipses:-
in BASIC there is a build-in
command that will draw circles, part of a circle or ellipse. In medium graphic
resolution it has the following format;
Circle (X,Y), R, C, S, E, A
It will draw a circle of radius R with center at (X, Y) in
the color C. S is the start arc position, E is the end arc position and A is
the aspect ratio (height/width).
Program
10 Rem *Brown upper and Green lower semi circles*
20 Screen 1, 0
30 Color 7, 0
40 Circle(50, 100), 30, 3, 0, 3.14
50 Circle(120, 100), 30, 1, 3.14
