Thursday, May 10, 2018

HP Prime: Pentcolor Demonstration





HP Prime: Pentcolor Demonstration

Introduction

The HP Prime program PENTCOLOR allows the cycler to through colors with the touch of the following buttons:

Key [ 1 ]:  Red
Key [ 2 ]:  Green
Key [ 3 ]:  Blue

Each color setting cycles through the values of 0, 64, 128, 192, and 255.  Exit the program with the Escape key ( [ Esc ] ).  This program allows the user to cycle through different colors using RGB values.

 I use two subroutines in PENTCOLOR.  The first draws the text every time the key is selected, which allows for crisp text.   The second is for value calculation.  In subroutines on the HP Prime, all variables that are used must be local.  Global variables are passed through the subroutine arguments.  





HP Prime Program:  PENTCOLOR

SBR1(); // sub routine text
// allows for crisp text

SBR2(); // sub routine calc
// saves space in main program

// main program
EXPORT PENTCOLOR()
BEGIN
// EWS 2018-05-07

LOCAL K,R,G,B;
// R,G,B are set at 0
RECT();

TEXTOUT_P("Ready! 1. Red,
2. Green, 3. Blue",0,20,4);

REPEAT
K:=GETKEY;

// Key 1, red
IF K==42 THEN
RECT();
R:=SBR2(R);
SBR1(R,G,B);
END;

// Key 2, green
IF K==43 THEN
RECT();
G:=SBR2(G);
SBR1(R,G,B);
END;

// Key 3, blue
IF K==44 THEN
RECT();
B:=SBR2(B);
SBR1(R,G,B);
END;

UNTIL K==4; // ESC key

END;

// sub routines
// all subroutines have
// all local variables
SBR1(x,y,z)
BEGIN
TEXTOUT_P("[ 1 ]: Red: "+x,
0,20,4,#FF0000h);
TEXTOUT_P("[ 2 ]: Green: "+y,
0,40,4,#00FF00h);
TEXTOUT_P("[ 3 ]: Blue: "+z,
0,60,4,#0000FFh);
TEXTOUT_P("[Esc]: Exit",
0,120,4);
// draw box
FILLPOLY_P({(160,20),(310,20),
(310,170),(160,170)},RGB(x,y,z));
END;

SBR2(t)
BEGIN
t:=t+64;
IF t==256 THEN t:=255; END;
IF t==319 THEN t:=0; END;
RETURN t;
END;

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Spotlight: Sharp EL-5200

  Spotlight: Sharp EL-5200 As we come on the 13 th (April 16) anniversary of this blog, I want to thank you. Blogging about mathematic...