/[gzz]/gzz/gfx/demo/irregu3.py
ViewVC logotype

Diff of /gzz/gfx/demo/irregu3.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by jvk, Mon Oct 21 12:53:56 2002 UTC revision 1.10 by jvk, Mon Oct 21 17:37:08 2002 UTC
# Line 1  Line 1 
1    from math import sin,cos,sqrt,pi
2    
3  ripple_scale = .25  ripple_scale = .25
4    
5  args = ["radius", "2", str(ripple_scale), "0.25",  args = ["radius", "2", str(ripple_scale), "0.25",
# Line 10  texinv.shade_all_levels(128, 128, 0, 4, Line 12  texinv.shade_all_levels(128, 128, 0, 4,
12                          ["invert", "1"])                          ["invert", "1"])
13    
14    
15    # alpha(y) = e / y * f >= e
16    #                    y <= f
17    
18    
19    def lerp(a, b, f):
20        return [ (1-f) * a[i] + f * b[i] for i in range(0, len(a)) ]
21        
22    def getirr(texid, angle, pos):
23    
24  # alpha(y) = e / y * f >= e      texmat = js([
25  #                    y <= f          cos(angle), sin(angle), 0, 0,
26            -sin(angle), cos(angle), 0, 0,
27            0, 0, 1, 0,
28            sin(angle)*pos, cos(angle)*pos, 0, 1,
29            ])
30    
31        col0l = [ (1.0,0.5,0.5), (0.5,0.5,1.0), (0.5,1.0,0.5), (1.0,0.5,0.5) ]
32        col1l = [ (.75,0.5,0.5), (0.5,0.5,.75), (0.5,.75,0.5), (.75,0.5,0.5) ]
33    
34        a = angle * 6 / (2 * pi)
35        while a < 0: a+=3
36        i = int(a) % 3
37        f = a - int(a)
38    
39        col0 = js(lerp(col0l[i], col0l[i+1], f))
40        col1 = js(lerp(col1l[i], col1l[i+1], f))
41    
42        #print col0, col1
43    
 def getirr(texid):  
44      e = 0.5      e = 0.5
45      return getDList("""      return getDList("""
46      PushAttrib ENABLE_BIT      PushAttrib ENABLE_BIT
# Line 83  def getirr(texid): Line 107  def getirr(texid):
107      #TexEnv TEXTURE_ENV OPERAND1_ALPHA_ARB SRC_ALPHA      #TexEnv TEXTURE_ENV OPERAND1_ALPHA_ARB SRC_ALPHA
108    
109      MatrixMode TEXTURE      MatrixMode TEXTURE
110      LoadMatrix 1 0 0 0  0 1 0 0  0 0 1 0  0 0 0 1      LoadMatrix %(texmat)s
111      MatrixMode MODELVIEW      MatrixMode MODELVIEW
112                    
113      Begin QUAD_STRIP      Begin QUAD_STRIP
114    
115      TexCoord 0 0 0 1      TexCoord 0 0 0 1
116      Color 1 .5 .5      Color %(col0)s
117      Vertex 0 %(e)s 0 1      Vertex 0 %(e)s 0 1
118    
119      TexCoord 0 0 0 %(e)s      TexCoord 0 0 0 %(e)s
120      Color .75 .5 .5      Color %(col1)s
121      Vertex 0 %(e)s 0 %(e)s      Vertex 0 %(e)s 0 %(e)s
122    
123      TexCoord 1 0 0 1      TexCoord 1 0 0 1
124      Color 1 .5 .5      Color %(col0)s
125      Vertex 1 %(e)s 0 1      Vertex 1 %(e)s 0 1
126    
127      TexCoord %(e)s 0 0 %(e)s      TexCoord %(e)s 0 0 %(e)s
128      Color .75 .5 .5      Color %(col1)s
129      Vertex %(e)s %(e)s 0 %(e)s      Vertex %(e)s %(e)s 0 %(e)s
130    
131      End      End
# Line 163  def getirr(texid): Line 187  def getirr(texid):
187  """ % vars())  """ % vars())
188    
189    
 irr = getirr(tex.getTexId())  
 irrinv = getirr(texinv.getTexId())  
   
190    
191    
192    
# Line 178  class IrreguScene: Line 199  class IrreguScene:
199      def __init__(self):      def __init__(self):
200          self.scale = 128          self.scale = 128
201          self.dist = 1          self.dist = 1
202            self.angle = 0
203            self.pos = 0
204                    
205      def scene(self, vs):      def scene(self, vs):
206          putnoc(vs, background((0.7,0.7,1.0)))          putnoc(vs, background((0.7,0.7,1.0)))
# Line 187  class IrreguScene: Line 210  class IrreguScene:
210          vs.matcher.add(cs1, "1")          vs.matcher.add(cs1, "1")
211          vs.matcher.add(cs2, "2")          vs.matcher.add(cs2, "2")
212    
213            irr = getirr(tex.getTexId(), self.angle, self.pos)
214            irrinv = getirr(texinv.getTexId(), self.angle, self.pos)
215    
216          vs.map.put(irr, cs1)          vs.map.put(irr, cs1)
217          vs.map.put(irrinv, cs2)          vs.map.put(irrinv, cs2)
218    
219      def key(self, k):      def key(self, k):
220          if k == "+": self.scale *= 1.4142135623731; print round(self.scale)          if k == "+": self.scale *= 1.4142135623731; print round(self.scale)
221          if k == "-": self.scale /= 1.4142135623731; print round(self.scale)          if k == "-": self.scale /= 1.4142135623731; print round(self.scale)
222          if k == "Up": self.dist *= 1.1          if k == "Prior": self.dist *= 1.1
223          if k == "Down": self.dist /= 1.1          if k == "Next": self.dist /= 1.1
224            if k == "Up": self.pos -= 1./128
225            if k == "Down": self.pos += 1./128
226            if k == "Left": self.angle -= pi/180
227            if k == "Right": self.angle += pi/180
228            print "angle",round(self.angle / pi * 180)
229    
230  currentScene = IrreguScene()          currentScene = IrreguScene()        

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26