}

Delphi.int.ru — Портал программистов

Вход Регистрация | Забыли пароль?

Просмотр кода

Идентификатор: 7a859e86 Описание: Код загружен: 4 октября 2013, 12:56 (Ixer)

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, ComCtrls, ExtCtrls, jpeg;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. Image1: TImage;
  12. pb1: TProgressBar;
  13. Timer1: TTimer;
  14. procedure Timer1Timer(Sender: TObject);
  15. procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  16. procedure FormResize(Sender: TObject);
  17. procedure FormDestroy(Sender: TObject);
  18. procedure FormCreate(Sender: TObject);
  19. procedure Image1DblClick(Sender: TObject);
  20. private
  21. { Private declarations }
  22. mjpeg:TJPEGImage;
  23. bit:TBitmap;
  24. c100:Integer;
  25. c150:integer;
  26. c300:integer;
  27. cim:Cardinal;
  28. cmax:cardinal;
  29. public
  30. { Public declarations }
  31. FUNCTION lim255(value:Integer):Byte;
  32. procedure rndPosX;
  33. end;
  34.  
  35. var
  36. Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.dfm}
  41. procedure TForm1.rndPosX;
  42. begin
  43. c100:= random(100)+10;
  44. c150:= random(150)+20;
  45. c300:= random(300)+30;
  46. end;
  47.  
  48. procedure TForm1.Timer1Timer(Sender: TObject);
  49. begin
  50. if (cim < cmax) or (cmax = 0) then begin
  51. Image1DblClick(nil);
  52. end
  53. else
  54. close;
  55. end;
  56.  
  57. procedure TForm1.FormCreate(Sender: TObject);
  58. begin
  59. mjpeg:= TJPEGImage.Create;
  60. bit:=TBitmap.Create;
  61. bit.Height:=Image1.Height;
  62. bit.Width:=Image1.Width;
  63. cim:=0;
  64. if StrToIntDef(ParamStr(1),5)>0 then
  65. begin
  66. cmax:=StrToIntDef(ParamStr(1),0);
  67. Timer1.Interval:=100;
  68. end;
  69. end;
  70.  
  71. procedure TForm1.FormDestroy(Sender: TObject);
  72. begin
  73. mjpeg.Free;
  74. bit.Free;
  75. end;
  76.  
  77. procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  78. begin
  79. if key = VK_ESCAPE then
  80. Close;
  81. end;
  82.  
  83. procedure TForm1.FormResize(Sender: TObject);
  84. begin
  85. bit.Height:=Image1.Height;
  86. bit.Width:=Image1.Width;
  87. end;
  88.  
  89. procedure TForm1.Image1DblClick(Sender: TObject);
  90. var xr,yr,xg,yg,xb,yb,i,j,wx,wy,wv,rv,gv,bv:integer;
  91. cr,cb,cg,cw:byte;
  92. kr,kg,kb,kw:real;
  93. begin
  94. Timer1.Enabled:=False;
  95. inc(cim);
  96. Randomize;
  97. rndPosX;
  98. xr:=random(Image1.Width-c300)+c150;
  99. yr:=random(Image1.Height-c300)+c150;
  100. xg:=random(Image1.Width-c300)+c150;
  101. yg:=random(Image1.Height-c300)+c150;
  102. xb:=random(Image1.Width-c300)+c150;
  103. yb:=random(Image1.Height-c300)+c150;
  104. wx:=random(Image1.Width-c300)+c150;
  105. wy:=random(Image1.Height-c300)+c150;
  106. kr:=random(c100)/10-5;
  107. kg:=random(c100)/10-5;
  108. kb:=random(c100)/10-5;
  109. kw:=random(c100)/10-5;
  110. wv:=Random(255);
  111. rv:=Random(255);
  112. gv:=Random(255);
  113. bv:=Random(255);
  114. for i:=0 to Image1.Width do
  115. begin
  116. for j:=0 to Image1.Height do
  117. begin
  118. cw:=round(abs(wv*(1-abs((wy+j)*kw+(wx-i))/sqrt(1+kw*kw)/Image1.Width)));
  119. cr:=round(abs(rv*(1-abs((yr+j)*kr+(xr-i))/sqrt(1+kr*kr)/Image1.Width)));
  120. cg:=round(abs(gv*(1-abs((yg+j)*kg+(xg-i))/sqrt(1+kg*kg)/Image1.Width)));
  121. cb:=round(abs(bv*(1-abs((yb-j)*kb+(xb-i))/sqrt(1+kb*kb)/Image1.Width)));
  122. bit.Canvas.Pixels[i,j]:=RGB(lim255(cr+cw),lim255(cg+cw),lim255(cb+cw));
  123. end;
  124. end;
  125. Image1.Picture.Bitmap.Assign(bit);
  126. mjpeg.Assign(bit);
  127. mjpeg.Compress;
  128. mjpeg.SaveToFile(ExtractFilePath(ParamStr(0))+'\im'+inttostr(Random($ffffff))+'.jpg');
  129. Timer1.Enabled:=True;
  130. end;
  131.  
  132. function TForm1.lim255(value: Integer): Byte;
  133. begin
  134. lim255:=abs(value-255);
  135. end;
  136.  
  137. end.

Ссылка на данный код:

На главную страницу сервиса обмена кодом »