Post Reply 
Keeping graphic objects in programs
11-21-2020, 04:43 PM
Post: #5
RE: Keeping graphic objects in programs
(11-21-2020 03:03 AM)cahlucas Wrote:  Dear Mr. Gege,
I like the ICON method, how can I use it with graphics made on my Prime? At least, I hope this is possible. How do I do that, and how do I bring it up on the screen? Sincerely, Karel.

If you type ICON in the command line, and while the cursor is touching any letter of the word ICON, pressing the [Help] key will bring up any relevant information on its usage. The unfortunate drawback (pun optional) is that one must rely on computer program to create the data for the ICON command. The data itself can be quite large even for very small images, and it makes code management extremely cumbersome if you ever need to alter your images. In short, there are much better ways that will also make your code more manageable.

If you are planning to create a relatively large project (perhaps large due to lots of graphics files), I would recommend creating them as PNG files. This can be done on your computer. Simply create them, and incorporate them into your application. Or if you generate them on your calculator, you can save the image on the screen using AFiles("filename.png"):=G0 (G0 through G9 are the system's graphic objects, with G0 being the current screen.) The AFiles() command really only makes sense within a custom application (i.e. an app you create based on one of the existing apps).

One of the applications I wrote makes use of an extensive collection of images: https://www.hpmuseum.org/forum/thread-7725.html

The source code is provided as well, so you are welcome to look at how they are used. A snippet of the drawing routine is below. Basically, the images are stored as img##.png files where ## are alphanumeric digits and "na" specifically means a picture is not available (scheme selected for ease of coding). The "picture" is either a static image, or a collection of frames within an animation.
Code:
// UI for viewing picture
ssShowPic()
begin
  local j,n,x,y,run,fname,frames;
  fname:=ssCurSys(9);

  if (type(fname) == 2) then

    // fixed image
    if (fname == "na") then
      msgbox(ssNoPicAvail);
    else
      dimgrob_p(G2,1,1);
      fname:="img" + fname + ".png";
      G2:=AFiles(fname);
      x:=grobw_p(G2);
      y:=grobh_p(G2);
      if ((x < 160) AND (y < 120)) then
        x:=2*x; y:=2*y;
      end;
      rect_p(G0);
      blit_p(160-x/2, 120-y/2,160+x/2,120+y/2,G2);
      textout_p(ssCurSys(1),1,1,4,ssR);
      freeze;
      wait(-1);
    end;

  else

    // animation (list)
    frames:=fname;
    n:=size(frames)-1;
    dimgrob_p(G2,1,1);
    fname:="img" + frames(1) + ".png";
    G2:=AFiles(fname);
    x:=grobw_p(G2);
    y:=grobh_p(G2);
    if ((x < 160) AND (y < 120)) then
      x:=2*x; y:=2*y;
    end;
    j:=0;
    run:=1;
    rect_p(G0);
    textout_p(ssCurSys(1),1,1,4,ssR);
    while run do
      j:=(j mod n) + 1;
      fname:="img" + frames(j) + ".png";
      G2:=AFiles(fname);
      blit_p(160-x/2, 120-y/2,160+x/2,120+y/2,G2);
      wait(frames(n+1));
      run:=(mouse(1)==-1) AND (getkey() == -1);
    end;

  end;
end;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Keeping graphic objects in programs - Han - 11-21-2020 04:43 PM



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