Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
Re: Pyramide zeichnen
15. Mär 2007, 20:56
Hi,
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var i,x,y: Integer;
begin
for i:= 0 to 200 do
begin
x:= 300 - i; // 300 ist die X Position der Spitze
y:= 10 + i; // 10 ist die Y Position der Spitze
Canvas.Pen.Color := RGB(random(256),random(256),random(256)); // wenn mans bunt haben will :P (randomize ins FormCreate!
Canvas.MoveTo(x,y);
Canvas.LineTo(x+i*2,y);
end;
end;
vielleicht so ?
Ergänzung:
Und als komfortable Procedure:
Delphi-Quellcode:
procedure DrawPyramide(Canvas: TCanvas; const x,y,Height: Integer; Coloured: Boolean);
var i: Integer;
fx,fy: Integer;
begin
for i:= 0 to Height do
begin
fx:= x - i;
fy:= y + i;
if Coloured then
Canvas.Pen.Color := RGB(random(256),random(256),random(256));
Canvas.MoveTo(fx,fy);
Canvas.LineTo(fx+i*2,fy);
end;
end;
// Aufruf
DrawPyramide(Canvas,200,30,400,true);
Gruß
Neutral General
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
|
|
Zitat
|