Gravitation is a natural phenomenon by which all objects with mass attract each other. Gravity is the force that causes two particles to pull towards each other.
If smaller objects are pixels and a bigger object is your mouse pointer - when you move the mouse the pixels should follow :)
Wanna see how that would look coded in Delphi?
A great idea for the Fancy Delphi Application Contest ;-)
Pixelated Gravity
Here's what Gerben Wijnja said about this great idea:Here is my entry for the Fancy Delphi Application Contest! It became fancier than I initially planned. At first I thought: let's make a little thingy with pixels tracking the cursor. Then I added colors, then I added blur, then I converted some stuff to assembler to speed things up and finally I added a color filter.
It's still not a very big application but there's a LOT of comment, making it look pretty lengthy. Writing the comments took a lot longer than coding. :)
As Gerben says, this little piece of great code uses ASM (assembler) a lot. If you want to learn what can be done when using ASM in Delphi and how it can be done - reading the source code of "Pixelated Gravity" is a must!
Here's a code sneak peak:
procedure TGravityWindow.BlurBitmap;
var
y, offset: Cardinal;
w, h: Integer;
begin
w := FForm.ClientWidth;
h := FForm.ClientHeight;
{ We take 1 pixel, plus the 3 pixels below this top pixel, like this...
+---+
1 |
+---+---+---+
| 2 | 3 | 4 |
+---+---+---+
...and then we take the average and put that back in the top
pixel. We skip the bottom row of the bitmap (because obviously
there are no pixels to average below the bottom row) and we skip
the left and right column, because they have no pixels left and
right of them. }
for y := 0 to h - 2 do
BlurRow(FRows[y], FRows[y + 1], w) ;
// Make the left, right and bottom borders black
offset := 4 * (w - 1) ; // the x value of the right border
for y := 0 to h - 2 do
begin
SetPixel(DWORD(FRows[y]), 0) ;
SetPixel(DWORD(FRows[y]) + offset, 0) ;
end;
ZeroBitmap(FRows[h - 1], w) ;
end;
"Pixelated Gravity" was submitted by Gerben Wijnja.
Do you have a FDA(C)? Submit your Delphi code to the Fancy Delphi Application Contest.
