HP Forums
[Request] drawing a dinamic line - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: [Request] drawing a dinamic line (/thread-1815.html)



[Request] drawing a dinamic line - fabila - 07-10-2014 06:03 PM

I'm trying to draw a diameter of a circle, and rotate by dragging your finger on the screen,
How to do a single line it looks? I tried but that rect(G2) after blit(G2) but erases the background

Code:

export Mes()
BEGIN
    LOCAL m,m1,m2,mx,my,mxi,myi,A;
  RECT(RGB(252,252,200));
        DIMGROB_P(G2,340,240,RGB(252,252,200,128));
        DIMGROB_P(G3,340,240,RGB(252,252,200,128));
      ARC_P(G3,160,105,85,0,360);
blit(G3);
WHILE MOUSE(1)≥0 DO END;
REPEAT
    REPEAT
        m:=MOUSE;
        m1:=B→R(m(1));
        m2:=B→R(m(2));
        
    UNTIL SIZE(m1)>0;
    
        mx:=m1(1);
        my:=m1(2);
        mxi:=m1(3);
        myi:=m1(4);

    if m1(5)==#2d then  A:=(mx-mxi); END;
    
    LINE_P(G2,161+85*COS(A),106+85*SIN(A),161-85*COS(A),106-85*SIN(A),RGB(0,0,255));    
    TEXTOUT_P(A,G2,20,208,2,RGB(255,0,0));
  BLIT(G2);
UNTIL my>220 ;
END;



RE: [Request] drawing a dinamic line - eried - 07-10-2014 07:41 PM

For your example, fastest way is just redrawing the last line over with the background color.


RE: [Request] drawing a dinamic line - fabila - 07-10-2014 07:58 PM

(07-10-2014 07:41 PM)eried Wrote:  For your example, fastest way is just redrawing the last line over with the background color.
the problem is that if redraw using blit (G3) in the last line, the screen flickers while dragging your finger with a very ugly effect.


RE: [Request] drawing a dinamic line - eried - 07-10-2014 08:21 PM

Well, you can use G0 and/or a condition to avoid unnecessary redraws:

Code:
export Mes()
BEGIN
  LOCAL m,m1,m2,mx,my,mxi,myi,A;
  LOCAL p1:=0,p2:=0,p3:=0,p4:=0,o1:=-1,o2:=-1,o3:=-1,o4:=-1;
  RECT(RGB(252,252,200));
  DIMGROB_P(G2,340,240,RGB(252,252,200,128));
  DIMGROB_P(G3,340,240,RGB(252,252,200,128));
  ARC_P(G3,160,105,85,0,360);
  blit(G3);
  
WHILE MOUSE(1)≥0 DO END;
REPEAT
  REPEAT
    m:=MOUSE;
    m1:=B→R(m(1));
    m2:=B→R(m(2));
    
  UNTIL SIZE(m1)>0;
  
  mx:=m1(1);
  my:=m1(2);
  mxi:=m1(3);
  myi:=m1(4);
  
  if m1(5)==#2d then  A:=(mx-mxi); END;
  
  p1:=161+85*COS(A);
  p2:=106+85*SIN(A);
  p3:=161-85*COS(A);
  p4:=106-85*SIN(A);
  
  if p1<>o1 then
    LINE_P(G0,o1,o2,o3,o4,RGB(252,252,200));
    LINE_P(G0,p1,p2,p3,p4,RGB(0,0,255));
    o1:=p1;o2:=p2;o3:=p3;o4:=p4;
  end;
  //TEXTOUT_P(A,G0,20,208,2,RGB(255,0,0));
  //BLIT(G2);
UNTIL my>220 ;
END;



RE: [Request] drawing a dinamic line - fabila - 07-10-2014 09:23 PM

thank you very much for the code, just what I needed

Habia intentado el volver a dibujar la recta de color del fondo pero me faltaba el condicional muchas gracias.