HP Prime for All

English  Русский 

Author: Edward Shore (original article)

This section we will start covering some of the graphics features of the HP Prime Programming Language. We touched on graphics a bit when we used STARTAPP and STARTVIEW to call up the Plot screen of certain apps (Function, Parametric, Polar, Advanced Grpahing).

This time we are going to use drawing commands that can be used in any HP Prime app. In a sense we are creating a graphic object (GROB). The HP Prime allows for ten graphic objects, named G0 - G9. For this tutorial series, (unless specified) I am always going to use the default GROB, G0. This makes typing commands much easier.

Cartesian vs Pixel

Each graphic object operates in either one of two coordinate systems: Cartesian and pixel.
If you worked with the Hewlett Packard HP 39gii calculator, this might look familiar to you.

The features of the Cartesian system (x,y) are these:

The Pixel System (x,y):

The Drawing Commands

The HP Prime has two sets of drawing commands: one for the Cartesian system and one for the Pixel system.

All commands for the Pixel system will have a _P suffix attached. For example:

LINE draws a line using Cartesian coordinates, while LINE_P draws a line using Pixel coordinates.

General Access: (in the Programming Editor)
Drawing Commands for the Pixel system: Cmds 2(Drawing), 6(Pixels)
Drawing Commands for the Cartesian system: Cmds 2(Drawing), 7(Cartésian)

Clearing the GROB screen

To clear the GROB screen, we will simply type RECT().
The wipes the screen, leaving it white. It is necessary to do this at least at the beginning of each program containing drawing commands.
In a sense, RECT() is similar to PRINT().

Hint: To paint an entire screen a specific color, use RECT(color).

Showing the Graphics Screen

It is not enough to type the drawing commands. We need a command to tell the HP Prime to show the graphics. Two ways to do it are:

FREEZE: This does exactly what it says, freezes the screen.
To exit, tap the screen or press J.
Pressing E will re-execute the program.

Access: Cmds 2(Drawing), 3(FREEZE)

WAIT(0): This freezes the screen for an indefinite amount of time. However, pressing any button will cause the program to continue. Of course, if the last END is followed by WAIT(0), the program terminates.

Of course, you can use WAIT(n) to make the calculator wait n seconds before executing the next step.


TEXTOUT and TEXTOUT_P inserts text on a graphics object using Cartesian and Pixel coordinates, respectively.
They are also at the bottom of the Cartesian and Pixel Drawing sub menus, respectively.
(Use either the d button or the up button followed by E).

Syntax (starred commands are optional):

TEXTOUT(text, GROB*, x, y, font size*, text color*, width*, background color*)

TEXTOUT_P(text, GROB*, x, y, font size*, text color*, width*, background color*)

Simplified Syntaxes:

Black text at default font size:
TEXTOUT(text, x, y)
TEXTOUT_P(text, x, y)

Colored text at a set font size:
TEXTOUT(text, x, y, size code, color)
TEXTOUT_P(text, x, y, size code, color)

With all this, we finally get to some programming. Since it is December, and snowing in a lot of the northern side of Earth, let's use TEXTOUT_P to draw snowflakes. I am going to use symbolize the snowflake by the asterisk, the symbol of multiplication in programming × types *.


Note: Take note the order of the commands. The order regarding where to draw and generate random numbers is important to get the results you want.

SNOWFLAKE takes one argument, which is the number of snowflakes to be drawn.


L0 := {RGB(0, 0, 255), RGB(178, 255, 255),
RGB(30, 144, 255), RGB(0, 255, 255)};
// blue, light blue, dodger blue, cyan

FOR I FROM 1 TO N DO X := RANDINT(0, 304); // save some room since text takes pixels
Y := RANDINT(0, 208);
Z := RANDINT(1, 4);
Z := L0(Z);
TEXTOUT_P("*", X, Y, 2, Z);


N = 50 Screen

N = 250 Screen

N = 500 Screen

Read Part 7 >