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

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

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

revision 1.1 by tjl, Fri Oct 25 08:20:44 2002 UTC revision 1.2 by tjl, Sun Nov 17 20:56:37 2002 UTC
# Line 1  Line 1 
1    from __future__ import nested_scopes
2    
3  from java.awt import Color  from java.awt import Color
4    
5  class SSScene :  class SSScene :
6      def __init__(self):      def __init__(self):
7          self.bgdepth = 40          self.bgdepth = 40
8          self.shadow = getDList("""          gen = java.util.Random()
9              PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT DEPTH_BUFFER_BIT          def jit(s):
10              Enable BLEND              return s + .1*(2*gen.nextDouble()-1)
11              DepthFunc EQUAL          # l = (.5, .66, .83, 1.16, 1.33, 1.5)
12              Disable ALPHA_TEST          # self.lights = [(jit(x),jit(y)) for x in l for y in l]
13            if 0:
14              Begin TRIANGLE_FAN              self.shadow = getDList("""
15              Color 0 0 0 1                  PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT DEPTH_BUFFER_BIT
16              Vertex .5 .5                  Enable BLEND
17              Color 0 0 0 .2                  DepthFunc EQUAL
18              Vertex 0 0                  Disable ALPHA_TEST
19              Vertex 0 1  
20              Vertex 1 1                  Begin TRIANGLE_FAN
21              Vertex 1 0                  Color 0 0 0 1
22              Vertex 0 0                  Vertex .5 .5
23              End                  Color 0 0 0 .2
24                    Vertex 0 0
25                    Vertex 0 1
26                    Vertex 1 1
27                    Vertex 1 0
28                    Vertex 0 0
29                    End
30    
31                    PopAttrib
32                """)
33            else:
34                self.shadowstart = getDListNocoords("""
35                    PushAttrib ENABLE_BIT CURRENT_BIT COLOR_BUFFER_BIT DEPTH_BUFFER_BIT
36                    Enable BLEND
37                    DepthFunc EQUAL
38                    Disable ALPHA_TEST
39                    BlendColor .95 .95 .95 0
40                    BlendFunc ZERO CONSTANT_COLOR
41    
42              PopAttrib              """)
43          """)              self.shadowend = getDListNocoords("""
44                    PopAttrib
45                """)
46      def key(self, key):      def key(self, key):
47          pass          pass
48      def draw(self, vs, color, depths, depth, x, y, w, h):      def draw(self, vs, color, depths, depth, x, y, w, h):
49          vs.put(coloredQuad(color), str(depth), depth, x, y, w, h)          vob = coloredQuad(color)
50            vs.put(vob, str(depth), depth, x, y, w, h)
51            q = quad()
52    
53          for d in depths:          vs.map.put(self.shadowstart)
54              if d > depth:  
55                  o = 1 * (d-depth)          for l in self.lights:
56                  vs.put(self.shadow, str((d, depth)), d, x+o, y+o, w, h)              for d in depths:
57                    if d > depth:
58                        o = (d-depth)
59                        vs.put(vob, str((d, depth,l)), d, x+l[0]*o, y+l[1]*o, w, h)
60            vs.map.put(self.shadowend)
61                    
62      def scene(self, vs):      def scene(self, vs):
63          vs.map.put(background((.3, .6, .7)))          vs.map.put(background((.3, .6, .7)))
64          depths = (10, 20, 30, 40)          depths = (10, 20, 30, 40)
65    
66            gen = java.util.Random()
67            def r(s=1):
68                return s * gen.nextDouble()
69    
70          self.draw(vs, (.3,.7,.8), depths, depths[3], 0, 0, 600, 600)          self.draw(vs, (.3,.7,.8), depths, depths[3], 0, 0, 600, 600)
71          self.draw(vs, (0,1,0), depths, depths[2], 140, 50, 30, 400)          self.draw(vs, (0,1,0), depths, depths[2], r(640), r(450), r(300), r(400))
72          self.draw(vs, (1,0,0), depths, depths[1], 150, 150, 100, 100)          self.draw(vs, (1,0,0), depths, depths[1], r(650), r(450), r(300), r(400))
73          self.draw(vs, (0,0,1), depths, depths[0], 100, 100, 100, 100)          self.draw(vs, (0,0,1), depths, depths[0], r(600), r(400), r(400), r(300))
74                    
75  currentScene = SSScene()  currentScene = SSScene()

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