Welcome to Part 8 of the HP Prime Tutorial. Continuing in our drawing commands, we are going to feature ARC and LINE.

Syntax:

Cartesian:

ARC(x, y, r, angle 1*, angle 2*, color*).

Pixels:

ARC_P(x, y, r, angle 1*, angle 2*, color*)

x: x coordinate

y: y coordinate

r: length of the radius in pixels. This is why I prefer using pixel commands in my programming.

angle 1 and angle 2: If included, these two arguments draw an arc segment. The angle follows the conventional circle notation, starting with 0 (due east) going counter clockwise. Use the current angle mode.

color: color of the arc. To use it, angle 1 and angle 2 must be included.

Draws a line segment from (x1, y1) to (x2, y2). The color is optional.

Syntax:

Cartesian:

LINE(x1, y1, x2, y2, color*)

Pixels:

LINE_P(x1, y1, x2, y2, color*)

The next to programs CIRCLE1 and CIRCLE2 do the same thing: draw a circle, label quadrants and angels. The reason why I am posting these two is that when you are programming graphics, care must be given. Adjustments to where graphics are placed can be necessary and I hope CIRCLE1 and CIRCLE2 illustrates this.

Medium font is assumed (set in Home Settings).

The angle symbol (°) get be retrieved by pressing Shift + 9 and selecting ° from the grid.

CIRCLE1 (the "rough draft", if you will):

EXPORT CIRCLE1()

BEGIN

RECT();

TEXTOUT_P("Circle", 0, 0);

TEXTOUT_P("II",109,59);

TEXTOUT_P("90°",159,59);

TEXTOUT_P("I",209,59);

TEXTOUT_P("180°",109,109);

TEXTOUT_P("0°",209,109);

TEXTOUT_P("III",109,159);

TEXTOUT_P("270°",159,159);

TEXTOUT_P("IV",209,159);

LINE_P(0,109,318,109,RGB(16,16,16));

LINE_P(159,0,159,239,RGB(16,16,16));

ARC_P(159,109,30);

FREEZE;

END;

The results:

**ARC and ARC_P**: Draws a Circle or a Circular ArcSyntax:

Cartesian:

ARC(x, y, r, angle 1*, angle 2*, color*).

Pixels:

ARC_P(x, y, r, angle 1*, angle 2*, color*)

x: x coordinate

y: y coordinate

r: length of the radius in pixels. This is why I prefer using pixel commands in my programming.

angle 1 and angle 2: If included, these two arguments draw an arc segment. The angle follows the conventional circle notation, starting with 0 (due east) going counter clockwise. Use the current angle mode.

color: color of the arc. To use it, angle 1 and angle 2 must be included.

**LINE and LINE_P**Draws a line segment from (x1, y1) to (x2, y2). The color is optional.

Syntax:

Cartesian:

LINE(x1, y1, x2, y2, color*)

Pixels:

LINE_P(x1, y1, x2, y2, color*)

The next to programs CIRCLE1 and CIRCLE2 do the same thing: draw a circle, label quadrants and angels. The reason why I am posting these two is that when you are programming graphics, care must be given. Adjustments to where graphics are placed can be necessary and I hope CIRCLE1 and CIRCLE2 illustrates this.

Medium font is assumed (set in Home Settings).

The angle symbol (°) get be retrieved by pressing Shift + 9 and selecting ° from the grid.

CIRCLE1 (the "rough draft", if you will):

EXPORT CIRCLE1()

BEGIN

RECT();

TEXTOUT_P("Circle", 0, 0);

TEXTOUT_P("II",109,59);

TEXTOUT_P("90°",159,59);

TEXTOUT_P("I",209,59);

TEXTOUT_P("180°",109,109);

TEXTOUT_P("0°",209,109);

TEXTOUT_P("III",109,159);

TEXTOUT_P("270°",159,159);

TEXTOUT_P("IV",209,159);

LINE_P(0,109,318,109,RGB(16,16,16));

LINE_P(159,0,159,239,RGB(16,16,16));

ARC_P(159,109,30);

FREEZE;

END;

The results:

This is good, but we can do better. First I am going to move the labels II, 180°, and III 10 pixels to the left, primarily so the 180° label does not touch the circle.

Second I am going to move the labels III, 270°, and IV up 10 pixels to make the bottom line look better and not "so far away" from the circle.

Although it is not necessarily, I am going to make the angle labels blue. I will need to specify the font size code at 0.

Finally, I find that the lines are too dark. I am going to make them a bit more gray.

Here is the second revision. For the purposes of this tutorial, I call this program CIRCLE2. All changes are in bold.

EXPORT CIRCLE1()

BEGIN

RECT();

TEXTOUT_P("Circle", 0, 0);

