PROGRAM Bresenham; {zeichnet geometrische Grundfiguren nach Bresenham} USES Crt, Graph; VAR xM, yM, radius : integer; PROCEDURE Eingabe (VAR x0, y0, r: integer); {liest Mittelpunktskoordinaten und Radius ein} BEGIN clrScr; writeln; writeln('Geben Sie Mittelpunkt und Radius ein!'); write('Abszisse des Mittelpunkts (z. B. 320): '); readln(x0); write('Ordinate des Mittelpunkts (z. B. 240): '); readln(y0); write('Kreisradius (z. B. 200): '); readln(r) END; {of Eingabe} PROCEDURE initGraphik; {initialisiert Grafikroutinen} VAR g0, g1 : integer; BEGIN g0 := detect; initGraph(g0, g1, 'BGI') END; {of initGraphik} PROCEDURE zeichne_Kreis (x0, y0, r: integer); {zeichnet Kreis um (x0, y0) mit Radius r; dabei erfolgt keine Prfung, ob der Kreis auf den Bildschirm pat} VAR x, y, delta : integer; FUNCTION sgn (x: integer): integer; {Signum-Funktion (Vorzeichen)} BEGIN IF x > 0 THEN sgn := 1 ELSE IF x < 0 THEN sgn := - 1 ELSE sgn := 0 END; {of sgn} PROCEDURE innerhalb; {whlt Punkt innerhalb der idealen Kreislinie} VAR inDelta : integer; BEGIN inDelta := delta + delta + y + y - 1; IF inDelta <= 0 THEN BEGIN x := succ(x); delta := delta + x + x + 1 END ELSE BEGIN y := pred(y); delta := delta - y - y + 1 END {of else} END; {of innerhalb} PROCEDURE ausserhalb; {whlt Punkt auerhalb der idealen Kreislinie} VAR ausDelta : integer; BEGIN ausDelta := delta + delta - x - x - 1; IF ausDelta <= 0 THEN BEGIN x := succ(x); y := pred(y); delta := delta + x + x - y - y + 2 END ELSE BEGIN y := pred(y); delta := delta - y - y + 1 END {of else} END; {of auerhalb} PROCEDURE drauf; {whlt Punkt auf der idealen Kreislinie} BEGIN x := succ(x); y := pred(y); delta := delta + x + x - y - y + 2 END; {of drauf} BEGIN {zeichne Kreis} x := 0; y := r; delta := 2 - r - r; putPixel(x0 + x, y0 + y, 10); WHILE y > 0 DO BEGIN delay(100); {Verzgerung} CASE sgn(delta) OF -1 : innerhalb; 0 : drauf; 1 : ausserhalb END; {of case} putPixel(x0 + x, y0 + y, 10); {1. Quadrant} putPixel(x0 - x, y0 + y, 10); {2. Quadrant} putPixel(x0 - x, y0 - y, 10); {3. Quadrant} putPixel(x0 + x, y0 - y, 10) {4. Quadrant} END {of while} END; {of zeichne Kreis} BEGIN {Hauptprogramm} Eingabe(xM, yM, radius); initGraphik; zeichne_Kreis(xM, yM, radius); readln; closeGraph END.