Previous page Next page Navigation bar

Programs

Utility Programs

Line Drawing

Summary Description

Program:

DRAWLINE

Version:

1.0, 7 July 2002

Description:

This program draws lines on the calculator display, truncating the lines to those segments that lie within the display area.

Compatability:

Is compatible CFX-9850G

Compatible with CFX-9850G

Is compatible FX-7400G

Compatible with FX-7400G

Other programs
required:

VRPRE, VRSAVFJ, VRRESFJ

Detailed Description

The Casio FX-7400G and CFX-9850G calculators permit programs to draw on the calculator display screen. Programs do this by plotting the endpoints of the line, then executing the Line command. The Line command draws a line between the two most recently plotted points. Points that fall outside the calculator display area are not plotted. This implies that lines may be drawn between unrelated endpoints, if intermediate points plotted lie outside the calculator display area.

The DRAWLINE program takes two line endpoints, and draws that portion of the line segment between them that is in the calculator display area. The CFX-9850G version of the program also accepts an indicator of the color in which the line is to be drawn.

Usage

Load the DRAWLINE, VRPRE, VRSAVFJ, and VRRESFJ programs into the calculator. Invoke the VRPRE program before the first call to DRAWLINE. Ensure the calculator view window limits are set as desired, either through the ViewWindow command or through stores to the individual Xmin, Xmax, Ymin, and Ymax pseudovariables.

To draw a line segment from one point to another, place the x-coordinate of the first point into the A variable, the y-coordinate of the first point into the B variable, the x-coordinate of the second point into the C variable, the y-coordinate of the second point into the D variable, and the color code into the E variable. On the CFX-9850G calculator, the color code is 0 for green, 1 for orange, and any other value (such as -1) for blue. On the FX-7400G calculator, the color code is ignored. Then invoke the DRAWLINE program.

The DRAWLINE will draw the part, if any, of the line segment between (A,B) and (C,D) that falls into the view window, in the color specified by the color code E.

When different line segments intersect in the display, the effects are dependent on the calculator. On the FX-7400G, the only available color is black, and the intersection point is black. On the CFX-9850G, the intersection point is orange if any line segment is orange, otherwise blue if any line segment is blue, otherwise green.

Program Source

The DRAWLINE program has two variations, a CFX-9850G version and an FX-7400G version. The FX-7400G version can be used on the CFX-9850G, but will draw all lines in blue. The CFX-9850G version cannot be used on the FX-7400G.

The programs are available as a text file with .CAT contents, or may be entered as shown below. A semicolon (“;”) marks the beginning of a comment, which is not to be entered into the calculator. Remember that these programs are copyrighted; see the copyright issues page for limitations on redistribution.

Program DRAWLINE (FX-7400G version) (327 bytes):

; Program DRAWLINE (FX-7400G version)
;
; Description:
;   Draws the portion of a line segment between two points that lies
;   in the calculator display area.
;
; Formal parameters:
;   A: The X-coordinate of the first endpoint of the line segment
;   B: The Y-coordinate of the first endpoint of the line segment
;   C: The X-coordinate of the second endpoint of the line segment
;   D: The Y-coordinate of the second endpoint of the line segment
;   E: Ignored [color code in CFX-9850G version]
;
; Implicit inputs:
;   Xmax, Xmin, Ymax, Ymin: calculator display area limits
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   Changes the current point on the calculator display
;
; Symbols used:
;   -> is assignment arrow
;   => is conditional jump
;   / is division operator
 
Prog "VRSAVFJ"     ; Save variables F through J
A->F               ; Get work copy of
B->G               ;   first endpoint
C->H               ; Get work copy of
D->I               ;   second endpoint
If F>H             ; Sort points into
Then F->J          ;   ascending order
H->F               ;   by X-coordinate
J->H               ;
G->J               ;
I->G               ;
J->I               ;
IfEnd              ; [End of sort]
F>Xmax=>Goto 0     ; If both points are outside X range,
H<Xmin=>Goto 0     ;   return without drawing anything
If F<Xmin          ; If lower point is below lower X bound
Then G+(I-G)(Xmin-F)/(H-F)->G
                   ;   find intersection point
Xmin->F            ;   with lower X bound
IfEnd              ; [End of test on lower point]
If H>Xmax          ; If upper point is above upper X bound
Then I-(G-I)(H-Xmax)/(H-F)->I
                   ;   find intersection point
Xmax->H            ;   with upper X bound
IfEnd              ; [End of test on upper point]
If G>I             ; Sort points into
Then F->J          ;   ascending order
H->F               ;   by Y-coordinate
J->H               ;
G->J               ;
I->G               ;
J->I               ;
IfEnd              ; [End of sort]
G>Ymax=>Goto 0     ; If both points are outside Y range,
I<Ymin=>Goto 0     ;   return without drawing anything
If G<Ymin          ; If lower point is below lower Y bound
Then F+(H-F)(Ymin-G)/(I-G)->F
                   ;   find intersection point
