Entwickler-Ecke

Multimedia / Grafik - Kreise zeichnen


navarro2010 - Sa 21.05.11 12:13
Titel: Kreise zeichnen
Hallo,
ich möchte mit Delphi mehrere Kreise zeichnen, die unterschiedliche Größen haben, jedoch den gleichen Mittlepunkt. Es soll eine Art Fadenkreuz geben.
Hier mein Versuch:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure Image1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Image1Click(Sender: TObject);
  var x:integer;
begin
  x:=0;
  repeat
  Form1.Canvas.Ellipse(Form1.Width div 2-x, Form1.Height div 2-x, Form1.Width div 2+x, Form1.Height div 2+x);
  Form1.Canvas.Ellipse(Form1.Width div 2-2*x, Form1.Height div 2-2*x, Form1.Width div 2+2*x, Form1.Height div 2+2*x);
  x:=x+1;
  until x=73;

end;

end.


Ich glaube, dass zwar mehrere Kreise gezeichnet werden, die aber dann vom größten Kreis überdeckt werden. wie kann ich das ändern?
Danke für die Hilfe


Horst_H - Sa 21.05.11 12:45

Hallo,

Du musst den brush.style passend festlegen:
http://www.greatis.com/delphicb/tips/lib/graphics-brushstyles.html


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Image1Click(Sender: TObject);
  var x:integer;
begin
  x:=0;
  Form1.Canvas.Brush.Style :=bsClear;
  repeat
     with Form1.Canvas do
       begin
       Ellipse(Form1.Width div 2-x, Form1.Height div 2-x, Form1.Width div 2+x, Form1.Height div 2+x);
       Ellipse(Form1.Width div 2-2*x, Form1.Height div 2-2*x, Form1.Width div 2+2*x, Form1.Height div 2+2*x);
       end;
    inc(x);
  until x=73;

end;


Gruß Horst


Regan - Sa 21.05.11 12:46

Du könntest das Ganze von oben Herunterlaufen lassen. Dann wird der größte Kreis als erstes gemalt ;)


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  x:=73;
  repeat
  Form1.Canvas.Ellipse(Form1.Width div 2-x, Form1.Height div 2-x, Form1.Width div 2+x, Form1.Height div 2+x);
  Form1.Canvas.Ellipse(Form1.Width div 2-2*x, Form1.Height div 2-2*x, Form1.Width div 2+2*x, Form1.Height div 2+2*x);
  x:=x-1;
  until x<=0;


navarro2010 - Sa 21.05.11 13:02

Danke für eure Hilfe.
Wenn ich das Ganze so mache taucht allerdings noch das Problem auf, dass in der Mitte die Kreise so eng aneinander liegen, dass eigentlich ein schwarzer Punkt ist.
Was kann ich noch ändern?


Gerd Kayser - Sa 21.05.11 13:43

user profile iconnavarro2010 hat folgendes geschrieben Zum zitierten Posting springen:
Wenn ich das Ganze so mache taucht allerdings noch das Problem auf, dass in der Mitte die Kreise so eng aneinander liegen, dass eigentlich ein schwarzer Punkt ist.

Dann setz halt einen größeren Abstand, z. B.:

Delphi-Quelltext
1:
 x := x - 5;                    


beastofchaos - Sa 21.05.11 13:55

(Genau, dann könnte man der Schönheits halber auch noch die Funktion Dec() benutzen :P

-> Dec(x, 5);

Gruß, Thomas