Brownian tree: Difference between revisions

Solved the task for Delphi
(Solved the task for Delphi)
Line 180:
draw.draw img
img.write "brownian_tree.bmp"</lang>
 
=={{header|Delphi}}==
<lang delphi>const
SIZE = 800;
NUM_PARTICLES = 1000;
 
procedure TForm1.Button1Click(Sender: TObject);
type
TByteArray = array[0..0] of Byte;
PByteArray = ^TByteArray;
var
B: TBitmap;
I: Integer;
P: TPoint;
begin
B := TBitmap.Create;
try
B.Width := SIZE;
B.Height := SIZE;
B.PixelFormat := pf8bit;
 
B.Canvas.Brush.Color := clBlack;
B.Canvas.FillRect(B.Canvas.ClipRect);
B.Canvas.Pixels[Random(SIZE), Random(SIZE)] := clWhite;
 
For I := 0 to NUM_PARTICLES - 1 do
Begin
P.X := Random(SIZE);
P.Y := Random(SIZE);
 
While true do
Begin
Inc(P.X, Random(3) - 1);
Inc(P.Y, Random(3) - 1);
 
If ((P.X or P.Y) < 0) or (P.X >= SIZE) or (P.Y >= SIZE) Then
Begin
P.X := Random(SIZE);
P.Y := Random(SIZE);
end
else if B.Canvas.Pixels[P.X, P.Y] <> 0 then
begin
B.Canvas.Pixels[P.X, P.Y] := clWhite;
Break;
end;
end;
end;
 
Canvas.Draw(0, 0, B);
finally
FreeAndNil(B);
end;
end;</lang>
Anonymous user