Post Reply 
Programming questions
04-06-2016, 03:43 PM (This post was last modified: 04-06-2016 03:45 PM by periappi.)
Post: #1
Programming questions
Hi,

I've got some weird issues with my program, so here are some of them :

1) I cannot set the space width right :

HP Prime Emulator (the same on the calculator) :
[Image: 227964bug.png]

The code see by the program editor in the emulator :
[Image: 412776Capture.png]

HP Connection Kit (no problem here) :
[Image: 41873422ok.png]

2) Is there a way so I can put a big text into a PRINT() without it crashs ?

Thanks !
Find all posts by this user
Quote this message in a reply
04-06-2016, 10:35 PM
Post: #2
RE: Programming questions
If you would like to create your own screens, you might find textout_p() useful. It will require manipulating graphic screens, most likely, but well worth the effort.

-Dale-
Find all posts by this user
Quote this message in a reply
04-07-2016, 08:03 AM
Post: #3
RE: Programming questions
The Kit and program editor using a monospaced font, PRINT and TEXTOUT adjust the text according to the character, there is no way to modify this feature.

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
04-07-2016, 11:29 AM
Post: #4
RE: Programming questions
The PRINT() uses the terminal, and does not use pixel-based character positioning. TEXTOUT commands do.

Additionally, with TEXTOUT, more font sizes, text color, and background color are available. You can put characters anywhere you want them. Using PIXON, and PIXOFF you could even construct your own characters, (which I found useful to display 'rotated' text around the perimeter of the outer resistance circle for a Smith Chart application). These pixel based commands do require familiarity with graphic variable usage, such as RECT_P(), and BLIT_P().

Designing an output display can be more versatile when using the graphic feature set. It just comes with more overhead than the simple PRINT() command.

Here's a small program that uses both methods, perhaps useful for ideas:

Code:

//  RegPolygon()
//  4/7/2016  DrD
//
//  Regular polygon, (equal sides, and equal angles)
//
//  Finds:
//         1. Side length                                                     (a);  a:=2*r*TAN(180/n), a:=2*R*SIN(180/n), a:=SQRT((4*A*TAN(180/n))n)
//         2. Inradius (apothem: Distance from center to midpoint of a side)  (r);  r:=1/2*a*COT(180/n), r:=R*COS(180/n), r:=SQR(A*n*TAN(180/n))        
//         3. Circumradius (Distance from center to a vertex)                 (R);  R:=1/2*a*CSC(180/n), R:=r*SEC(180/n), R:=SQRT(2*A/(n*SIN(360/n)))  
//         4. Area                                                            (A);  A:=1/4*n*a^2*COT(180/n), A:=n*r^2*TAN(180/n), A:=1/2*n*R^2*SIN(180/n)
//         5. Perimeter                                                       (p);  p:=n*a, p:=2*n*R*sin(180/n)     
//
//  Provide the number of sides (n),  select one of the unknowns (a,r,R,A), and it's dimension.  

EXPORT RegPolygon()
BEGIN

  LOCAL a,r,p,R,A;
  LOCAL n,k,Sidelength,Apothem,Circumradius,Area,Perimeter;  // n=number of sides, k=known parameter, cb(x)=checkboxes for (a,r,R,A,p)
  LOCAL white:=rgb(255,255,255),
        black:=rgb(0,0,0),
        red:=rgb(255,0,0),        
        green:=rgb(0,255,0),
        blue:=rgb(0,0,255);        

  HAngle:=1;

    input ({ {n, [0], {60,20,0}}, 
             {k, [0], {60,20,1}},             
             
             {Perimeter, 4, {45,21,3}}, 
             {Apothem, 4, {75,21,3}},
             {Circumradius, 4, {45,21,4}},
             {Area, 4, {75,21,4}},
             {Sidelength, 4, {45,21,5}} },

             "Regular Polygon Parameters", 
             {"Number of sides ", "(Check box) Dimension"}, 
             {"How many sides?", "(Checked box) Value?"},           
             {6,5}, 
             {6,5} ); 

  IF Perimeter THEN
    a:=k/n;r:=1/2*a*COT(180/n);R:=1/2*a*CSC(180/n);A:=1/4*n*a^2*COT(180/n);
  END; 

 IF Sidelength THEN
    a:=k;r:=1/2*a*COT(180/n);R:=1/2*a*CSC(180/n);A:=1/4*n*a^2*COT(180/n);
  END; // Sidelength given

  IF Apothem THEN
    r:=k;a:=2*r*TAN(180/n);R:=r*SEC(180/n);A:=n*r^2*TAN(180/n);
  END; // Inradius (Distance from center to Apothem (midpoint of side))given

  IF Circumradius THEN
    R:=k;a:=2*R*SIN(180/n);r:=R*COS(180/n);A:=1/2*n*R^2*SIN(360/n);
  END;  // Circumradius (Distance from center to vertex) given

  IF Area THEN
    A:=k;a:=SQRT((4*A*TAN(180/n))/n);r:=SQRT(A/(n*TAN(180/n)));R:=SQRT(2*A/(n*SIN(360/n)));
  END;  // Area given

  p:=n*a;  //  Perimeter

//  == Data display ==

DIMGROB_P(G1,320,240);                    //  Define working space (full screen)
RECT(G1);                                 //  Clear working space

  LINE_P(G1,160,120,100*COS(0)+160,100*SIN(0)+120,green);                 //  Circum Radius line
  ARC_P(G1,160,120,100,green);                                            //  Draw unit circumcircle (radius 100)
  TEXTOUT_P("Circumradius   =   " + ROUND(R,2),G1,165,105,2,green);       //  Label Circumradius

  LINE_P(G1,160,120,r/R*100*COS(180/n)+160,r/R*100*SIN(180/n)+120,blue);                            //  Inradius (Apothem) line
  ARC_P(G1,160,120,r/R*100,blue);                                                                   //  Draw unit Inircle (radius r/R*100)
  TEXTOUT_P("Apothem   = " + ROUND(r,2),G1,r/R*100*COS(180/n)+100,r/R*100*SIN(180/n)+120,2,blue);   //  Label Apothem radius

  TEXTOUT_P("Number of Sides = " + n,G1,100,4);                                                               //  Label Number of Sides
  TEXTOUT_P("Area = " + ROUND(A,2),G1,120,220);                                                               //  Label Number of Area
  TEXTOUT_P("Side Length  = " + ROUND(a,2),G1,200,r/R*100*SIN(180/n)+20,2,red);                               //  Label Side Length
  TEXTOUT_P("Ext. Angles = " + ROUND((180-360/n),1) + "°",G1,200,20,2,red);                                   //  Label Ext Angles
  TEXTOUT_P("Int. Angles = " + ROUND((360/n),1) + "°",G1,r/R*100*COS(180/n)+20,r/R*100*SIN(180/n)+10,2,red); //  Label Int Angles
  TEXTOUT_P("Perimeter = " + ROUND(p,2),G1,10,25,2,red);                                                    //  Label Number of Sides  

  FOR I from 0 to 360 STEP 360/n do    
    LINE_P(G1,100*COS(I)+160,100*SIN(I)+120,100*COS(I+360/n)+160,100*SIN(I+360/n)+120,red);  //  n Sides
  END; 

BLIT_P(G0,0,0,320,240,G1,0,0,320,240);    //  Transfer working space to display space
WAIT;
 
  Print;
  Print( "           SUMMARY:" + CHAR(10) + CHAR(10) +
         "    Number of sides = " + n + CHAR(10) +
         "    Side length = " + ROUND(a,2) + CHAR(10) +
         "    Perimeter = " + ROUND(p,2) + CHAR(10) +
         "    Area = " + ROUND(A,2) + CHAR(10) +
         CHAR(10) + 
         "    Circumradius = " + ROUND(R,2) + CHAR(10) +
         "    Inradius (Apothem) = " + ROUND(r,2) + CHAR(10) +         
         CHAR(10) +  
         "    Interior Angles = " + 360/n + "°" + CHAR(10) +
         "    Exterior Angles = " + (180-360/n) + "°" );

END;
Find all posts by this user
Quote this message in a reply
04-07-2016, 01:37 PM
Post: #5
RE: Programming questions
(04-07-2016 11:29 AM)DrD Wrote:  
Code:

//  RegPolygon()
//  4/7/2016  DrD
//
//  Regular polygon, (equal sides, and equal angles)
//
//  Finds:
//         1. Side length                                                     (a);  a:=2*r*TAN(180/n), a:=2*R*SIN(180/n), a:=SQRT((4*A*TAN(180/n))n)
//         2. Inradius (apothem: Distance from center to midpoint of a side)  (r);  r:=1/2*a*COT(180/n), r:=R*COS(180/n), r:=SQR(A*n*TAN(180/n))        
//         3. Circumradius (Distance from center to a vertex)                 (R);  R:=1/2*a*CSC(180/n), R:=r*SEC(180/n), R:=SQRT(2*A/(n*SIN(360/n)))  
//         4. Area                                                            (A);  A:=1/4*n*a^2*COT(180/n), A:=n*r^2*TAN(180/n), A:=1/2*n*R^2*SIN(180/n)
//         5. Perimeter                                                       (p);  p:=n*a, p:=2*n*R*sin(180/n)     
//
//  Provide the number of sides (n),  select one of the unknowns (a,r,R,A), and it's dimension.  

