gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture
Date: Mon, 21 Oct 2002 08:53:56 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/10/21 08:53:56

Modified files:
        gfx/demo       : irregu3.py 
        gfx/libtexture : irregu.texture 

Log message:
        Add inverted version of the texture

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu3.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/irregu.texture.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/irregu3.py
diff -u gzz/gfx/demo/irregu3.py:1.8 gzz/gfx/demo/irregu3.py:1.9
--- gzz/gfx/demo/irregu3.py:1.8 Mon Oct 21 08:41:29 2002
+++ gzz/gfx/demo/irregu3.py     Mon Oct 21 08:53:56 2002
@@ -1,27 +1,24 @@
-
-tex = GL.createTexture()
-
-#tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
-#          "sawnoise", ["bias", ".5",
-#                       "scale", "0.15", "freq", "1", "df", "2", 
-#                       "scale2", "0.25", "freq2", "10", "df2", ".5"])
-
 ripple_scale = .25
-tex.shade_all_levels(128, 128, 0, 4, "RGBA", "RGBA",
-                     "irregu", ["radius", "2", str(ripple_scale), "0.25",
-                                "scale", ".25", "bias", ".75", "eps", ".125"])
 
+args = ["radius", "2", str(ripple_scale), "0.25",
+        "scale", ".25", "bias", ".75", "eps", ".125"]
+
+tex = GL.createTexture()
+texinv = GL.createTexture()
+tex.shade_all_levels(128, 128, 0, 4, "RGBA", "RGBA", "irregu", args)
+texinv.shade_all_levels(128, 128, 0, 4, "RGBA", "RGBA", "irregu", args +
+                        ["invert", "1"])
 
 
-e = 0.5
 
-texid = tex.getTexId()
 
 
 # alpha(y) = e / y * f >= e
 #                    y <= f
 
-irr = getDList("""
+def getirr(texid):
+    e = 0.5
+    return getDList("""
     PushAttrib ENABLE_BIT
 
     BindTexture TEXTURE_2D %(texid)s
@@ -166,6 +163,12 @@
 """ % vars())
 
 
+irr = getirr(tex.getTexId())
+irrinv = getirr(texinv.getTexId())
+
+
+
+
 def getIrregu(x0, y0, x1, y1, s0, t0, s1, t1):
     tlen = sqrt((s1 - s0)**2 + (t1 - t0)**2)
     len =  sqrt((x1 - x0)**2 + (y1 - y0)**2)
@@ -174,17 +177,23 @@
 class IrreguScene:
     def __init__(self):
         self.scale = 128
+        self.dist = 1
         
     def scene(self, vs):
         putnoc(vs, background((0.7,0.7,1.0)))
 
         cs1 = vs.coords.affineCoordsys(0, 0, 512, 384, self.scale, 0, 0, 
-2*ripple_scale*self.scale)
+        cs2 = vs.coords.affineCoordsys(0, 0, 512, 384-self.dist*self.scale, 
self.scale, 0, 0, 2*ripple_scale*self.scale)
        vs.matcher.add(cs1, "1")
+       vs.matcher.add(cs2, "2")
 
         vs.map.put(irr, cs1)
+        vs.map.put(irrinv, cs2)
 
     def key(self, k):
         if k == "+": self.scale *= 1.4142135623731; print round(self.scale)
         if k == "-": self.scale /= 1.4142135623731; print round(self.scale)
+        if k == "Up": self.dist *= 1.1
+        if k == "Down": self.dist /= 1.1
 
 currentScene = IrreguScene()        
Index: gzz/gfx/libtexture/irregu.texture
diff -u gzz/gfx/libtexture/irregu.texture:1.4 
gzz/gfx/libtexture/irregu.texture:1.5
--- gzz/gfx/libtexture/irregu.texture:1.4       Mon Oct 21 08:41:30 2002
+++ gzz/gfx/libtexture/irregu.texture   Mon Oct 21 08:53:56 2002
@@ -3,11 +3,13 @@
 
 #define FPARAM(name, default) float name = params->getFloat(#name, default);
 
+#define INVERT(i, x) ((i) + 2 * (0.5 - (i)) * (x))
+
 float func(float x, float y) {
     float t = x*10;
     float u = y*10;
-    return .5 + .2 * sin(x*M_PI*2*4) - .2*(t-floor(t)) + .2*sin(y*M_PI*2)
-       +  .2*(u-floor(u));
+    return  .5 + .2 * sin(x*M_PI*2*4) - .2*(t-floor(t)) + .2*sin(y*M_PI*2) 
+       + .2*(u-floor(u));
 }
 
 float filter(float *data, int w, int h, int c, float x, float y) {
@@ -32,6 +34,7 @@
     FPARAM(bias, 0);
     FPARAM(scale, 1);
     FPARAM(eps, .25);
+    FPARAM(invert, 0);
     
     // Note: radius is specified in texels
     FPARAM(radius, 2);
@@ -50,7 +53,7 @@
     ind = 3;
     for (j = 0, y = 0; j < height; j++, y += ystep) {  
        for (i = 0, x = 0; i < width; i++, x += xstep) {
-           data[ind] = func(x,y) * scale + bias;
+           data[ind] = INVERT(invert, func(x,y)) * scale + bias;
 
            // Add outer edge to quantized inner edge
            data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0;




reply via email to

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