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: 


Other programs 
The Casio FX7400G and CFX9850G 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 CFX9850G version of the program also accepts an indicator of the color in which the line is to be drawn.
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 xcoordinate of the first point into the A variable, the ycoordinate of the first point into the B variable, the xcoordinate of the second point into the C variable, the ycoordinate of the second point into the D variable, and the color code into the E variable. On the CFX9850G calculator, the color code is 0 for green, 1 for orange, and any other value (such as 1) for blue. On the FX7400G 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 FX7400G, the only available color is black, and the intersection point is black. On the CFX9850G, the intersection point is orange if any line segment is orange, otherwise blue if any line segment is blue, otherwise green.
The DRAWLINE program has two variations, a CFX9850G version and an FX7400G version. The FX7400G version can be used on the CFX9850G, but will draw all lines in blue. The CFX9850G version cannot be used on the FX7400G.
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 (FX7400G version) (327 bytes):
; Program DRAWLINE (FX7400G version) ; ; Description: ; Draws the portion of a line segment between two points that lies ; in the calculator display area. ; ; Formal parameters: ; A: The Xcoordinate of the first endpoint of the line segment ; B: The Ycoordinate of the first endpoint of the line segment ; C: The Xcoordinate of the second endpoint of the line segment ; D: The Ycoordinate of the second endpoint of the line segment ; E: Ignored [color code in CFX9850G 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 Xcoordinate 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+(IG)(XminF)/(HF)>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(GI)(HXmax)/(HF)>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 Ycoordinate 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+(HF)(YminG)/(IG)>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(HF)(IYmax)/(IG)>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 CFX9850G 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 CFX9850G 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 (CFX9850G version) (389 bytes):
; Program DRAWLINE (CFX9850G version) ; ; Description: ; Draws the portion of a line segment between two points that lies ; in the calculator display area. ; ; Formal parameters: ; A: The Xcoordinate of the first endpoint of the line segment ; B: The Ycoordinate of the first endpoint of the line segment ; C: The Xcoordinate of the second endpoint of the line segment ; D: The Ycoordinate 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 Xcoordinate 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+(IG)(XminF)/(HF)>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(GI)(HXmax)/(HF)>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 Ycoordinate 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+(HF)(YminG)/(IG)>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(HF)(IYmax)/(IG)>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 CFX9850G calculator:
And the following diagram on the FX7400G calculator:
[ Previous page  Top of page  Next page ]
Copyright © 2002 Brian Hetrick
Page last updated 7 July 2002.