Vibrating rectangles: Difference between revisions

no edit summary
No edit summary
Line 198:
}
</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
The program works by drawing a rectangle the size of the window and then shrinking it using the Windows InflateRect API call. Each time the rectangle shrinks, it steps through a 48 entry color palette. Each time the program goes through the color palette, it offsets the palette index by one, which causes the color pattern to move inward continously. By allowing the rectangle to shrink past zero, it turns inside out and give the exotic pattern seen in the image.
<syntaxhighlight lang="Delphi">
 
 
procedure DrawVibratingRectangles(Image: TImage);
var StartRect,WR: TRect;
const PenSize = 2;
var I,J,Offset: integer;
begin
StartRect:=Rect(0,0,Image.Width,Image.Height);
Image.Canvas.Pen.Width:=PenSize;
Image.Canvas.Brush.Style:=bsClear;
Offset:=0;
{Run for 100 seconds}
for J:=0 to 1000 do
begin
{Start with Window-sized rect}
WR:=StartRect;
for I:=0 to 100 do
begin
{Draw rectangle}
Image.Canvas.Pen.Color:=ColorMap47[(I+Offset) mod Length(ColorMap47)];
Image.Canvas.Rectangle(WR);
{Shrink rect by twice the pen width}
InflateRect(WR,-PenSize*2,-PenSize*2);
end;
Image.Repaint;
Inc(Offset);
Application.ProcessMessages;
if AbortFlag or Application.Terminated then break;
Sleep(100);
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
Elapsed Time: 14.692 Sec.
</pre>
 
 
=={{header|EasyLang}}==
465

edits