EXPORT RegPolygon()
BEGIN

  LOCAL a,r,p,R,A;
  LOCAL n,k,Sidelength,Apothem,Circumradius,Area,Perimeter;  // n=number of sides, k=known parameter, cb(x)=checkboxes for (a,r,R,A,p)
  LOCAL white:=rgb(255,255,255),
        black:=rgb(0,0,0),
        red:=rgb(255,0,0),        
        green:=rgb(0,255,0),
        blue:=rgb(0,0,255);        

  HAngle:=1;

    input ({ {n, [0], {60,20,0}}, 
             {k, [0], {60,20,1}},             
             
             {Perimeter, 4, {45,21,3}}, 
             {Apothem, 4, {75,21,3}},
             {Circumradius, 4, {45,21,4}},
             {Area, 4, {75,21,4}},
             {Sidelength, 4, {45,21,5}} },

             "Regular Polygon Parameters", 
             {"Number of sides ", "(Check box) Dimension"}, 
             {"How many sides?", "(Checked box) Value?"},           
             {6,5}, 
             {6,5} ); 

  IF Perimeter THEN
    a:=k/n;r:=1/2*a*COT(180/n);R:=1/2*a*CSC(180/n);A:=1/4*n*a^2*COT(180/n);
  END; 

 IF Sidelength THEN
    a:=k;r:=1/2*a*COT(180/n);R:=1/2*a*CSC(180/n);A:=1/4*n*a^2*COT(180/n);
  END; // Sidelength given

  IF Apothem THEN
    r:=k;a:=2*r*TAN(180/n);R:=r*SEC(180/n);A:=n*r^2*TAN(180/n);
  END; // Inradius (Distance from center to Apothem (midpoint of side))given

  IF Circumradius THEN
    R:=k;a:=2*R*SIN(180/n);r:=R*COS(180/n);A:=1/2*n*R^2*SIN(360/n);
  END;  // Circumradius (Distance from center to vertex) given

  IF Area THEN
    A:=k;a:=SQRT((4*A*TAN(180/n))/n);r:=SQRT(A/(n*TAN(180/n)));R:=SQRT(2*A/(n*SIN(360/n)));
  END;  // Area given

  p:=n*a;  //  Perimeter

//  == Data display ==

DIMGROB_P(G1,320,240);                    //  Define working space (full screen)
RECT(G1);                                 //  Clear working space

  LINE_P(G1,160,120,100*COS(0)+160,100*SIN(0)+120,green);                 //  Circum Radius line
  ARC_P(G1,160,120,100,green);                                            //  Draw unit circumcircle (radius 100)
  TEXTOUT_P("Circumradius   =   " + ROUND(R,2),G1,165,105,2,green);       //  Label Circumradius

  LINE_P(G1,160,120,r/R*100*COS(180/n)+160,r/R*100*SIN(180/n)+120,blue);                            //  Inradius (Apothem) line
  ARC_P(G1,160,120,r/R*100,blue);                                                                   //  Draw unit Inircle (radius r/R*100)
  TEXTOUT_P("Apothem   = " + ROUND(r,2),G1,r/R*100*COS(180/n)+100,r/R*100*SIN(180/n)+120,2,blue);   //  Label Apothem radius

  TEXTOUT_P("Number of Sides = " + n,G1,100,4);                                                               //  Label Number of Sides
  TEXTOUT_P("Area = " + ROUND(A,2),G1,120,220);                                                               //  Label Number of Area
  TEXTOUT_P("Side Length  = " + ROUND(a,2),G1,200,r/R*100*SIN(180/n)+20,2,red);                               //  Label Side Length
  TEXTOUT_P("Ext. Angles = " + ROUND((180-360/n),1) + "°",G1,200,20,2,red);                                   //  Label Ext Angles
  TEXTOUT_P("Int. Angles = " + ROUND((360/n),1) + "°",G1,r/R*100*COS(180/n)+20,r/R*100*SIN(180/n)+10,2,red); //  Label Int Angles
  TEXTOUT_P("Perimeter = " + ROUND(p,2),G1,10,25,2,red);                                                    //  Label Number of Sides  

  FOR I from 0 to 360 STEP 360/n do    
    LINE_P(G1,100*COS(I)+160,100*SIN(I)+120,100*COS(I+360/n)+160,100*SIN(I+360/n)+120,red);  //  n Sides
  END; 

BLIT_P(G0,0,0,320,240,G1,0,0,320,240);    //  Transfer working space to display space
WAIT;
 
  Print;
  Print( "           SUMMARY:" + CHAR(10) + CHAR(10) +
         "    Number of sides = " + n + CHAR(10) +
         "    Side length = " + ROUND(a,2) + CHAR(10) +
         "    Perimeter = " + ROUND(p,2) + CHAR(10) +
         "    Area = " + ROUND(A,2) + CHAR(10) +
         CHAR(10) + 
         "    Circumradius = " + ROUND(R,2) + CHAR(10) +
         "    Inradius (Apothem) = " + ROUND(r,2) + CHAR(10) +         
         CHAR(10) +  
         "    Interior Angles = " + 360/n + "°" + CHAR(10) +
         "    Exterior Angles = " + (180-360/n) + "°" );

END;
This program is very nice! TKS!

Leo

Visit this user's website Find all posts by this user
Quote this message in a reply
04-07-2016, 05:43 PM
Post: #6
RE: Programming questions
Thanks for the replies, it helps a lot !

PS : the program is awesome !
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)