Kreis zeichnen - GLCD - bekomme nur ein Karo?

OP #664542
Lesenswert?

Hallo,

ich habe mich beim zeichen auf den C-Code unter wikipedia berufen und in 
mit copy/paste in mein Code hineingebastelt und bekomme nur karos!

Der funktioniert doch, oder?
Hat jemand Erfahrung mit dem Code?

void ks0108_circle(uint8_t x0, uint8_t y0, uint8_t radius)  {
  uint8_t f = 1 - radius;
     uint8_t ddF_x = 0;
     uint8_t ddF_y = -2 * radius;
     uint8_t x = 0;
     uint8_t y = radius;

     ks0108_set_pixel(x0, y0 + radius);
     ks0108_set_pixel(x0, y0 - radius);
     ks0108_set_pixel(x0 + radius, y0);
     ks0108_set_pixel(x0 - radius, y0);

     while(x < y) {
      if(f >= 0) {
           y--;
           ddF_y += 2;
           f += ddF_y;
      }
    x++;
    ddF_x += 2;
    f += ddF_x + 1;
    ks0108_set_pixel(x0 + x, y0 + y);
    ks0108_set_pixel(x0 - x, y0 + y);
    ks0108_set_pixel(x0 + x, y0 - y);
    ks0108_set_pixel(x0 - x, y0 - y);
    ks0108_set_pixel(x0 + y, y0 + x);
    ks0108_set_pixel(x0 - y, y0 + x);
    ks0108_set_pixel(x0 + y, y0 - x);
    ks0108_set_pixel(x0 - y, y0 - x);
  }
}


Gruß

Tobi
#664571
Lesenswert?

>uint8_t f = 1 - radius;
>uint8_t ddF_x = 0;
>uint8_t ddF_y = -2 * radius;

deklariere f als int16_t oder int32_t, und ddf_x, ddf_y als int16_t. Bei 
beiden musst du mit Vorzeichen rechnen.

im verlinkten Thread schaue dir RasterCircle() von Johannes an, das ist 
defakto excakt der Source den du auch hast, eben nur mit korrekten 
Deklarationen der lokalen Variablen.

Gruß Hagen

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren