/[gzz]/gzz/gfx/demo/fillet/oldcode.py
ViewVC logotype

Diff of /gzz/gfx/demo/fillet/oldcode.py

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

revision 1.1 by tjl, Thu Dec 5 17:33:52 2002 UTC revision 1.2 by tjl, Thu Dec 19 09:12:39 2002 UTC
# Line 1  Line 1 
1    if 0:
2    
3  # Demo fillets      # Demo fillets
4    
5  from gzz.impl import *      from gzz.impl import *
6  from gzz.view import *      from gzz.view import *
7  from gzz.gfx.gl import *      from gzz.gfx.gl import *
8  from gzz.media.impl import *      from gzz.media.impl import *
9  import gzz      import gzz
10    
11  from gfx.libutil import saveanim      from gfx.libutil import saveanim
12  reload(saveanim)      reload(saveanim)
13    
14  red = (1, 0.2, 0.2)      red = (1, 0.2, 0.2)
15  green = (0.2, 1, 0.2)      green = (0.2, 1, 0.2)
16  whitish = (1,1,0.9)      whitish = (1,1,0.9)
17    
18    
19  def rectangle(rgb):      def rectangle(rgb):
20      return getDList("""          return getDList("""
21          LineWidth 4              LineWidth 4
22          Color %s %s %s              Color %s %s %s
23          Disable TEXTURE_2D              Disable TEXTURE_2D
24          Begin LINE_LOOP              Begin LINE_LOOP
25          Vertex -1 -1              Vertex -1 -1
26          Vertex -1 1              Vertex -1 1
27          Vertex 1 1              Vertex 1 1
28          Vertex 1 -1              Vertex 1 -1
29          End              End
30      """%(rgb))          """%(rgb))
31    
32    
33  class ZZScene(AlphaCells):      class ZZScene(AlphaCells):
34      def __init__(self):          def __init__(self):
35          obsTrigger = SimpleObsTrigger();              obsTrigger = SimpleObsTrigger();
36          cellTexter = SimpleVStreamTexter(FakeSpanMaker(),              cellTexter = SimpleVStreamTexter(FakeSpanMaker(),
37                      Enfilade1DImpl.Enfilade1DImplMaker())                          Enfilade1DImpl.Enfilade1DImplMaker())
38          cellManager = PlainCellManager()              cellManager = PlainCellManager()
39          dimManager = SimpleDim.SimpleDimManager()              dimManager = SimpleDim.SimpleDimManager()
40          identityManager = DummyIdentityManager()              identityManager = DummyIdentityManager()
41          space = self.space = gzz.impl.ModularSpace(              space = self.space = gzz.impl.ModularSpace(
42              cellTexter, cellManager, dimManager, identityManager, None, obsTrigger)                  cellTexter, cellManager, dimManager, identityManager, None, obsTrigger)
43          self.cursor = self.space.getHomeCell()              self.cursor = self.space.getHomeCell()
44          d1 = self.d1 = space.getDim(space.N())              d1 = self.d1 = space.getDim(space.N())
45          d2 = self.d2 = space.getDim(space.N())              d2 = self.d2 = space.getDim(space.N())
46    
47          self.home = self.space.getHomeCell()              self.home = self.space.getHomeCell()
48    
49          self.initStruct()              self.initStruct()
50    
51          self.bgcolor = (0.7, 0.8, 0.6)              self.bgcolor = (0.7, 0.8, 0.6)
52    
53          AlphaCells.__init__(self)              AlphaCells.__init__(self)
54      def showstruct(self, vs, passno):          def showstruct(self, vs, passno):
55          pv = PlainVanishing()              pv = PlainVanishing()
56          vc = self.getVanishingClient(vs, passno)              vc = self.getVanishingClient(vs, passno)
57          class SimpleVC(ViewContext):              class SimpleVC(ViewContext):
58              def __init__(self, main):                  def __init__(self, main):
59                  self.main = main                      self.main = main
60              def getAccursed(self):                  def getAccursed(self):
61                  return self.main.cursor                      return self.main.cursor
62              def getCursorColors(self, c):                  def getCursorColors(self, c):
63                  return None                      return None
64              def getDims(self):                  def getDims(self):
65                  return [self.main.d1, self.main.d2]                      return [self.main.d1, self.main.d2]
66              def getCursorOffset(self):                  def getCursorOffset(self):
67                  return 0                      return 0
68              def getWindow(self):                  def getWindow(self):
69                  return None                      return None
70    
71          pv.render(vc, SimpleVC(self), 400, 400)              pv.render(vc, SimpleVC(self), 400, 400)
72      def getVanishingClient(self, vs, passno):          def getVanishingClient(self, vs, passno):
73          ind = self.ind              ind = self.ind
74          return gzz.gfx.gl.GLVanishingClient(vs, 0,              return gzz.gfx.gl.GLVanishingClient(vs, 0,
75                  self.cells[passno][ind],                      self.cells[passno][ind],
76                  self.vert[1][ind],                      self.vert[1][ind],
77                  self.horiz[1][ind],                      self.horiz[1][ind],
78                      50, 50)                          50, 50)
79      def move(self, dim, dir):          def move(self, dim, dir):
80          c = self.cursor.s(dim, dir)              c = self.cursor.s(dim, dir)
81          if c != None:              if c != None:
82              self.cursor = c                  self.cursor = c
83      def key(self, k):          def key(self, k):
84          if k == "Right":              if k == "Right":
85              self.move(self.d1, 1)                  self.move(self.d1, 1)
86          if k == "Left":              if k == "Left":
87              self.move(self.d1, -1)                  self.move(self.d1, -1)
88          if k == "Up":              if k == "Up":
89              self.move(self.d2, -1)                  self.move(self.d2, -1)
90          if k == "Down":              if k == "Down":
91              self.move(self.d2, 1)                  self.move(self.d2, 1)
92          if k == "t":              if k == "t":
93              self.ind += 1                  self.ind += 1
94              self.ind %= len(cellTexs)                  self.ind %= len(cellTexs)
95              print "IND NOW: ",self.ind                  print "IND NOW: ",self.ind
96      def scene(self, vs):          def scene(self, vs):
97          d = w.getSize()              d = w.getSize()
98          putnoc(vs, background(self.bgcolor))              putnoc(vs, background(self.bgcolor))
99    
100          putnoc(vs, getDList("""              putnoc(vs, getDList("""
101              Enable ALPHA_TEST                  Enable ALPHA_TEST
102              AlphaFunc GEQUAL 0.2                  AlphaFunc GEQUAL 0.2
103              Enable DEPTH_TEST                  Enable DEPTH_TEST
104              Disable BLEND                  Disable BLEND
105              Enable TEXTURE_2D                  Enable TEXTURE_2D
106              PushAttrib POLYGON_BIT ENABLE_BIT                  PushAttrib POLYGON_BIT ENABLE_BIT
107          """))              """))
   
         for passno in (0,1):  
   
             if passno == 0:  
                 putnoc(vs, getDList("""  
                     Color %s %s %s  
                 """ % self.bgcolor))  
             else:  
                 putnoc(vs, getDList("""  
                     Color 1 1 1  
                 """))  
108    
109              self.showstruct(vs, passno)              for passno in (0,1):
110    
111          putnoc(vs, getDList("""                  if passno == 0:
112              PopAttrib                      putnoc(vs, getDList("""
113              """))                          Color %s %s %s
114          return vs                      """ % self.bgcolor))
115                    else:
116                        putnoc(vs, getDList("""
117                            Color 1 1 1
118                        """))
119    
120  class NormalZZScene(ZZScene):                  self.showstruct(vs, passno)
121      def initStruct(self):  
122          home = self.home              putnoc(vs, getDList("""
123          d1,d2 = (self.d1, self.d2)                  PopAttrib
         home.connect(d2, home.N(self.d1).N(self.d2).N(self.d1))  
         self.ind = 5  
   
   
 class ExpScene(AlphaCells):  
     def __init__(self):  
         self.cw = 8  
         self.ch = 8  
         self.jx = 3  
         self.jy = 5  
         self.dx = 1  
         self.zoom = 1  
         self.cs = [  
             [None for y in range(0, self.ch)] for  
                 x in range(0, self.cw)]  
         self.ind = 1  
   
         AlphaCells.__init__(self)  
   
         self.bgcolor = (0.8, 0.5, 0.8)  
     def putcs(self, vs):  
         for x in range(0,self.cw):  
             for y in range(0, self.ch):  
                 self.cs[x][y]=vs.coords.ortho(str(x)+"_"+str(y), 10,  
                     x + 0.2 , y + 0.2, 0.6, 0.6)  
     def key(self, k):  
         if k == "s":  
             self.dx = 1-self.dx  
         if k == "z":  
             self.zoom = 1-self.zoom  
         if k == "t":  
             self.ind += 1  
             self.ind %= len(cellTexs)  
             print "IND NOW: ",self.ind  
         pass  
           
     def scene(self, vs):  
         d = w.getSize()  
         putnoc(vs, background(self.bgcolor))  
         self.putcs(vs)  
   
         putnoc(vs, getDList("""  
             Enable ALPHA_TEST  
             AlphaFunc GEQUAL 0.2  
             Enable DEPTH_TEST  
             DepthFunc LEQUAL  
             Disable BLEND  
             Enable TEXTURE_2D  
         """))  
   
         if self.zoom:  
             zw = 320  
             transaffine(vs, "aff", d.width/2-zw*(self.jx+0.5),  
                                     d.height/2-zw*(self.jy+0.5),  
                                     zw, 0, 0, zw)  
         else:  
             zw = d.height / self.ch  
             transaffine(vs, "aff", 0, 0, zw, 0, 0, zw)  
   
         for passno in (0,1):  
   
             if passno == 0:  
                 putnoc(vs, getDList("""  
                     Color %s %s %s  
                 """ % self.bgcolor))  
             else:  
                 putnoc(vs, getDList("""  
                     Color 1 1 1  
124                  """))                  """))
125                return vs
126    
127        class NormalZZScene(ZZScene):
128            def initStruct(self):
129                home = self.home
130                d1,d2 = (self.d1, self.d2)
131                home.connect(d2, home.N(self.d1).N(self.d2).N(self.d1))
132                self.ind = 5
133    
134    
135        class ExpScene(AlphaCells):
136            def __init__(self):
137                self.cw = 8
138                self.ch = 8
139                self.jx = 3
140                self.jy = 5
141                self.dx = 1
142                self.zoom = 1
143                self.cs = [
144                    [None for y in range(0, self.ch)] for
145                        x in range(0, self.cw)]
146                self.ind = 1
147    
148                AlphaCells.__init__(self)
149    
150                self.bgcolor = (0.8, 0.5, 0.8)
151            def putcs(self, vs):
152              for x in range(0,self.cw):              for x in range(0,self.cw):
153                  for y in range(0, self.ch):                  for y in range(0, self.ch):
154                      vs.map.put(                      self.cs[x][y]=vs.coords.ortho(str(x)+"_"+str(y), 10,
155                          self.cells[passno][self.ind],                          x + 0.2 , y + 0.2, 0.6, 0.6)
156                          self.cs[x][y]          def key(self, k):
157                          )              if k == "s":
158                    self.dx = 1-self.dx
159                if k == "z":
160                    self.zoom = 1-self.zoom
161                if k == "t":
162                    self.ind += 1
163                    self.ind %= len(cellTexs)
164                    print "IND NOW: ",self.ind
165                pass
166                
167            def scene(self, vs):
168                d = w.getSize()
169                putnoc(vs, background(self.bgcolor))
170                self.putcs(vs)
171    
172                putnoc(vs, getDList("""
173                    Enable ALPHA_TEST
174                    AlphaFunc GEQUAL 0.2
175                    Enable DEPTH_TEST
176                    DepthFunc LEQUAL
177                    Disable BLEND
178                    Enable TEXTURE_2D
179                """))
180    
181              for x in range(0,self.cw-1):              if self.zoom:
182                  for y in range(0, self.ch):                  zw = 320
183                      if self.dx and y == self.jy:                  transaffine(vs, "aff", d.width/2-zw*(self.jx+0.5),
184                          if x == self.jx:                                          d.height/2-zw*(self.jy+0.5),
185                              continue                                          zw, 0, 0, zw)
186                          if x == self.jx-1:              else:
187                              vs.map.put(                  zw = d.height / self.ch
188                                  self.horiz[passno][self.ind],                  transaffine(vs, "aff", 0, 0, zw, 0, 0, zw)
                                 self.cs[x][y],  
                                 self.cs[x+2][y]  
                                 )  
                             continue  
                     vs.map.put(  
                         self.horiz[passno][self.ind],  
                         self.cs[x][y],  
                         self.cs[x+1][y]  
                         )  
