Vibrating rectangles: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(9 intermediate revisions by 3 users not shown)
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.
 
[[File:DelphiVibratingRectangles.png|frame|none]]
<syntaxhighlight lang="Delphi">
 
 
 
const ColorMap47: array [0..46] of TColor = (
0 or (0 shl 8) or (0 shl 16),
255 or (224 shl 8) or (224 shl 16),
255 or (212 shl 8) or (212 shl 16),
255 or (169 shl 8) or (169 shl 16),
255 or (127 shl 8) or (127 shl 16),
255 or (84 shl 8) or (84 shl 16),
255 or (42 shl 8) or (42 shl 16),
255 or (0 shl 8) or (0 shl 16),
255 or (13 shl 8) or (0 shl 16),
255 or (26 shl 8) or (0 shl 16),
255 or (40 shl 8) or (0 shl 16),
255 or (53 shl 8) or (0 shl 16),
255 or (67 shl 8) or (0 shl 16),
255 or (80 shl 8) or (0 shl 16),
255 or (93 shl 8) or (0 shl 16),
255 or (107 shl 8) or (0 shl 16),
255 or (120 shl 8) or (0 shl 16),
255 or (134 shl 8) or (0 shl 16),
255 or (147 shl 8) or (0 shl 16),
255 or (161 shl 8) or (0 shl 16),
255 or (174 shl 8) or (0 shl 16),
255 or (187 shl 8) or (0 shl 16),
255 or (201 shl 8) or (0 shl 16),
255 or (214 shl 8) or (0 shl 16),
255 or (228 shl 8) or (0 shl 16),
255 or (241 shl 8) or (0 shl 16),
255 or (255 shl 8) or (0 shl 16),
236 or (248 shl 8) or (0 shl 16),
218 or (242 shl 8) or (0 shl 16),
200 or (235 shl 8) or (0 shl 16),
183 or (229 shl 8) or (0 shl 16),
167 or (223 shl 8) or (0 shl 16),
151 or (216 shl 8) or (0 shl 16),
136 or (210 shl 8) or (0 shl 16),
122 or (204 shl 8) or (0 shl 16),
108 or (197 shl 8) or (0 shl 16),
95 or (191 shl 8) or (0 shl 16),
83 or (185 shl 8) or (0 shl 16),
71 or (178 shl 8) or (0 shl 16),
60 or (172 shl 8) or (0 shl 16),
49 or (166 shl 8) or (0 shl 16),
39 or (159 shl 8) or (0 shl 16),
30 or (153 shl 8) or (0 shl 16),
22 or (147 shl 8) or (0 shl 16),
14 or (140 shl 8) or (0 shl 16),
6 or (134 shl 8) or (0 shl 16),
0 or (128 shl 8) or (0 shl 16));
 
 
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}}==
 
[https://easylang.dev/show/#cod=hY/LCoAgEEX3fsXdizJGLYL6mOgBgimotPDrY6w2bdzM3HMuDEzwyPbcowCQCtSMjqM9mCYQw1PN6MeX1uBCRFz8Zn2GISIoGC41jzNcOwZ2qXybvbO+etnw8udVw3936iMg3Qkt3ixu Run it]
[https://easylang.online/apps/_vibrating-rectangles.html Run it]
 
<syntaxhighlight lang="text">on timer
on timer
sz -= 2
if sz <-= 02
if sz =< 490
color random 1000sz -= 149
color randint 1000 - 1
.
.
move 50 - sz 50 - sz
line move 50 +- sz 50 - sz
line 50 + sz 50 +- sz
line 50 -+ sz 50 + sz
line 50 - sz 50 -+ sz
line 50 - sz 50 - sz
timer 0.2
timer 0.2
.
timer 0.2</syntaxhighlight>
</syntaxhighlight>
 
=={{header|Factor}}==
Line 266 ⟶ 364:
{ normal-title-bar close-button minimize-button } }
} <vibrating-gadget> >>gadgets ;</syntaxhighlight>
 
 
 
=={{header|FutureBasic}}==
Note: The compiled macOS app runs faster than the attached GIF with a smoother fade.
<syntaxhighlight lang="futurebasic">
_window = 1
 
void local fn BuildWindow
block NSUInteger i = 0
block double red, green, blue
block CGRect r = fn CGRectMake( 0, 0, 410, 410 )
window _window, @"Vibrating Rectangles", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
r = fn CGRectMake( 20, 20, 360, 360 )
timerbegin, 0.3, YES
i++
cln red = (((double)arc4random()/0x100000000));
cln green = (((double)arc4random()/0x100000000));
cln blue = (((double)arc4random()/0x100000000));
timerbegin, 0.2, NO
rect fill r, fn ColorWithRGB( red, green, blue, 1.0 )
timerend
rect fill r, fn ColorWithRGB( 0.3, 0.3, 0.3, 1.0 )
r = fn CGRectInset( r, 3, 3 )
if i mod 60 == 0 then r = fn CGRectMake( 20, 20, 360, 360 )
timerend
end fn
 
void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _windowWillClose : end
end select
end fn
 
random
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
[[file:Vibrating_Rectangles_FutureBasic.gif]]
 
=={{header|Go}}==
Line 1,199 ⟶ 1,341:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
9,476

edits