Ymin->G            ;   with lower Y bound
IfEnd              ; [End of test on lower point]
If I>Ymax          ; If upper point is above upper Y bound
Then H-(H-F)(I-Ymax)/(I-G)->H
                   ;   find intersection point
Ymax->I            ;   with upper Y bound
IfEnd              ; [End of test on upper point]
Plot F,G           ; Plot the adjusted first point
Plot H,I           ; Plot the adjusted second point
Line               ; Draw the line between them
Lbl 0
Prog "VRRESFJ"     ; Restore variables

The DRAWLINE program for the CFX-9850G is the same as the above, with the exception of the two Plot statements and the Line statement. The changes needed are shown in bold in the following program listing. Also, as the .CAT file format does not permit two different programs to have the same name, the CFX-9850G version of the program is called DRAW9850 in the .CAT format file. You can rename this program to DRAWLINE after you have downloaded it to the calculator.

Program DRAWLINE (CFX-9850G version) (389 bytes):

; Program DRAWLINE (CFX-9850G version)
;
; Description:
;   Draws the portion of a line segment between two points that lies
;   in the calculator display area.
;
; Formal parameters:
;   A: The X-coordinate of the first endpoint of the line segment
;   B: The Y-coordinate of the first endpoint of the line segment
;   C: The X-coordinate of the second endpoint of the line segment
;   D: The Y-coordinate of the second endpoint of the line segment
;   E: Color code for the line segment (-1 = green, 0 = blue, 1 =
;      orange)
;
; Implicit inputs:
;   Xmax, Xmin, Ymax, Ymin: calculator display area limits
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   Changes the current point on the calculator display
;
; Symbols used:
;   -> is assignment arrow
;   => is conditional jump
;   / is division operator
 
Prog "VRSAVFJ"     ; Save variables F through J
A->F               ; Get work copy of
B->G               ;   first endpoint
C->H               ; Get work copy of
D->I               ;   second endpoint
If F>H             ; Sort points into
Then F->J          ;   ascending order
H->F               ;   by X-coordinate
J->H               ;
G->J               ;
I->G               ;
J->I               ;
IfEnd              ; [End of sort]
F>Xmax=>Goto 0     ; If both points are outside X range,
H<Xmin=>Goto 0     ;   return without drawing anything
If F<Xmin          ; If lower point is below lower X bound
Then G+(I-G)(Xmin-F)/(H-F)->G
                   ;   find intersection point
Xmin->F            ;   with lower X bound
IfEnd              ; [End of test on lower point]
If H>Xmax          ; If upper point is above upper X bound
Then I-(G-I)(H-Xmax)/(H-F)->I
                   ;   find intersection point
Xmax->H            ;   with upper X bound
IfEnd              ; [End of test on upper point]
If G>I             ; Sort points into
Then F->J          ;   ascending order
H->F               ;   by Y-coordinate
J->H               ;
G->J               ;
I->G               ;
J->I               ;
IfEnd              ; [End of sort]
G>Ymax=>Goto 0     ; If both points are outside Y range,
I<Ymin=>Goto 0     ;   return without drawing anything
If G<Ymin          ; If lower point is below lower Y bound
Then F+(H-F)(Ymin-G)/(I-G)->F
                   ;   find intersection point
Ymin->G            ;   with lower Y bound
IfEnd              ; [End of test on lower point]
If I>Ymax          ; If upper point is above upper Y bound
Then H-(H-F)(I-Ymax)/(I-G)->H
                   ;   find intersection point
Ymax->I            ;   with upper Y bound
IfEnd              ; [End of test on upper point]
If E=0             ; If line is to be blue
Then Plot F,G      ;   Plot first endpoint in blue
Plot H,I           ;   Plot second endpoint in blue
Line               ;   Draw line in blue
Else If E=1        ; Otherwise, if line is to be orange
Then Orange Plot F,G ; Plot first endpoint in orange
Orange Plot H,I    ;   Plot second endpoint in orange
Orange Line        ;   Draw line in orange
                   ; Otherwise the line is to be green
Else Green Plot F,G ;  Plot first endpoint in green
Green Plot H,I     ;   Plot second endpoint in green
Green Line         ;   Draw line in green
IfEnd              ; [End of test if orange]
IfEnd              ; [End of test if blue]
Lbl 0
Prog "VRRESFJ"     ; Restore variables

In addition to these two programs, the text file with .CAT contents contains a unit test. This unit test draws the following diagram on the CFX-9850G calculator:

Screen shot of unit test on CFX-9850G

And the following diagram on the FX-7400G calculator:

Screen shot of unit test on FX-7400G

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 7 July 2002.

Brian’s Casio Calculator Corner

Home

Programs

Index

Linkage Conventions

Mathematics

Finance

Physics

Utility

Index

Save/Restore

Line Drawing

Boolean Operations

Bitwise Operations

Tutorial

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data