gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gfx/libpaper textures.py


From: Vesa Kaihlavirta
Subject: [Gzz-commits] gzz/gfx/libpaper textures.py
Date: Thu, 14 Nov 2002 08:44:55 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Vesa Kaihlavirta <address@hidden>       02/11/14 08:44:54

Modified files:
        gfx/libpaper   : textures.py 

Log message:
        Changed gfx.libpaper.textures.init() to return textures, not use icky 
globals.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/textures.py.diff?tr1=1.35&tr2=1.36&r1=text&r2=text

Patches:
Index: gzz/gfx/libpaper/textures.py
diff -u gzz/gfx/libpaper/textures.py:1.35 gzz/gfx/libpaper/textures.py:1.36
--- gzz/gfx/libpaper/textures.py:1.35   Thu Nov 14 07:07:38 2002
+++ gzz/gfx/libpaper/textures.py        Thu Nov 14 08:44:54 2002
@@ -50,9 +50,10 @@
 
 initialized = 0
 def init():
+    """Creates and returns textures.""" # XXX need more doc here
     global initialized
     initialized = 1
-    global ptextures
+    # global ptextures (return instead)
 
 
     # "scale": something like reciprocal of maximum derivative
@@ -334,25 +335,30 @@
 
     ptextures["FOOBAR"] = [ ptextures["RGB2"][-1] ]
     
+    return ptextures    
+
 def getPaperTexture(type, gen):
     return selectRandom(ptextures[type], gen)
 
 
 class Textures:
+    textures = None
     def __init__(self, seed):
-        if not initialized: init()
-        
+        if not self.textures:
+            self.textures = init()
+            print "DEBUG: Textures created"
+
        rnd = java.util.Random(seed)
 
         hyper = rnd.nextGaussian()*5
 
         self.probs = {}
 
-        for type in ["RGB2"] + filter(lambda key: key != "RGB2", 
ptextures.keys()):
+        for type in ["RGB2"] + filter(lambda key: key != "RGB2", 
self.textures.keys()):
             self.probs[type] = []
             sum = 0
 
-            for tex in ptextures[type]:
+            for tex in self.textures[type]:
                 prob = exp(rnd.nextGaussian() * hyper)
             
                 self.probs[type].append(prob)
@@ -371,12 +377,12 @@
         for p in self.probs[type]:
             t -= p
             if t < 0:
-                #print ptextures[type][index].getName()
-                return ptextures[type][index]
+                #print self.textures[type][index].getName()
+                return self.textures[type][index]
             index += 1
 
         print "Warning: null probability event occured"
-        return ptextures[type][-1]
+        return self.textures[type][-1]
         
 
     def getPaperTextures(self, types, gen):




reply via email to

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