На главную
Подписка
Новости


Рейтинг@Mail.ru











Главная / DELPHI / Часто задаваемые вопросы и ответы на них / Графика / Пример прорисовки "плазмы" Сделать домашней страницей Добавить в избранное Написать писмо

Пример прорисовки "плазмы"



unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure makeplasma;
procedure start1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
plasma : array[0..768,0..768] of byte;
implementation
{$R *.DFM}
procedure TForm1.makeplasma;
procedure halfway(x1,y1,x2,y2: integer);
procedure adjust(xa,ya,x,y,xb,yb: integer);
var
d: integer;
v: double;
begin
if plasma[x,y]<>0 then exit;
d:=Abs(xa-xb)+Abs(ya-yb);
v:=(plasma[xa,ya]+plasma[xb,yb])/2+(random-0.5)*d*2;
if v<1 then v:=1;
if v>=193 then v:=192;
plasma[x,y]:=Trunc(v);
end;
var
x,y: integer;
v: double;
begin
if (x2-x1<2) and (y2-y1<2) then exit;
x:=(x1+x2) div 2;
y:=(y1+y2) div 2;
adjust(x1,y1,x,y1,x2,y1);
adjust(x2,y1,x2,y,x2,y2);
adjust(x1,y2,x,y2,x2,y2);
adjust(x1,y1,x1,y,x1,y2);
if plasma[x,y]=0 then
begin
v:=(plasma[x1,y1]+plasma[x2,y1]+plasma[x2,y2]+plasma[x1,y2])/4;
plasma[x,y]:=Trunc(v);
end;
halfway(x1,y1,x,y);
halfway(x,y1,x2,y);
halfway(x,y,x2,y2);
halfway(x1,y,x,y2);
end;
var
x,y :integer ;
begin
randomize;
plasma[0,768]:=random(192);
plasma[768,768]:=random(192);
plasma[768,0]:=random(192);
plasma[0,0]:=random(192);
halfway(0,0,768,768);
end;
procedure TForm1.start1Click(Sender: TObject);
var
x,y:integer;
begin
makeplasma;
for x:=0 to 255 do
begin
for y:=0 to 255 do
begin
image1.canvas.pixels[x,y]:=rgb(plasma[x,y],plasma[x+256,y+256],plasma[x+512,y+512]);
end;
image1.update;
end;
end;
end.



Copyright ©   "Мастера DELPHI"   E-mail:   delphi@mastak.com  http://www.delphimaster.ru
Источник получения информации: http://www.delphimaster.ru
Hosted by uCoz