Post new question
Question
Reply
 
Tutor
Posts: 12
Member Since: ‎03-01-2017
Message 1 of 1 (388 Views)

ARC_P issue

Product Name: HP Prime v1

I made a simple interactive graphics program to get used to mouse and during development I discoverd an interesting bug: When printing to a grob, ARC_P doesn't accept multiple prints through matrix calls. In other words, you can give ARC_P input from a matrix once and it will operate as expected, but if you try to iterate through a loop using this matrix, ARC_P breaks down and displays a black loop with radius y, with the center intersecting the center point and the center on y = 0 For all ARC_P on the screen. 

 

Here's my code. Note the A, B, C, D, E, and F is a work around that fixes the issue.

 

icrColor(red,green,blue,cStep);
printCirc(center,radius,color);

EXPORT Mouse_Test()
BEGIN
  SUBGROB_P(G0,G2);
  LOCAL centers,radii,colors,rStep;
  LOCAL red,green,blue,cStep;
  cStep:= 8; // Calc //  .8 //Emu
  rStep:= 1; // Calc //  .1 //Emu
  RECT_P();
  LOCAL last,curr,rMax,nCirc,lastN,maxN;
  last:={};
  DIMGROB_P(G1,320,240);
  REPEAT
    curr:= MOUSE();
    curr:= curr[1];
    
    IF size(curr) THEN
      FOR I FROM 1 TO 5 DO
        curr[I]:= SETBASE(curr[I]);
      END;

      IF curr[5]==0 AND size(last)==0 THEN
        rMax:= MAX(√((curr[1])^2+(curr[2])^2),√((curr[1])^2+(240-curr[2])^2),√((320-curr[1])^2+(curr[2])^2),√((320-curr[1])^2+(240-curr[2])^2));
        IF nCirc THEN
          ADDROW(centers,[curr[1],curr[2]],1);
          ADDROW(radii,[0,rMax],1);
          ADDROW(colors,[255,0,0],1);
        ELSE 
          centers:= [[curr[1],curr[2]]];
          radii:= [[0,rMax]];
          colors:= [[255,0,0]];
        END;
        nCirc:= nCirc+1;
      END;
    END;
    lastN:= nCirc;
    last:= curr;
    IF nCirc>maxN THEN maxN:= nCirc; END;

    BLIT_P(G1,G2);
//    RECT_P(G1);
    IF nCirc>0 THEN
      I:= 1;
      WHILE nCirc>=I DO
//        TEXTOUT_P(nCirc,G1,10,120);
//        TEXTOUT_P(maxN,G1,120,120);
        printCirc(centers[I],radii[I,1],colors[I]);
        radii[I,1]:= radii[I,1]+rStep;
        colors:= REPLACE(colors,{I,1},icrColor(colors[I],cStep)); 
        IF radii[I,1]>radii[I,2] THEN
          DELROW(centers,I);
          DELROW(radii,I);
          DELROW(colors,I);
          nCirc:= nCirc-1;
        ELSE
          I:= I+1;
        END;
      END;
    END;
    BLIT_P(G1);
  UNTIL GETKEY==30;
END;

icrColor(color,cStep)
BEGIN
  LOCAL keystep,red,green,blue;
  red:= color[1];
  green:= color[2];
  blue:= color[3];
  CASE
    IF red==255 AND green≠255 AND blue==0 THEN keystep:= 0; END;
    IF red≠0 AND green==255 AND blue==0 THEN keystep:= 1; END;
    IF red==0 AND green==255 AND blue≠255 THEN keystep:= 2; END;
    IF red==0 AND green≠0 AND blue==255 THEN keystep:= 3; END;
    IF red≠255 AND green==0 AND blue==255 THEN keystep:= 4; END;
    IF red==255 AND green==0 AND blue≠0 THEN keystep:= 5; END;
  END;
  CASE
    IF keystep==0 THEN
      green:= green+cStep;
      IF green>255 THEN green:= 255; END;
    END;
    IF keystep==1 THEN
      red:= red-cStep;
      IF red<0 THEN red:= 0; END; 
    END;
    IF keystep==2 THEN
      blue:= blue+cStep;
      IF blue>255 THEN blue:= 255; END;
    END;
    IF keystep==3 THEN
      green:= green-cStep;
      IF green<0 THEN green:= 0; END;
    END;
    IF keystep==4 THEN
      red:= red+cStep;
      IF red>255 THEN red:= 255; END;
    END;
    IF keystep==5 THEN
      blue:= blue-cStep;
      IF blue<0 THEN blue:= 0; END;
    END;
  END;
  RETURN [red,green,blue];
END;

printCirc(center,radius,color)
BEGIN
  A:= center[1];
  B:= center[2];
  C:= radius;
  D:= color[1];
  E:= color[2];
  F:= color[3];

  FOR J FROM 0 TO 2 DO
    IF (radius-J)≥0 THEN 
      ARC_P(G1,A,B,C-J,RGB(D,E,F)); 
    END;
  END;
END;
Reply
0
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation