Date post: | 22-Feb-2018 |
Category: |
Documents |
Upload: | mario-aguirre |
View: | 320 times |
Download: | 10 times |
of 33
7/24/2019 HP Prime Programming Tutorial
1/33
HP Prime Programming Tutorial #1: LOCAL, RETURNOver the next month, maybe month and a half, I plan to post programming tutorials for the HP(Hewlett Packard) Prime
If you have programmed with the HP !"#, !$g, or !$gii, this language will be similar to those %he
programming language for the Prime is named the HP Prime Programming &anguage (HPPP)
%hroughout this tutorial, I am going to use the latest version of the software
How to start writing a program'
Press hift * (Program)+ Press ew It is the second touch key! -nter the name of the program Pressing the.&PH.key twice will turn on /PP-01.- 2&PH.3&O14 Pressing .&PH., hift, .&PH. will turn on lowercase alpha3lock %o exit any lock, press the
.&PH. key one more time 5hen happy with the name, press -nter
7/24/2019 HP Prime Programming Tutorial
2/33
7/24/2019 HP Prime Programming Tutorial
3/33
0ules for Program ames'
&etters, numbers, and the underscore character (6) only
+ %he program name must start with a letter
tructure of a HP Prime Program
. HPPP program is encased of an -7PO0% 3 8-#I 3 -9 structure %he layout is generally likethis'
EXPORTprogram_name(arguments)
BEGIN
commands and comments go here
END;
-ach line containing a command generally must end with a semicolon (:) . semicolon can by typeby pressing .&PH. then the Plus key ( * )
7/24/2019 HP Prime Programming Tutorial
4/33
1omments can be typed %he are designated by two forward slashes %he slashes are typed bypressing the 9ivide key ( ; ) .nything in the line following the two slashes is ignored in running theprogram
>s
7/24/2019 HP Prime Programming Tutorial
5/33
-xamples to try with
7/24/2019 HP Prime Programming Tutorial
6/33
5elcome to another programming tutorial for the HP Prime In this session, we will cover J#8O7,IE3%H-3-&-, P0I%, and the EO0 loop
J#8O7
MS"#!$' J#O7 takes a string a makes a pop3up message box Program execution stops untilyou press a key to acknowledge the message
.ccess' 1mds, IAO, " J#8O7
%he program 1OJ&O14' Imagine that you are in charge of setting the combinations for the good,old3school combination locks %his program gives three digit combinations through the use ofJ#8O7
EXPORT COMLOCK()
BEGIN
LOCAL L0;
L0:=RANDINT(3,0,39);**
MSGBOX("SECRET: "+L0(1)+","+L0(2)+","+L0(3));
END;LL %hanks to %homas &ake for pointing out my typo .pologies for any inconvenience 3 -ddie(!A+A+>F)
Other commands that are featured'
0.9I%(n, a, b) generates a list of n integers between a and b Cou can leave n out if you desire asingle random integer Picks may be repeated
%he HP PrimeMs default list variables are designated &> through &$
7/24/2019 HP Prime Programming Tutorial
7/33
Here is a sample output for 1OJ&O14'
IE3%H-3-&-
%&-THEN-ESE' Program structure'IF conditionTHEN
do if the condition is true;
ELSE
do if the condition is false;
END;
.ccess' %mplt, + 8ranch, + IE %H- -&-
%ip' Cou can leave out the -&- part if you only want to test to see if a condition is true .ccess thesimple IE3%H- structure by pressing %mplt, + 8ranch, IE %H-
.ccess N, , @@, etc by pressing hift, ote that the double e?uals is needed to check e?uality
7/24/2019 HP Prime Programming Tutorial
8/33
P0I%
PR%NT' %he P0I% command prints a sting, result, or a combination of both onto the PrimeMs
%erminal screen If P0I% is used, the program will end on the terminal (text output) screen Press abutton to exit
Cou can access the terminal screen at any time by pressing the O button, holding it, and thenpressing the 9ivide ( ; ) button
.ccess' 1mds, IAO, $ P0I%
%ip' %o clear the terminal screen, type P0I%() %his is a good way to clear the terminal screen andI usually use this at the beginning of any program if P0I% is going to be used later on
%he program
7/24/2019 HP Prime Programming Tutorial
9/33
D:=B^2-4*A*C;
IF D?0 THEN
PRINT("Roots are real.");
ELSE
PRINT("Roots are complex.");
END;
PRINT((-B+?D)/(2*A));PRINT((-B-?D)/(2*A));
END;
-xamples'
7/24/2019 HP Prime Programming Tutorial
10/33
Eor strings, 9IJ returns length as a numberEor matrices, 9IJ returns the list Qnumber of rows, number of columnsR
.ccess' 1mds, trings, $ 9IJ
%he program'
EXPORT SUMDIV(N)
BEGIN
LOCAL S:=0,K,mdiv,ldiv;
mdiv:=CAS.idivis(N);
ldiv:=DIM(mdiv);
FOR K FROM 1 TO ldiv(1) DO
S:=S+mdiv(K);
END;
RETURN S;
END;
LL %hanks to %homas &ake for pointing out that the variable =mat=, which I had in this program was
unnecessary 3 -ddie !A+A+>!
-xamples'/J9IK(+) returns +"/J9IK(+F) returns >/J9IK("G) returns >"
HP Prime Programming Tutorial #%: &H"LE, "NPUT, '"LL, REPEAT,
GET'E(
%his tutorial is going to cover a lot, each with some new programming commands in this series Ihope you are ready for the intensity ')
5HI&-, IP/%, 4I&&
HP Prime Program' %.0#-% %.0#-% is a game where you provide a guess to get a desirednumber If you miss, the calculator will tell you if number is higher and lower .t the end of thegame, the calculator gives you how may picks you needed to get the target number
*H%E' 0epeat a number of commands while a specific condition is test
WHILE condition is true DO
commandsEND;
.ccess' %mplt, ! &oop, G 5HI&-
1aution' 5atch your -9sS Jake sure an -9 is with each loop and the program itself Press thesoft key 1heck to check your work
%NPUT' 1reates an input screen for variables On the HP Prime, the input can asked for more than
7/24/2019 HP Prime Programming Tutorial
11/33
one input %.0#-% demonstrates IP/% with one prompt
One Kariable'INPUT(variable, "title", "label", "help text")
Julti3Kariable'INPUT(list of variables, "title", list of "labels", list of "help text")
ote' Pressing 1ancel will store a > in variable Cou may include code of what to do if the userpresses 1ancel, but it is not re?uired
.ccess' 1mds, IAO, G IP/%
+%' %erminates program execution othing dies, I promise
.ccess' %mplt 8lock, ! 4I&&
Program'EXPORT TARGET()
BEGIN
LOCAL C:=0, N:=RANDINT(1,20), G:=-1;
WHILE G?N DO
C:=C+1;
INPUT(G,"Guess?","GUESS:","1 - 20");
IF G==0 THEN
KILL;
END;
IF G < N THEN
MSGBOX("Higher");
END;
IF G > N THEN
MSGBOX("Lower");
END;
END;
MSGBOX("Correct! Score: "+C);
END;
%ry it and of course, you can adDust the higher limit Here is some thing for you to try with %.0#-%'
.dd a limited amount of guesses+ 1an you display the list of guessesT
0-P-.%
/&.J .lgorithm' take an integer n If n is even, divide it by + If n is odd, multiply it by ! and add /&.J counts how many steps it takes to get n to
REPEAT'
7/24/2019 HP Prime Programming Tutorial
12/33
.ccess' %mplt, ! &oop, 0-P-.%
Eeatured'C!NCATli(t, li(t./' Jelds list and list+ into one
.ccess' %oolbox, Jath, &ist, F 1oncatenate
EXPORT ULAM(N)
BEGIN
LOCAL C:=1, L0:={N};
REPEAT
IF FP(N/2)==0 THEN
N:=N/2;
ELSE
N:=3*N+1;
END;
C:=C+1;
L0:=CONCAT(L0,{N});
UNTIL N==1;
MSGBOX("NO. OF STEPS="+C);
RETURN L0;
END;
-xamples'
/&.J(G) returns'
Jessage 8ox' =O OE %-P@=&ist' QG, , ", F, +, R
/&.J(++) returns'Jessage 8ox' =O OE %-P@=&ist' Q++, , !F, , G+, +, !, F>, +>, >, G, , ", F, +, R
#-%4-C
%he next section will introduce a super3important command, #-%4-C 5e will be working with#-%4-C over the entire series
%he Program 4-CO' %he person presses key presses 5hich each key press, the code returns tothe terminal screen %he program terminates when the -nter key is pressed
"ET+E0' 0eturns the key code of last key pressed %he PrimeMs key map is below (Picture is fromthe HP Prime /serMs #uide)
.ccess' 1mds, IAO, F #-%4-C
7/24/2019 HP Prime Programming Tutorial
13/33
EXPORT KEYNO()
BEGIN
LOCAL K;
PRINT();
PRINT("Press any key to get its code.");
PRINT("Press Enter to exit.");
REPEAT
K:=GETKEY;
IF K ? 0 THEN
PRINT(K);
END;
UNTIL K==30;
END;
7/24/2019 HP Prime Programming Tutorial
14/33
-xample 4ey 1odes'!!' " key+' up' left"' right+' downG>' plusFG' minus
HP Prime Programming Tutorial #): CHOOSE an* CASE, Ti+ aout
"NPUT
5elcome to Part F of our programming series for the Prime %odayMs session will cover 1HOO-and 1.-
Eirst a tip from Han of the JoHP1 Eorum, which is found at http'AAwwwhpmuseumorgAcgi3
sysAcgiwrapAhpmuseumAforumcgiU+GG>"F%hank you Han for allowing me to share this
/se the IE %H- -&- structure with IP/% to execute a set of default instructions if the userpresses cancel IP/% returns a value of > if -1 or cancel is pressed, and if a value is entered
IF INPUT(...) THEN
commands if values are entered
ELSE
commands if Cancel is pressed
END;
9efault values can be assigned to values as an optional fifth argument for IP/%
INPUT(var, "Title", "Prompt", "Help", default value)
%he type of variable maybe set to other than real numbers Vust remember to store such type beforethe IP/% command Eor example, if you want var to be a string, store an empty string'
var:=" ";
.gain, maDor thanks to Han
1HOO- and 1.-
CH!!SE' 1reates a pop up choose box, similar to what you see when you click on a soft menu%here are two syntaxes for 1HOO-'
imple yntax (up to F options)'1HOO-(var, =title string=, =item =, =item +=, , =item n=):
&ist syntax (infinite amount of items)'1HOO-(var, =title string=, Q=item =, =item +=R):
1hoosing item assigns the value of to var, choosing item + assigns the value of + to var
.ccess' 1mds, IAO, 1HOO-
http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi#255084http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi#255084http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi#255084http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi#255084http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi#2550847/24/2019 HP Prime Programming Tutorial
15/33
1.-' .llows for different test cases for one variable .lso includes a default scenario (optional)
CASE
IF test 1 THEN do if true END;
IF test 2 THEN do if true END;
...DEFAULT commands END;
.ccess' 1mds, + 8ranch, ! 1.-
&etMs look at two programs to demonstrate both 1HOO- and 1.-
%-0JK-& 3 %erminal Kelocity of an ObDect
EXPORT TERMVEL()
BEGIN
LOCAL L0:={9.80665,32.174},
L1:={1.225,.0765},L2:={.47,1.05,1.15,.04},C,K,M,A,T;
CHOOSE(C,"Units","SI","English");
CHOOSE(K,"Type of Object","Sphere","Cube",
"Cylinder","Tear-Shaped");
INPUT({M,A},"Object",
{"M=","A="},{"Mass","Surface Area"});
T:=?((2*M*L0(C))/(L1(C)*A*L2(K)));
MSGBOX("Terminal Velocity="+T);RETURN T;
END;
-xamples'
phere, I /nits, J @ >G kg, . @ >>+" mB+%erminal Kelocity' % @ +FF>FG!" mAs
1ube, / /nits, J @ + lb, . @ !F>! ftB+%erminal Kelocity' % @ G!F$"++>$ ftAs
.0-.1 3 .rea of 1ircles, 0ings, and ectors
EXPORT AREAC()
BEGIN
LOCAL C,R,S, ,A;
CHOOSE(C,"Areas","1. Circle","2. Ring","3. Sector");
INPUT(R, "Input Radius", "R =");
7/24/2019 HP Prime Programming Tutorial
16/33
CASE
IF C==1 THEN A:=?*R^2; END;
IF C==2 THEN
INPUT(S,"Small Radius","r=");
A:=?*(R^2-S^2);
END;
IF C==3
INPUT( , "Angle", " =");
\\ Assume you are in the correct angle mode
IF HAngle==1 THEN
\\ Test Angle Mode
:= *?/180;
END;
A:= *R^2/2;
END;
END;
MSGBOX("Area is "+A);
RETURN A;
END;
-xamples
0 @ +G, r @ G, W @ XAF radians or FGY
1ircle' $!F$GF>"F$0ing' +G!>FFector' +FGF!$+>+
HP Prime Programming Tutorial #-: STARTAPP, START."E&, RG
%odayMs session is about starting other apps in a program and using colors
)e1ining e23ation( in t4e Program Editor and Home
%he e?uation must be a string and be stored to the appropriate designated variable
EU is for functions of 7 (Eunction app)
0U is for polar functions of W (Polar app)
/U is for se?uences of , 3, 3+ (e?uence app)
7U and CU for parametric e?uations of % (Parametric .pp)
KU for open statements and e?uations in the .dvanced #raphing .pp, which %he independent
variables are 7 and C
7/24/2019 HP Prime Programming Tutorial
17/33
U is a digit >3$
9efining e?uations this way leaves them uncheck If you want them plotted or accessed in um
Kiew, you will need to check them
-xample'E'@=+L7B!= stores the function f(x) @ +LxB! in Eunction
0G'@=.LI(W)= stores the polar function r(W) @ .Lsin(W) in Polar Eunction G, with . being what value
stored in it
STARTAPP
%.0%.PP(application name in quotes):
tarts the named .pp %he calculator points the screen to the default view (Plot, ymb, um)
.ccess' 1mds, F .pp Eunctions, + %.0%.PP
CHEC+and UNCHEC+
1hecks and unchecks specific e?uation or function (>3$) in the current app Eor example, if you are
in the Eunction app, 1H-14() activates E .s you should expect, /1H-14() turns E off
5hat does 1H-14 and /1H-14 affectT
5hether a function is plotted in Plot view
+ 5hether a function is analyZed in um view
.ccess for 1H-14' 1mds, F .pp Eunctions, 1H-14
.ccess for /1H-14' 1mds, F .pp Eunctions, F /1H-14
START5%E*
Instructs the HP Prime to go to a certain view It has two arguments, the view number and a redraw
number
1ommon view numbers include (not all inclusive)'
3+ @ Jodes screen
3 @ Home
> @ ymbolic (ymb)
@ Plot
+ @ umeric (um)
! @ ymbolic etup
F @ Plot etup
7/24/2019 HP Prime Programming Tutorial
18/33
G @ umeric etup
@ .pp Information
@ %he Kiews 4ey
" @ first special view
$ @ second special view
-tc
%he redraw number is either > or non3Zero > does not redraw the screen, anything else does I
recommend the latter
yntax' %.0%KI-5(view number, redraw number)
.ccess' 1mds, F .pp Eunctions, ! %.0%KI-5
R"#
0eturns an integer code pertaining to a colorMs 0#8 code %his is super useful for drawing and text
writing
yntax' 0#8(red, green, blue, alpha)
0ed' Intensity of 0ed, >3+GG
#reen' Intensity of #reen, >3+GG
8lue' Intensity of 8lue, >3+GG
.lpha' (optional) Opacity (up to +")
0#8 codes'
8lue' 0#8(>,>,+GG)
Kiolet' 0#8(F!,+GG,>)
9ark #reen' 0#8(>,+",>)
Orange' 0#8(+GG,+,>)
Cellow' 0#8(>,+GG,+GG)
0ed' 0#8(+GG,>,>)
5hite' 0#8(+GG,+GG,+GG)
8lack' 0#8(>,>,>)
#ray' 0#8(+$,+",+")
8rown' 0#8(G>,G,>)
&ight 8lue' 0#8(!,+,!!>)
Eor other colors, 0#8 can be found on various sites on the Internet, including 5ikipedia
.ccess' 1mds, + 9rawing, G 0#8
%ip' 1hange a color of a graph
7/24/2019 HP Prime Programming Tutorial
19/33
/se the syntax
EU(1O&O0)'@0#8(red,blue,green,[alpha\):
E stands for the designated function type (E for function, 0 for polar, etc)
U is the digit >3$
-xample'
E"(1O&O0)'@0#8(>,>,+GG)
makes the function E" plot in blue
%his is a lot, but this is doable &etMs see all these commands and tips in action and create somemagic
1onic 9rawing for HP Prime
9raws the conic section for the general e?uation
.xB+ * 8yB+ * 1xy * 9x * -y * E @ >
Cou can choose the color how the conic section is plotted, from red, blue, orange, and green
(#ame show enthusiasts take note of the order of the colors I listed :) )
EXPORT CONIC()
BEGIN
LOCAL cr, cg, cb, I;INPUT({A,B,C,D,E,F},
"Ax^2+By^2+Cxy+Dx+Ey+F", { }, { },
{0,0,0,0,0,0});
// Colors
CHOOSE(I, "Choose a Color",
"Red","Blue","Orange","Green");
cr:={255,0,255,0};
cg:={0,0,127,255};
cb:={0,255,0,0};
STARTAPP("Advanced Graphing");
V1:="A*X^2+B*Y^2+C*X*Y+D*X+E*Y+F=0";
V1(COLOR):=RGB(cr(I),cg(I),cb(I));
CHECK(1);
// Plot View
STARTVIEW(1,1);
END;
7/24/2019 HP Prime Programming Tutorial
20/33
8elow are some examples 0emember the form'
.xB+ * 8yB+ * 1xy * 9x * -y * E @ >
7/24/2019 HP Prime Programming Tutorial
21/33
7/24/2019 HP Prime Programming Tutorial
22/33
ProDectile Jotion for HP Prime
%his program calculates range and height of a proDectile, and plots its path %he program sets the
mode into 9egrees (H.ngle@) and the calculator to the Parametric app
-?uations'
x @ K L cos W L t
y @ K L sin W L t 3 G L g L tB+
5here
K @ initial velocity
W @ initial degree of flight
g @ -arth gravitation constant ($">G mAsB+, ]!+F>F ftAsB+)
.ir resistance is not factored, so we are dealing with idealconditions How much the proDectile
represents reality varies, where factors include the obDect being proDected, the temperate and
pressure of the air, and the weather
EXPORT PROJ13()
BEGIN
LOCAL M, str;
// V, G, are global
// Degrees
7/24/2019 HP Prime Programming Tutorial
23/33
HAngle:=1;
CHOOSE(M, "Units", "SI", "US");
IF M==1 THEN
str:="m";
G:=9.80665;
ELSE
str:="ft";
G:=32.17404;
END;
INPUT({V, }, "Data",
{"V:"," :"},
{"Initial Velocity in "+str+"/s",
"Initial Angle in Degrees"});
X1:="V*COS( )*T";
Y1:="V*SIN( )*T-.5*G*T^2";
STARTAPP("Parametric");
CHECK(1);
// Adjust Window
Xmin:=0
// Range
Xmax:=V^2/G*SIN(2* );
Ymin:=0
// Height
Ymax:=(V^2*SIN( )^2)/(2*G);
MSGBOX("Range: "+Xmax+" "+str+", "
+", Height: "+Ymax+" "+str);
// Plot View
STARTVIEW(1,1);
END;
8elow are screen shots from an example with K @ !G+G mAs and W @ F"Y
7/24/2019 HP Prime Programming Tutorial
24/33
HP Prime Programming Tutorial #/: Suroutine0S3bro3tine(
7/24/2019 HP Prime Programming Tutorial
25/33
%his session will show how routines work in HPP& #enerally, subroutines have bedeclared beforethe main program 9eclaration is important %he details of the subroutinesare afterthe main program
9efinitely take a look at the example programs to get a better understanding
/8 0outines for HP Prime
#eneral yntax'
sub(); //declare subroutines
EXPORT main()
BEGIN
commands go here, including sub()
END;
sub()
BEGIN
commands go here
END;
/8-7.J
%his is Dust a demonstration of how sub routines work %his program calculates one of two values'
If . is positive, then the program evaluates . If not, the program values 8 instead 5here'
. @ +(x3y)A^ * xy8 @ ^B+
and ^ @ +eB(x*y) 3 eB(x3y) 3 eB(y3x)
5e will use ^ as the subroutine
SUB1();
EXPORT SUBEXAM(X,Y)
BEGIN
LOCAL A, B;
A:=(2*(Y-X))/SUB1(X,Y)+X*Y;
B:=(SUB1(X,Y))^2;
IF A>B THEN
RETURN A;
ELSE
RETURN B;
END;
END;
SUB1(X,Y)
BEGIN
RETURN 2*e^(X+Y)-e^(X-Y)-e^(Y-X);
END;
7/24/2019 HP Prime Programming Tutorial
26/33
-xamples'
/8-7.J(3F, ) returns +$$"$""$/8-7.J(+,!) returns "+"!+$$F/8-7.J(3G,3) returns !>F">+""/8-7.J(+,3!) returns +">>FF
9ays 8etween 9ates
99.C /sing ubroutines for HP Prime' 8est for $> to +>$$
L 0emember century years not divisible by F>> are O% leap years %his program does not takethis into account If any such years are passed, subtract one day for such year manually
ource' HP +1 Janual 3 Hewlett Packard
// Declare Subroutines
SUB1();
SUB2();
SUB3();
// Main program
EXPORT DDAYS(m1,d1,y1,m2,d2,y2)
BEGIN
// DYS HP 12C
LOCAL x1, x2, z1, z2;
x1:=SUB1(m1); x2:=SUB1(m2);
z1:=SUB2(m1,y1); z2:=SUB2(m2,y2);
RETURN SUB3(y2,m2,d2,z2,x2)-
SUB3(y1,m1,d1,z1,x1);
END;
SUB1(X)BEGIN
IF X?2 THEN
RETURN 0;
ELSE
RETURN IP(.4*X+2.3);
END;
END;
SUB2(X,Y)
BEGIN
IF X?2 THEN
RETURN Y-1;
ELSERETURN Y;
END;
END;
SUB3(Y,M,D,Z,X)
BEGIN
RETURN 365*Y+31*(M-1)+D+IP(Z/4)-X;
END;
7/24/2019 HP Prime Programming Tutorial
27/33
(%hanks to Owitte for pointing out my typo)
-xamples'9ays 8etween 9ates'
A!A$"G to +A+"A$$G is !,G+ days
!AFA$ to AA+>! is !,!$ days
+A>A+>> to A!>A+>F is ,+$" days
AGA+>G to !A$A+++ returns ,G> 8/% this program treats +>> and ++>> as leap years, whichin reality they are not ubtract + to get the correct answer of ,G>F days
HP Prime Programming Tutorial #: TE!TOUT#reetings everyone It has been too long since I last posted I hope everyone had a fantastic%hanksgiving Eor those of you who are battling cold and stormy weather, please be safe Eor those
of you living in the outhern Hemisphere where summer is about to begin IMm DealousS ') I lovesummer
%ntrod3ction
O4 this section we will start covering some of the graphics features of the HP Prime Programming&anguage 5e touched on graphics a bit when we used %.0%.PP and %.0%KI-5 to call up thePlot screen of certain apps (Eunction, Parametric, Polar, .dvanced #rpahing)
%his time we are going to use drawing commands that can be used in any HP Prime app In asense we are creating a graphic obDect (#0O8) %he HP Prime allows for ten graphic obDects,named #> 3 #$ Eor this tutorial series, (unless specified) I am always going to use the default#0O8, #> %his makes typing commands much easier
1artesian vs Pixel
-ach graphic obDect operates in either one of two coordinate systems' 1artesian and pixel If youworked with the Hewlett Packard HP !$gii calculator, this might look familiar to you
%he features of the 1artesian system (x,y) are these'
L %he end points depend on the Plot variables 7min, 7max, Cmin, and CmaxL %he system is familiar, having x increasing as we move to the right and y increasing as we moveup (no shocker there)L %he trade is that some (very few) drawing commands donMt accommodate the 1artesian system
.n example is the .01 command, which re?uires the radius to be in pixels
8elow is a map of the 1artesian system'
7/24/2019 HP Prime Programming Tutorial
28/33
%he Pixel ystem (x,y)'
L %he boundaries are 1ixed %he pixel (>,>) is the top left hand corner, the pixel (!", +") is thelower right hand cornerL %he value of x still increases as we go to the right However, y increases as we go down, oppositeof the 1artesian system On the other hand, x and y are always non3negative
7/24/2019 HP Prime Programming Tutorial
29/33
%he 9rawing 1ommands
%he HP Prime has two sets of drawing commands' one for the 1artesian system and one for thePixel system .ll commands for the Pixel system will have a =6P= suffix attached Eor example'
&I- draws a line using 1artesian coordinates, while &I-6P draws a line using Pixel coordinates
#eneral .ccess' (in the Programming -ditor)
9rawing 1ommands for the Pixel system' 1mds, + 9rawing, Pixels9rawing 1ommands for the 1artesian system' 1mds, + 9rawing, 1art_sian
1learing the #0O8 screen
%o clear the #0O8 screen, we will simply type RECT() %he wipes the screen, leaving it white It is
necessary to do this at least at the beginning of each program containing drawing commands In asense, RECT()is similar to PRINT()
Hint' %o paint an entire screen a specific color, use RECT(color)
howing the #raphics creen
It is not enough to type the drawing commands 5e need a command to tell the HP Prime to showthe graphics %wo ways to do it are'
&REE6E' %his does exactly what it says, freeZes the screen %o exit, tap the screen or press -1
7/24/2019 HP Prime Programming Tutorial
30/33
7/24/2019 HP Prime Programming Tutorial
31/33
TEXTOUT(text, x, y)
TEXTOUT_P(text, x, y)
1olored text at a set font siZe'TEXTOUT(text, x, y, size code, color)
TEXTOUT_P(text, x, y, size code, color)
5ith all this, we finally get to some programming ince it is 9ecember, and snowing in a lot of thenorthern side of -arth, letMs use %-7%O/%6P to draw snowflakes I am going to use symboliZe thesnowflake by the asterisk, the symbol of multiplication in programming [ ` \ types L
O5E&.4-
O5E&.4- takes one argument, which is the number of snowflakes to be drawn
ote' %ake note the order of the commands %he order regarding where to draw and generaterandom numbers is important to get the results you want
Program'
EXPORT SNOWFLAKE(N)
BEGIN
LOCAL X,Y,Z,I,L0;
L0:={RGB(0,0,255),RGB(178,255,255),
RGB(30,144,255),RGB(0,255,255)};
\\ blue, light blue, dodger blue, cyan
RECT();
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);
END;
FREEZE;
END;
7/24/2019 HP Prime Programming Tutorial
32/33
7/24/2019 HP Prime Programming Tutorial
33/33