Post Reply 
Programming problem with graphics
11-21-2014, 01:30 PM (This post was last modified: 11-21-2014 01:32 PM by ww63.)
Post: #1
Programming problem with graphics
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.
Find all posts by this user
Quote this message in a reply
11-21-2014, 03:37 PM (This post was last modified: 11-21-2014 03:40 PM by Han.)
Post: #2
RE: Programming problem with graphics
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
11-21-2014, 03:55 PM
Post: #3
RE: Programming problem with graphics
many thanks, i will try that.
Find all posts by this user
Quote this message in a reply
11-21-2014, 05:00 PM
Post: #4
RE: Programming problem with graphics
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;
Find all posts by this user
Quote this message in a reply
Post Reply 




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