gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx demo/irregular2.py libtexture/sawnoise....


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/irregular2.py libtexture/sawnoise....
Date: Tue, 17 Sep 2002 03:35:55 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/17 03:35:55

Modified files:
        gfx/demo       : irregular2.py 
        gfx/libtexture : sawnoise.texture 

Log message:
        Separate sine and saw wave peaks in spectrum

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregular2.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/sawnoise.texture.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/irregular2.py
diff -c gzz/gfx/demo/irregular2.py:1.5 gzz/gfx/demo/irregular2.py:1.6
*** gzz/gfx/demo/irregular2.py:1.5      Tue Sep 17 02:34:35 2002
--- gzz/gfx/demo/irregular2.py  Tue Sep 17 03:35:55 2002
***************
*** 3,9 ****
  
  tex = GZZGL.createTexture()
  tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
!           "sawnoise", ["scale", "0.07", "freq", "8", "df", "4", "bias", 
"0.5"])
  
  boxtex = GZZGL.createTexture()
  
--- 3,11 ----
  
  tex = GZZGL.createTexture()
  tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
!           "sawnoise", ["bias", "0.5",
!                        "scale", "0.2", "freq", "1", "df", "2", 
!                        "scale2", "0.05", "freq2", "12", "df2", "1.5"])
  
  boxtex = GZZGL.createTexture()
  
Index: gzz/gfx/libtexture/sawnoise.texture
diff -c gzz/gfx/libtexture/sawnoise.texture:1.1 
gzz/gfx/libtexture/sawnoise.texture:1.2
*** gzz/gfx/libtexture/sawnoise.texture:1.1     Tue Sep 17 02:34:35 2002
--- gzz/gfx/libtexture/sawnoise.texture Tue Sep 17 03:35:55 2002
***************
*** 6,13 ****
  #include <math.h>
  #define FPARAM(name, default) float name = params->getFloat(#name, default);
  
- #define a b
- 
  static double drand() {
      return random() / (double)RAND_MAX;
  }
--- 6,11 ----
***************
*** 23,42 ****
  /* Add a fourier noise to the data.
   */
  static void fourier_noise(int width, int height, int depth, int components, 
float *data, 
!               float freq, float df) {
!     int nf = (int)(2 * freq);
!     float xsin[2][nf][width];
      for(int i=0; i<width; i++) 
        for(int f = 0; f < nf; f++) {
!           xsin[0][f][i] = saw_sin(i/(float)width * f * M_PI * 2);
!           xsin[1][f][i] = saw_cos(i/(float)width * f * M_PI * 2);
!     }
!     float ysin[2][nf][height];
      for(int j=0; j<width; j++) 
        for(int f = 0; f < nf; f++) {
!           ysin[0][f][j] = saw_sin(j/(float)height * f * M_PI * 2);
!           ysin[1][f][j] = saw_cos(j/(float)height * f * M_PI * 2);
!     }
      
      
      if(depth < 2) {
--- 21,44 ----
  /* Add a fourier noise to the data.
   */
  static void fourier_noise(int width, int height, int depth, int components, 
float *data, 
!                         float freq, float df, float amp, float freq2, float 
df2, float amp2) {
!     int nf = (int)(2 * ((freq > freq2) ? freq : freq2));
!     float xsin[4][nf][width];
      for(int i=0; i<width; i++) 
        for(int f = 0; f < nf; f++) {
!           xsin[0][f][i] = sin(i/(float)width * f * M_PI * 2);
!           xsin[1][f][i] = cos(i/(float)width * f * M_PI * 2);
!           xsin[2][f][i] = saw_sin(i/(float)width * f * M_PI * 2);
!           xsin[3][f][i] = saw_cos(i/(float)width * f * M_PI * 2);
!       }
!     float ysin[4][nf][height];
      for(int j=0; j<width; j++) 
        for(int f = 0; f < nf; f++) {
!           ysin[0][f][j] = sin(j/(float)height * f * M_PI * 2);
!           ysin[1][f][j] = cos(j/(float)height * f * M_PI * 2);
!           ysin[2][f][j] = saw_sin(j/(float)height * f * M_PI * 2);
!           ysin[3][f][j] = saw_cos(j/(float)height * f * M_PI * 2);
!       }
      
      
      if(depth < 2) {
***************
*** 45,62 ****
          for(int yf = 0; yf < nf; yf++) {
  
            double f = sqrt(xf*xf + yf*yf);
!           if(f < freq-df || f > freq+df) continue;
! 
!           for(int xsc = 0; xsc < 2; xsc++) {
!             for(int ysc = 0; ysc < 2; ysc++) {
!               float coeff[components];
!               for(int co = 0; co < components; co++)
!                   coeff[co] = drand()-0.5;
!               int ind = 0;
!               for (int j = 0; j < height; j++) {
!                 for (int i = 0; i < width; i++) {
!                   for(int co = 0; co < components; co++)
!                       data[ind++] += xsin[xsc][xf][i] * ysin[ysc][yf][j] * 
coeff[co];
                  }
                }
              }
--- 47,70 ----
          for(int yf = 0; yf < nf; yf++) {
  
            double f = sqrt(xf*xf + yf*yf);
!           int b;
!           float a;
!           for (b = 0; b < 4; b += 2) {
!             if (b == 0 && fabs(f - freq) < df) a = amp; // Sine noise
!             else if (b == 2 && fabs(f - freq2) < df2) a = amp2; // Saw noise
!             else continue;
! 
!             for(int xsc = 0; xsc < 2; xsc++) {
!               for(int ysc = 0; ysc < 2; ysc++) {
!                 float coeff[components];
!                 for(int co = 0; co < components; co++)
!                   coeff[co] = a * (drand()-0.5);
!                 int ind = 0;
!                 for (int j = 0; j < height; j++) {
!                   for (int i = 0; i < width; i++) {
!                     for(int co = 0; co < components; co++)
!                       data[ind++] += xsin[xsc+b][xf][i] * ysin[ysc+b][yf][j] 
* coeff[co];
!                   }
                  }
                }
              }
***************
*** 71,88 ****
  
  void GENERATE(TextureParam *params, int width, int height, int depth, int 
components, float *data) {
      FPARAM(bias, 0);
!     FPARAM(scale, 1);
      FPARAM(freq, 5);
      FPARAM(df, 2);
  
      int d = (depth==0 ? 1 : depth);
  
      for(int i = 0; i<width*height*d*components; i++)
        data[i] = 0;
  
!     fourier_noise(width,height,d,components,data, freq, df);
      for(int i = 0; i<width*height*d*components; i++) {
-       data[i] *= scale;
        data[i] += bias;
      }
  }
--- 79,100 ----
  
  void GENERATE(TextureParam *params, int width, int height, int depth, int 
components, float *data) {
      FPARAM(bias, 0);
! 
      FPARAM(freq, 5);
      FPARAM(df, 2);
+     FPARAM(scale, 1);
+ 
+     FPARAM(freq2, 5);
+     FPARAM(df2, 0);
+     FPARAM(scale2, 1);
  
      int d = (depth==0 ? 1 : depth);
  
      for(int i = 0; i<width*height*d*components; i++)
        data[i] = 0;
  
!     fourier_noise(width,height,d,components,data, freq, df, scale, freq2, 
df2, scale2);
      for(int i = 0; i<width*height*d*components; i++) {
        data[i] += bias;
      }
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]