The VIEWPORT statement specifies the area of the screen or graphic device to be used for graphics output and it also sets the soft-clip boundary limits to match the viewport bounds. The VIEWPORT parameters control the proportions, size, and position of the drawing surface. All graphic output is automatically scaled to fit this drawing surface. The coordinate of the left edge must be less than that of the right edge and the bottom edge must be less than the top edge. It is specified as follows:
VIEWPORT Left,Right,Bottom,Top
The VIEWPORT boundary parameters are defined in GDUs (Graphic Display Units). GDUs are units that describe the physical bounds of the display area on the graphic output device. By definition, Graphic Display Units are 1/100 of the shorter axis of a plotting device. A unit in the X direction and a unit in the Y direction are the same length. The RATIO function returns the ratio of the X to Y physical bounds for the PLOTTER IS device and can be used to determine the VIEWPORT soft-clip limits.
If the ratio is less than 1, the X axis is 100 GDUs and the Y axis is (100*RATIO) GDUs long; if the ratio is greater than 1, the Y axis is 100 GDUs and the X axis is (100*RATIO) GDUs long. The VIEWPORT soft-clip limits should not exceed the physical bounds of the device. By default the left limit is zero, the right limit is the X axis physical bound, the bottom limit is zero, and the top limit is the Y axis physical bound.
Changing the VIEWPORT does not affect any currently displayed graphics, only graphics that you subsequently generate.
Figure 4-1: Simplified Graphics Mapping
As mentioned any graphic points that fall outside the VIEWPORT are eliminated and any lines that cross through the VIEWPORT are clipped at the boundaries. These boundaries are called the soft-clip bounds. They must be within the device physical limits or the hard-clip bounds.
The following program outputs the same graphics information to three different VIEWPORTs.
10 GINIT
20 VIEWPORT 10,50,60,85 !Viewport #1
30 GOSUB 100
40 VIEWPORT 60,100,60,85 !Viewport #2
50 GOSUB 100
60 VIEWPORT 10,100,30,50 !Viewport #3
70 GOSUB 100
80 STOP
90 !
100 FRAME
110 AXES 10,10,20,20,2,3
120 RETURN
130 END
The first and second viewports are exactly the same size, they are just located at different sections of the screen. The third viewport stretches the X axis and compresses the Y axis, causing the image to be distorted.