Panel based, autoresizing, fullscreen filmgrain

It uses a single set of six 640 x 480 PCX images, and the scale factors are dependent on this size. If you use a different size, you'll have to change the scale values to match. As is, it takes up just over 6.2MB of video memory when active, and it'll purge itself when grainToggle = 0.

Code:

panel* pnl;
var grainToggle;

bmap grain1 = <grain1.pcx>;
bmap grain2 = <grain2.pcx>;
bmap grain3 = <grain3.pcx>;
bmap grain4 = <grain4.pcx>;
bmap grain5 = <grain5.pcx>;
bmap grain6 = <grain6.pcx>;

panel filmGrainPanel
{
layer = 200;
pos_x = 0;
pos_y = 0;
alpha = 5; //change to suit your needs
flags = transparent,overlay;
}

function filmGrain()
{
pnl = filmGrainPanel;
grainToggle = 1;
while(grainToggle == 1)
{
if(video_mode == 6) { pnl.scale_x = 1; pnl.scale_y = 1; } else { //640x480
if(video_mode == 7) { pnl.scale_x = 1.25; pnl.scale_y = 1.25; } else { //800x600
if(video_mode == 8) { pnl.scale_x = 1.6; pnl.scale_y = 1.6; } else { //1024x768
if(video_mode == 9) { pnl.scale_x = 2; pnl.scale_y = 2.134; } else { //1280x1024
if(video_mode == 11) { pnl.scale_x = 2.5; pnl.scale_y = 2.5; } } } } } //1600x1200
pnl.bmap = grain1; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain2; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain3; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain4; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain5; pnl.visible = on; sleep(0.09); pnl.visible = off;
pnl.bmap = grain6; pnl.visible = on; sleep(0.09); pnl.visible = off;
}
pnl.visible = off; bmap_purge(grain1); bmap_purge(grain2); bmap_purge(grain3); bmap_purge(grain4); bmap_purge(grain5); bmap_purge(grain6);
}



Here's some starter images. Use Winrar to open it. I highly recommend you create your own(use Gimp filmgrain/noise filters) so your project's grain isn't the same as every other one that uses it: http://www.geocities.com/hainesrs/grain6PCX.rar


My User Contributions master list - my initial post links are down but scroll down page to find list to active links