daily pastebin goal
51%
SHARE
TWEET

Plasma

a guest Jul 30th, 2011 884 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////////////////////////////////
  2. //                                                       //
  3. //  PC MAGAZIN 10/1998 - Demo Projekt                    //
  4. //                                                       //
  5. //                                                       //
  6. //  Routinen zum erzeugen einfacher Sinus-Plasmen        //
  7. //                                                       //
  8. ///////////////////////////////////////////////////////////
  9.  
  10. #include "demo.h"
  11. #include <math.h>
  12. #include <stdlib.h>
  13.  
  14. static unsigned char *sintable;
  15. static int           *wave;
  16.  
  17.  
  18. void init_sineplasma (void)
  19. {
  20.     // vorberechnen der Sinus-Tabelle
  21.  
  22.     sintable = (unsigned char *) malloc (1024);
  23.     wave     = (int *) malloc (4* sizeof (int));
  24.  
  25.     for ( int i=0; i<1024; i++)
  26.         sintable[i] = 128+127*sin((float)i*3.14/512.0);
  27.  
  28.     for ( i=0; i<4; i++)
  29.         wave[i]=0;
  30. }
  31.  
  32.  
  33.  
  34. void done_sineplasma (void)
  35. {
  36.     free (sintable);
  37. }
  38.  
  39.  
  40. void make_sineplasma (float time, unsigned short *picture, unsigned short *palette,
  41.                       int width, int height)
  42. {
  43.     int y, x;
  44.     int speed_x[4];
  45.     int speed_y[4];
  46.     int workwave_x[4];
  47.     int workwave_y[4];
  48.  
  49.     // Speed-Werte der Wellen vorberechnen
  50.     speed_x[0] = 3000 * sin (time*1.0+1);
  51.     speed_y[0] = 3000 * cos (time*1.1+2);
  52.     speed_x[1] =  700 * sin (-time*1.2+3);
  53.     speed_y[1] =  700 * cos (-time*1.3+4);
  54.     speed_x[2] = 2300 * sin (time*1.4+5);
  55.     speed_y[2] = 2300 * cos (time*1.5+6);
  56.     speed_x[3] = 1700 * sin (time*1.6+7);
  57.     speed_y[3] = 1700 * cos (time*1.7+8);
  58.  
  59.     register int i;
  60.     for ( i=0; i<4; i++)
  61.     {
  62.         wave[i]      += speed_x[i];
  63.         workwave_y[i] = wave[i];
  64.     }
  65.  
  66.     // Schleife ueber die Hoehe des Bitmaps
  67.     for ( y=0; y<height; y++)
  68.     {
  69.         for ( i=0; i<4; i++) workwave_x[i] = workwave_y[i];
  70.  
  71.         // Scanline zeichnen
  72.         for ( x=0; x<width; x++)
  73.         {
  74.           *(picture++) = palette[(sintable[(workwave_x[0]>>8)&1023] +
  75.                                   sintable[(workwave_x[1]>>8)&1023] +
  76.                                   sintable[(workwave_x[2]>>8)&1023] +
  77.                                   sintable[(workwave_x[3]>>8)&1023])>>2];
  78.  
  79.           for ( i=0; i<4; i++) workwave_x[i] += speed_x[i];
  80.         }
  81.         for ( i=0; i<4; i++) workwave_y[i] += speed_y[i];
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top