Click to open or copy the files for the Wormhole sample.
This effect uses palette animation.
Suppose we have a 4x4 display using 4 colors. We could set the colors up to look something like this:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Now we can cycle all of the colors in each row to the right. (The one on the right will wrap-around to the left.)
4 1 2 3
4 1 2 3
4 1 2 3
4 1 2 3
If we continue this cycling we would get animated lines moving to the right. The same can be done to animate the lines going down.
Now if we expand our palette to 16 colors, we can combine moving down and right at the same time.
If we tile these 4x4 blocks end to end and cycle the colors as above, we get a moving checkerboard.
The Wormhole sample does the same thing, except it uses 15x15 blocks (225 colors) and instead of tiling the blocks end to end on a flat plane, it tiles them in 3D, converging at the center of the wormhole.
The sample code generates the 3D wormhole using the aforementioned 15x15 grids.
After loading the bitmap to a direct draw surface, all that is left to do is rotate the colors, to produce a wormhole.
This sample uses the following keywords:
blt; clienttoscreen; createpalette; createsurface; createwindowex; cyclepalette; defwindowproc; destroywindow; directdrawcreate; dispatchmessage; doinit; findresource; finiobjects; freeresource; getclientrect; getentries; getmessage; getsystemmetrics; initfail; loadcursor; loadicon; loadresource; lock; lockresource; memcpy; messagebox; offsetrect; peekmessage; postmessage; postquitmessage; readbmpintosurfaces; registerclass; release; restore; restoreall; setcooperativelevel; setcursor; setdisplaymode; setentries; setpalette; showwindow; switch; translatemessage; unlock; updateframe; updatewindow; waitforverticalblank; waitmessage; windowproc; winmain