HP Forums
Programming problem with graphics - 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: Programming problem with graphics (/thread-2464.html)



Programming problem with graphics - ww63 - 11-21-2014 01:30 PM

Hello i've tried a short Programm, to display a analog clock on the screen:

Code:

#pragma mode( separator(.,;) integer(h32) )
EXPORT Uhr()
BEGIN
  LOCAL Tm,Hr,Mn,Sc,Mm,Ll;
  RECT(G0);
  REPEAT
    Tm := approx(Time);
    Hr := 2*π*(Tm MOD 12)/12;
    Mn := FP(Tm)*60;
    Sc := FP(Mn)*60;
    RECT(G1);
    FOR Mm FROM 0 TO 59 STEP 1 DO
      IF Mm MOD 5 == 0 THEN
        Ll := 8;
      ELSE
        Ll := 4;
      END;
      LINE_P(G1,ROUND(160+SIN(2*π*Mm/60)*(120-Ll),0),ROUND(120-COS(2*π*Mm/60)*(120-Ll),0),ROUND(160+SIN(2*π*Mm/60)*(120),0),ROUND(120-COS(2*π*Mm/60)*(120),0),RGB(192,192,192))
    END;

    LINE_P(G1,160,120,ROUND(160+SIN(Hr)*60,0),ROUND(120-COS(Hr)*60,0),RGB(0,0,0));
    LINE_P(G1,160,120,ROUND(160+SIN(2*π*Mn/60)*80,0),ROUND(120-COS(2*π*Mn/60)*80,0),RGB(0,0,255));
    LINE_P(G1,160,120,ROUND(160+SIN(2*π*Sc/60)*100,0),ROUND(120-COS(2*π*Sc/60)*100,0),RGB(255,0,0));
    BLIT_P(G0,0,0,320,240,G1,0,0,320,240); 
  UNTIL GETKEY ≥ 0;
  FREEZE; 
END;

but it won't display anything.

Edit: first it has dipslayed the clock, but after a few tries and minor changes it stopped working.


RE: Programming problem with graphics - Han - 11-21-2014 03:37 PM

You never declared the size of G1. So you're pretty much drawing into nothing, and then copying nothing into G0. Insert DIMGROB_P(G1,320,240) at the top and your clock works as it should.


RE: Programming problem with graphics - ww63 - 11-21-2014 03:55 PM

many thanks, i will try that.


RE: Programming problem with graphics - DrD - 11-21-2014 05:00 PM

No expert but, using just G0, and something like this could be a start:

Code:
#pragma mode( separator(.,;) integer(h32) )
EXPORT Uhr()
BEGIN
  LOCAL Tm,Hr,Mn,Sc,Mm,Ll;
  LOCAL fs,fm,fh;  // flag to redraw clock hands

  RECT(G0);

// Draw clock face

  FOR Mm FROM 0 TO 59 STEP 1 DO
    IF Mm MOD 5 == 0 THEN
      Ll := 8;
    ELSE
      Ll := 4;
    END;
      LINE_P(G0,ROUND(160+SIN(2*π*Mm/60)*(120-Ll),0),ROUND(120-COS(2*π*Mm/60)*(120-Ll),0),ROUND(160+SIN(2*π*Mm/60)*(120),0),ROUND(120-COS(2*π*Mm/60)*(120),0),RGB(192,192,192));
  END;

// Initialize time flags (hand redraws)

  Tm := approx(Time);
  fh:=FLOOR(2*π*(Tm MOD 12)/12);
  fm:=FLOOR(FP(Tm)*60);
  fs:=FLOOR(FP(Tm)*60^2);
 
// Update real time

  REPEAT
    Tm := approx(Time);
    Hr := 2*π*(Tm MOD 12)/12;
    Mn := FP(Tm)*60;
    Sc := FP(Mn)*60;


//  RECT(G1);

// Manage clock hands

    IF FLOOR(Hr)==fh then
      LINE_P(G0,160,120,ROUND(160+SIN(fh)*60,0),ROUND(120-COS(fh)*60,0),RGB(0,0,0));                       // Draw Hour hand
    ELSE
       LINE_P(G0,160,120,ROUND(160+SIN(fh)*60,0),ROUND(120-COS(fh)*60,0),RGB(255,255,255));                // Clear Hour hand
       fh:=FLOOR(Hr);  // Reset flag
    END;

    IF FLOOR(Mn)==fm then
      LINE_P(G0,160,120,ROUND(160+SIN(2*π*fm/60)*80,0),ROUND(120-COS(2*π*fm/60)*80,0),RGB(0,0,255));       //  Draw Minute hand
    ELSE 
      LINE_P(G0,160,120,ROUND(160+SIN(2*π*fm/60)*80,0),ROUND(120-COS(2*π*fm/60)*80,0),RGB(255,255,255));   // Clear Minute hand
      fm:=FLOOR(Mn);  // Reset flag
    END; 

    IF FLOOR(Sc)==fs then    
      LINE_P(G0,160,120,ROUND(160+SIN(2*π*fs/60)*100,0),ROUND(120-COS(2*π*fs/60)*100,0),RGB(255,0,0));     // Draw Second hand      
    ELSE
      LINE_P(G0,160,120,ROUND(160+SIN(2*π*fs/60)*100,0),ROUND(120-COS(2*π*fs/60)*100,0),RGB(255,255,255)); // Clear old Second hand
      fs:=FLOOR(Sc);   // Reset flag                                                                                                     
    END; 

    BLIT_P(G0,0,0,320,240,G1,0,0,320,240);
 
  UNTIL GETKEY ≥ 0;
  FREEZE; 
END;