Printer Graphics

Decimal BASIC for Windows deals with a printer as a graphics device.
Use a PostScript printer driver to make a EPS file(EPS files). Note. Metafile format is suitable for the images that are drawn by PLOT LINES or PLOT AERA. For the images that are drawn with a lot of points such as Mandelbrot sets, bitmap format is suitable.

1. Setting the printer

The printer shoud be set up before the program run.
Select Option menu - Graphics and Click Printer Settings to set up the printer and the paper.

2. Execute a graphics program

On the Graphics fundamental settings dialog, appoint Metafile(Size) in Image Format to make a metafile of the indicated size. The resolution shall be that of the printer set up previously. The directed area shall be the drawing pane.

When Metafile(printer) in Image Format is appointed, The printable area of the printer set up previously shall be the graphics device, and metafile shall be made for it. Normally the drawing pane is the maximum square at the bottom left corner in the printable area.
We can give an additional margin to the printer default margin. Print position can be changed as Uppermost when the drawing pane is a square.

You see the preview screen as below after the execution finishes. In this screen, you can print the result, save as a EMF file, copy it to the clipboard. You can paste the image as a metafile into MS-Word or so.

2. Appended statements

The following Full BASIC statemements are appended. Delails of them are described ANSI standard.
SET VIEWPORT
SET DEVICE WINDOW
SET DEVICE VIEWPORT
ASK VIEWPORT
ASK DEVICE WINDOW
ASK DEVICE VIEWPORT
SET CLIP
ASK CLIP

Note. The unit of DEVICE VIEWPORT is meter.

3. Examples

(1) Alter the aspect ration

The following program alter the aspect ratio of the width to the height into 3:4.

140 SET DEVICE WINDOW 0, 3/4, 0, 1
150 SET VIEWPORT      0, 3/4, 0, 1
160 SET WINDOW  -3, 3,  -4, 4
170 DRAW grid
180 DEF f(x)=x*(x-1)*(x+1)
190 FOR x=-3 TO 3 STEP 0.002
200    PLOT LINES: x,f(x);
210 NEXT x
220 END

Explanation
SET DEVICE WINDOW and SET VIEWPORT statements with the parameters 0, 3/4, 0, 1 are executed to make the aspect ratio of the width to the height into 3:4.
When we want to use the paper landscape, for example, the ratio of the height to the width to be 3:4, we execute the followings.
140 SET DEVICE WINDOW 0, 1, 0, 3/4
150 SET VIEWPORT 0, 1, 0, 3/4
Note that the parameters of these two statements must not exceed 1. For example, the following is wrong, if all the compatibility option settings are set to strictly obeying the standard, this statement raises a non-fatal exception to proceed next without doing anything.
SET DEVICE WINDOW 0, 4/3, 0, 1 ! this is wrong.

(2) Addition of margins

We can increase the margins around by shrinking DEVICE VIEWPORT.
When the following two lines are appended to the program above, the margins around are incased by 1cm.

120 ASK DEVICE VIEWPORT dvleft,      dvright,      dvbottom,      dvtop
130 SET DEVICE VIEWPORT dvleft+0.01, dvright-0.01, dvbottom+0.01, dvtop-0.01

Setting Additional Margins to 10mm in the Graphics fundamental settings dialog corresponds with executing these two statements beforehand.

(3) Size designation

When we want to have the image of width w mm, height of h mm, we execute the following if h<w.

ASK DEVICE VIEWPORT dvleft, dvright,         dvbottom, dvtop
SET DEVICE VIEWPORT dvleft, dvleft + w/1000, dvbottom, dvbottom + h/1000
SET DEVICE WINDOW 0, 1, 0, h/w
SET VIEWPORT      0, 1, 0, h/w

If w<h, modify the lower two lines as follows.
SET DEVICE WINDOW 0, w/h, 0, 1
SET VIEWPORT 0, w/h, 0, 1

4. Supplements

  1. ASK DEVICE SIZE w,h,s$
    w, h are numeric variables, s$ a string variable.
    Assigns the width and the height of printable area to w and h, and "METERS" to s$.
    The metric unit of the width and the height is the meter.
  2. The following statement returns meaningful value. The unit is the number of pixels.
    ASK PIXEL SIZE
  3. The following two statements return -1. Note that they cause no exceptions.
    ASK PIXEL VALUE
    ASK PIXEL ARRAY
  4. The following statements cause exceptions.
    GET POINT
    LOCATE POINT
  5. When the Image Format is Printer(direct) executing CLEAR feeds a page.
    When the Image Format is Metafile(printer), executing CLEAR paints the whole pane with the background color, that is, then color of color index 0 , never feed a page even if the image is outputted to the printer.

5. Non-Standard enhancement

SET AXIS COLOR numeric-exp
Change the color used by DRAW GRID and DRAW AXES.
When you want to change the axis color to black, execute
SET AXIS COLOR 1
This statement shall be removed or altered in syntax in future.


Back