189    
190              for x in range(0,self.cw):              for passno in (0,1):
191                  for y in range(0, self.ch-1):  
192                      if (not self.dx) and x == self.jx:                  if passno == 0:
193                          if y == self.jy:                      putnoc(vs, getDList("""
194                              continue                          Color %s %s %s
195                          if y == self.jy-1:                      """ % self.bgcolor))
196                              vs.map.put(                  else:
197                                  self.vert[passno][self.ind],                      putnoc(vs, getDList("""
198                                  self.cs[x][y+2],                          Color 1 1 1
199                                  self.cs[x][y]                      """))
200                                  )  
201                              continue                  for x in range(0,self.cw):
202                      vs.map.put(                      for y in range(0, self.ch):
203                          self.vert[passno][self.ind],                          vs.map.put(
204                          self.cs[x][y+1],                              self.cells[passno][self.ind],
205                          self.cs[x][y],                              self.cs[x][y]
206                          )                              )
207    
208          poptrans(vs, "aff")                  for x in range(0,self.cw-1):
209                        for y in range(0, self.ch):
210          return vs                          if self.dx and y == self.jy:
211                                if x == self.jx:
212  def quad(rgb):                                  continue
213      return getDList("""                              if x == self.jx-1:
214          LineWidth 4                                  vs.map.put(
215          Color %s %s %s                                      self.horiz[passno][self.ind],
216          Disable TEXTURE_2D                                      self.cs[x][y],
217          Begin QUADS                                      self.cs[x+2][y]
218          Vertex -1 -1                                      )
219          Vertex -1 1                                  continue
220          Vertex 1 1                          vs.map.put(
221          Vertex 1 -1                              self.horiz[passno][self.ind],
222          End                              self.cs[x][y],
223      """%(rgb))                              self.cs[x+1][y]
224                                )
225  def globalkey(k):  
226      if k == "0":                  for x in range(0,self.cw):
227          sc = AlphaBlendScene2()                      for y in range(0, self.ch-1):
228          vs1 = w.createVobScene()                          if (not self.dx) and x == self.jx:
229          vs2 = w.createVobScene()                              if y == self.jy:
230          sc.scene(vs1)                                  continue
231          sc.key("p")                              if y == self.jy-1:
232          sc.scene(vs2)                                  vs.map.put(
233          s = { "x" : 20, "y" : 20, "w" : 600, "h" : 600 }                                      self.vert[passno][self.ind],
234          saveanim.savesequence(w, "tmpfilm/frame0.", vs1, vs2, 30, **s)                                      self.cs[x][y+2],
235          saveanim.savesequence(w, "tmpfilm/frame1.", vs2, vs1, 20, **s)                                      self.cs[x][y]
236                                        )
237                                    continue
238                            vs.map.put(
239                                self.vert[passno][self.ind],
240                                self.cs[x][y+1],
241                                self.cs[x][y],
242                                )
243    
244                poptrans(vs, "aff")
245    
246                return vs
247    
248        def quad(rgb):
249            return getDList("""
250                LineWidth 4
251                Color %s %s %s
252                Disable TEXTURE_2D
253                Begin QUADS
254                Vertex -1 -1
255                Vertex -1 1
256                Vertex 1 1
257                Vertex 1 -1
258                End
259            """%(rgb))
260    
261        def globalkey(k):
262            if k == "0":
263                sc = AlphaBlendScene2()
264                vs1 = w.createVobScene()
265                vs2 = w.createVobScene()
266                sc.scene(vs1)
267                sc.key("p")
268                sc.scene(vs2)
269                s = { "x" : 20, "y" : 20, "w" : 600, "h" : 600 }
270                saveanim.savesequence(w, "tmpfilm/frame0.", vs1, vs2, 30, **s)
271                saveanim.savesequence(w, "tmpfilm/frame1.", vs2, vs1, 20, **s)
272    
273          saveanim.encodefilm("tmpfilm/frame\\*", "filletfilm.avi")              saveanim.encodefilm("tmpfilm/frame\\*", "filletfilm.avi")
274    
275      return 0          return 0
276    
277  currentScene = scenes[0]      currentScene = scenes[0]
278    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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