Welcome everyone to Part 5 of my HP 39gii programming tutorial.
We are going to work with some graphic commands with the HP 39gii.
When it comes to graphics, the HP 39gii has two systems: points and pixels.
Points refers to Cartesian points. Points work just as you would expect: x increases as you go right, y increases as you go up. The boundary of the screen are controlled by the value of Xmin, Xmax, Ymin, and Ymax.
Pixels refer to the LCD terminal screen. Unless you are working with the Plot screen, you are most likely going to work with the LCD terminal screen. In the pixel system, each coordinate is fixed. The 39gii screen is 255 pixels by 126 pixels. In the pixel system, the upper left hand coordinate is (0,0), and the bottom right hand corner is (254,125). The x coordinate increases as you go to the right, but the y coordinate increases as you go down. A row of (about) 14 pixels is reserved for the soft key menus (F1 - F6). In practice you would deal a screen of size 255 × 111.
We will work with the Pixel system in this part of the tutorial.
Common Drawing Commands
In a program, you will want to erase the drawing screen, and at the end, you will need a "hold" command.
Erasing the screen is pretty simple. Whenever you want to erase the LCD screen, type RECT();.
The "hold" command freezes the screen together to show you the picture. Without the "hold" command the calculator just returns to the Home screen. Two "hold" commands are WAIT(0) and FREEZE. I prefer WAIT(0) because the program continues with the press of any key and it works as expected.
Some of the common drawing commands are:
Erase the drawing screen:
[SHIFT] [Math] [ F1 ] [ 4 ] [ ) ]
To put text anywhere on the screen, starting from pixel (x,y):
[SHIFT] [Math] [ F1 ] [ 4 ] [ up ] [ENTER]
To draw a line segment from pixel (x1, y1) to (x2, y2):
[SHIFT] [Math] [ F1 ] [ 4 ] [ LN ]
To draw a white box with black border, given opposite corner pixels (x1, y1) and (x2, y2):
[SHIFT] [Math] [ F1 ] [ 4 ] [ ÷ ]
To draw a circle with center pixel (x,y) and radius of r pixels:
[SHIFT] [Math] [ F1 ] [ 4 ] [ 2 ]
To draw an arc between angle A and B:
[SHIFT] [Math] [ F1 ] [ 4 ] [ 2 ]
To turn the pixel (x,y) on:
[SHIFT] [Math] [ F1 ] [ 4 ] [ ( ]
To turn the pixel (x,y) off:
[SHIFT] [Math] [ F1 ] [ 4 ] [ x² ]
Colors (Really Grayscale) on the 39gii
The 39gii has four grayscale shades. Each have the following values:
0 = black
1 = dark gray
2 = light gray
3 = white
You can use color in the following commands. The color arguments are always optional.
RECT_P(x1,y1,x2,y2,edge color,fill color);
Fonts with the 39gii
The HP 39gii has two fonts: large and small. They have the following values:
0 (or left out) = default, whatever the system setting is
1 = force small font
2 = force large font
The syntax of TEXTOUT_P with font size is:
Let's use these commands in some programs.
The Program RTEXT
RTEXT(desired string, number of places)
RTEXT places a desired string all over the screen at random.
FOR K FROM 1 TO times DO
Example: Sprinkle "39gii" in 75 random places. From the Home screen type RTEXT("39gii",75). You get something like this:
The Program BOXLH
The program BOXLH draws a box of length L and height H. The box grows from the center pixel (127, 56). Input: BOXLH(L,H)
Draw a box with length of 60 pixels and height of 56 pixels. From the home screen type BOX(60,56).
The Program BOX3D
BOX3D takes the box drawing program one step further, by adding some depth to make the box look three-dimensional.
L = length of the box in pixels
H = height of the box in pixels
D = depth of the box in pixels
A = tilt angle in degrees
BOX3D sets the angle mode to Degrees. (HAngle = 0).
Note: The order of the drawing commands is important, especially when it comes to the RECT and RECT_P commands.
Example: Length of 45 pixels, height of 27 pixels, depth of 33 pixels, at an angle of 45°
A Short Animation: The Program GROWTH
GROWTH is a program of an arc that grows by π/6 (30°) every second until a circle is completed. Radians angle mode (HAngle=1) is set in this program.
FOR K FROM 0 TO 2π STEP π/6 DO
CDEMO: Colors and Fonts
CDEMO shows the three colors and the small font. You can cut down on the lines needed by using a clever mathematical equation and a well set up FOR loop.
FOR K FROM 1 TO 3 DO
Well, I hope these five programs demonstrate what you can do with the graphing commands with the 39gii. As always, I hope encourages you to program and to try things out!
In Part 6, we are going interactive!
Until next time,
This blog is property of Edward Shore. 2013