home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / plasma.cpp < prev    next >
Text File  |  1995-03-29  |  3KB  |  67 lines

  1. /*****************************************************************************
  2.                                   ATTENTION!
  3.                            this source is VOTEWARE,
  4.               you may only use it to the conditions listed below:
  5.  
  6.   -You may modify it, or use parts of it in your own source as long as
  7.     this header stays on top of all files containing this source.
  8.   -You must give proper credit to the author, Niklas Beisert / pascal.
  9.   -You may not use it in commercial productions without the written
  10.     permission of the author.
  11.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  12.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  13.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  14.     buy another one and fill it out CORRECTLY!!!)
  15. *****************************************************************************/
  16.  
  17.  
  18.  
  19. // calculates a plasma
  20. // wid=1<<(resbit+xabits)
  21. // hgt=1<<(resbit+yabits)
  22. // col=1<<colbits
  23. // roughness=p
  24.  
  25. void makeplasma(unsigned char *buf, short resbit, short xabits=0, short yabits=0, short colbits=8, short p=500, long seed=0x17091977)
  26. {
  27.   long resx=1<<(xabits+resbit);
  28.   long resy=resx<<(yabits+resbit);
  29.   unsigned short resx1=resx-1;
  30.   unsigned short resy1=resy-resx;
  31.   short colmask=-1<<colbits;
  32.  
  33.   long mx2=1<<resbit;
  34.   long my2=resx<<resbit;
  35.   long x,y;
  36.   for (x=0; x<resx; x+=mx2)
  37.     for (y=0; y<resy; y+=my2)
  38.       buf[x+y]=((seed=0x015a4e35*seed+1)>>16)&~colmask;
  39.   short k;
  40.   for (k=0; k<resbit; k++)
  41.   {
  42.     unsigned short mx=mx2>>1;
  43.     unsigned short my=my2>>1;
  44.     for (y=0; y<resy; y+=my2)
  45.       for (x=0; x<resx; x+=mx2)
  46.       {
  47.         short c=((unsigned short)buf[x+y]+buf[x+((y+my2)&resy1)]+buf[((x+mx2)&resx1)+y]+buf[((x+mx2)&resx1)+((y+my2)&resy1)]+2+((((seed=0x015a4e35*seed+1)>>16)*(p*3))>>17))>>2;
  48.         buf[x+mx+y+my]=c&colmask?c&0x8000?0:~colmask:c;
  49.       }
  50.     for (y=0; y<resy; y+=my2)
  51.       for (x=0; x<resx; x+=mx2)
  52.       {
  53.         short c=((unsigned short)buf[((x-mx)&resx1)+y+my]+buf[x+y]+buf[x+mx+y+my]+buf[x+((y+my2)&resy1)]+2+((((seed=0x015a4e35*seed+1)>>16)*p)>>16))>>2;
  54.         buf[x+y+my]=c&colmask?c&0x8000?0:~colmask:c;
  55.       }
  56.     for (y=0; y<resy; y+=my2)
  57.       for (x=0; x<resx; x+=mx2)
  58.       {
  59.         short c=((unsigned short)buf[x+y]+buf[x+mx+((y-my)&resy1)]+buf[((x+mx2)&resx1)+y]+buf[x+mx+y+my]+2+((((seed=0x015a4e35*seed+1)>>16)*p)>>16))>>2;
  60.         buf[x+mx+y]=c&colmask?c&0x8000?0:~colmask:c;
  61.       }
  62.     mx2=mx;
  63.     my2=my;
  64.     p>>=1;
  65.   }
  66. }
  67.