TEXTOUT_P("II",

TEXTOUT_P("90°",159,59,

TEXTOUT_P("I",209,59);

TEXTOUT_P("180°",

TEXTOUT_P("0°",209,109,

TEXTOUT_P("III",

TEXTOUT_P("270°",159,

TEXTOUT_P("IV",209,

LINE_P(0,109,318,109,

LINE_P(159,0,159,239,

ARC_P(159,109,30);

FREEZE;

END;

Second I am going to move the labels III, 270°, and IV up 10 pixels to make the bottom line look better and not "so far away" from the circle.

Although it is not necessarily, I am going to make the angle labels blue. I will need to specify the font size code at 0.

Finally, I find that the lines are too dark. I am going to make them a bit more gray.

Here is the second revision. For the purposes of this tutorial, I call this program CIRCLE2. All changes are in bold.

EXPORT CIRCLE1()

BEGIN

RECT();

TEXTOUT_P("Circle", 0, 0);

TEXTOUT_P("II",

**99**,59);TEXTOUT_P("90°",159,59,

**0,RGB(0,0,255)**);TEXTOUT_P("I",209,59);

TEXTOUT_P("180°",

**99**,109,**0,RGB(0,0,255)**);TEXTOUT_P("0°",209,109,

**0,RGB(0,0,255)**);TEXTOUT_P("III",

**99**,**149**);TEXTOUT_P("270°",159,

**149,0,RGB(0,0,255)**);TEXTOUT_P("IV",209,

**149**);LINE_P(0,109,318,109,

**RGB(128,128,128)**);LINE_P(159,0,159,239,

**RGB(128,128,128)**);ARC_P(159,109,30);

FREEZE;

END;

A better looking picture.

As always, thanks for your time, comments, and questions. Hopefully this session is helpful.

This blog is property of Edward Shore. 2013

Eddie

As always, thanks for your time, comments, and questions. Hopefully this session is helpful.

This blog is property of Edward Shore. 2013

Eddie

** Note: Thanks to Dennis for pointing out my typo. It is corrected now. 3/5/2014

Hi!

ReplyDeleteProbably the last LINE command was

LINE_P(159,0,159,239,RGB(128,128,128));

and not

LINE_P(159,0,159,0,RGB(128,128,128));

as written...

'cause LINE_P(159,0,159,0,RGB(128,128,128)); won't draw the middle vertical line.

Is it possible?

I am more than a year late, I know... :-)

Keep on the nice work here!

Dennis.

Thanks Dennis. I will correct the post right now. And no, it is not too late. :).

DeleteEddie

Hi!

ReplyDeleteI just received my Own HP Prime today. Very nice. I love it.

I would suggest you one day, if you're missing inspiration one day :-), to check, comment and blog something about the best or quickest way to convert back and forth from decimal to hexadecimal the values.

I love these calculators like the TI-nSPIRE, the big Casio or this HP Prime with so much functions, so much programmabilities, etc... but when it's time to simply convert a number from decimal to hex and vice versa, how much it's not as simple as stupid 2.99$ calculator that you simply press 2ND HEX or 2ND DEC and see the result... With the HP PRIME for example, let's suppose you just type "(1022*128*1024) and you see the result 133955584. For you, according to you, what is the shortest way in terms of number of "click" to convert this number to 0x7FE0000. (or to #7FE0000h like this HP seems to like).

Even by programming a program to replace a key (like you can do on this) it's not very efficiently done). OR maybe there is an obvious way I don't see....

Dennis.

Dennis,

DeleteI agree it is not simple. The way to easily covert numbers from decimal to hexadecimal is not obvious on the HP Prime. However, there are two conversion commands to be aware of:

B->R: Base to Real. This converts integers in base notation (they start with a hashtag symbol #) to a real number notation. Real numbers are always represented in decimal.

R->B: Real to Base. This converts numbers in real number format (decimal) to a integer. This effectively can be used as "convert decimal numbers to hexadecimals". The base R->B uses is determined by the Integers setting on the Home Settings screen.

You can change the Integers setting by pressing Shift, Home (the house key) or changing the value of system variable Base (please note the capitalization, very important). Base is found by pressing Vars, Settings, Integer, Base.

The value of Base determines the Integer Mode:

0: Binary

1: Octal

2: Decimal

3: Hexadecimal

R->B and B->R can be found in the catalog or can be typed out. The right arrow can be found by pressing Shift, 9, and selecting the arrow (1st row, 2nd column). If you are in the programming mode, these commands can be found in the Cmds, Integer menu.

Hope this helps,

Eddie

I find the R->B command actually accepts integer numbers as the Real argument. For example R->B(#16o,32,4) returns #E:32h. SETBASE is more concise. SETBASE (#16o,4) returns #Eh. I have my user key for "-, Base, :" set to return "SETBASE(#d,0)" which can be modified as needed for different conversions. Short programs such as H2D and D2B, etc. could be written for any conversion you often need.

DeleteDennis Right. Simple is powerful.

Your the best, Eddie. JFS.

Better yet: SETBASE(#20d,{1,2,3,4}) returns {#10100b,#24o,#20d,#14h}. Complex is powerful too. JFS.

DeleteHi. Great site.

ReplyDeleteHow do you SETBASE in RPN mode? It seems to only work in ALGEBRAIC.

Thanks,

Edward

1. Type the mode number and press Enter: 0 for Binary, 1 for Octal,

Delete2 for Decimal, and 3 for Hexadecimal. Press [Enter].

2. Press [Shift] [ ( ) ] to get the single quotes.

3. Press [Vars], 6 for Settings, 7 for Integer, 1 for Base. The word Base is entered in the quotes. Press [Enter].

4. Press [Shift] [ EEX ] for (Sto>). The mode number is not consumed, but the settings have changed.

I have tested this procedure on Software Version 8151 (the latest build).

Eddie

This comment has been removed by the author.

ReplyDeleteI think this is one of the most significant information for me.And i’m glad reading your article.But should remark on some general things, the web site style is perfect,the articles is really great : D. Good job…

ReplyDeleteIWIN89