Programming HP Calculators/Commands/Drawing Commands
The drawing commands are somewhat confusing in that they reference parts of the 'plot', not parts of the physical screen.
It is intuitive to assume that (knowing that the screen is 131x64 pixels wide, and that the calculator references points by a Cartesian-like system) a pixel at (1,1) will always be the most bottom-right pixel on the screen.
However, this is not the case. (1,1) is the pixel at (1,1) on the infinite 'plot'. This means that it will only be the bottom-right pixel, as expected, when the plot is set to the dimensions 1?X?131 and 1?Y?64. This can be done by setting the (X/Y)(MIN/MAX) commands to appropriate values:
Adding this code to the start of your program will set the calculator's plot size to these specifications automatically, ensuring smooth operation of your program. However, upon the program's completion, any graph the user might have set up will be displayed on a (presumably) incorrect plotsize, which may frustrate the user. You could work around this like follows:
XMIN?A:XMAX?B: YMIN?C:YMAX?D: 1?XMIN:131?XMAX: 1?YMIN:64?YMAX: <program code goes here> A?XMIN:B?XMAX: C?YMIN:D?YMAX
Of course, this adds bloat to the program somewhat, but will resolve the problem as long as you don't use the variables you selected in the program for other purposes. An alternate method would be to store the values in a list.
- <cent-x> and <cent-y> are the x- and y-coordinates of the center of the arc.
- <radius> is simply the radius of the arc.
- <start> is the starting angle of the arc, and <end> the finishing angle.
- Angles are measured mathematically, that is, the same as the unit circle; with 0° being the equivalent of due east on the compass, not due north, and counter-clockwise being the positive direction.
- The ARC command utilises the current angle mode for arguments <start> and <end>. Therefore, if you design your arcs using degrees, it may be wise to set the angle mode to degrees programmatically like so:
- Alternately, an HAngle value of 2 or 3 can be used to set the calculator in radians or grads, respectively.
- The ARC command is particularly slow, so if you need to draw extensively, it may be wise (although time-consuming) to use MAKEGROB.
Draws a full circle of radius 15px, from the center of the screen.
ARC 65;32;15;10;80: ARC 65;32;15;100;170: ARC 65;32;15;190;260: ARC 65;32;15;280;350:
Draws a full circle comprised of four arcs, but the circle is missing a arc of 20° at each cardinal point. Represented more concisely using a loop:
FOR X=0 TO 270 STEP 90; ARC 65;32;15;10+X;80+X: END:
- (<x1>,<y1>) are the coordinates of the box's starting corner.
- (<x2>,<y2>) are the coordinates of the corner that completes the box.
- There are no limitations on the corners used, as long as they are binary opposites, that is top-left and bottom-right or bottom-left and top-right. Additionally, the order they are used in is not significant.
Draws a box around the border of the screen.
BOX 1;1;131;64: BOX 2;2;130;63:
Draws a border 2 pixels thick around the screen. More concisely:
FOR X=0 TO 1; BOX 1+X;1+X;131-X;64-X: END:
This allows you to easily adjust the thickness of your border by simply adjusting the FOR command; for "FOR X= TO Z" the border will always be (Z-1) pixels thick.
- Erases the contents of the screen, as simple as that.
- Adding ERASE: before any of the drawing commands is usually a good idea to prevent the program from drawing over the programs catalog, or any other view that the user happens to be in at the time.
- Stops the program, and waits for a keypress to continue.
- Use it after you finish your drawing commands, so that the user has time to look at the screen!
- Draws a line from point (<x-start>,<y-start>) to point (<x-end>,<y-end>).
LINE 1;1;131;64: LINE 1;64;131;1:
Draws a cross across the screen.
PIXON <x>;<y>: PIXOFF <x>;<y>:
- Turns the pixel at (<x>,<y>) on or off.
- PIXON and PIXOFF are reasonably fast, but when inside a FOR loop (see below), can be appreciably slow. If you want to do something like a 'pretend' loading bar (or even a real one if it's applicable), you should use LINE or TLINE as they are faster.
FOR X=1 TO 131 STEP 1; FOR Y=64 TO 1 STEP -1; PIXON X;Y: END:END: FOR X=131 TO 1 STEP -1; FOR Y=1 TO 64 STEP 1; PIXOFF X;Y: END:END:
Fills the screen with pixels from left-to-right, top-to-bottom, then reverses the process.
- Same as LINE, except the command performs a slightly different task - instead of turning a line of pixels on, it toggles them. That is to say, if all the pixels you're drawing across are off already (say you just used ERASE:), it will function as a regular LINE, but if there are already pixels turned on, it will turn those off, and conversely turn off pixels on.
ERASE: DISPLAY? G1: GROBNOT G1: ?DISPLAY G1: TLINE 1;1;131;64: TLINE 1;64;131;1:
Draws a cross in white across the screen, after turning on all the pixels. Therefore, it acts the same as:
ERASE: LINE 1;1;131;64: LINE 1;64;131;1: DISPLAY? G1: GROBNOT G1: ?DISPLAY G1: