mixing.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Demo » sgi » gl » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Demo » sgi » gl » mixing.py
#! /usr/bin/env python

# Use Gouraud shading to mix colors.  Requires Z-buffer.
# It changes the color assignments so fast that you see white.
# Left button pauses, middle rotates the square.  ESC to quit.
# Experiment with a larger window (too slow) or smaller window (really white).

from GL import *
from gl import *
import DEVICE
from math import *

#
#  tekenvlak : draw a square. with bgnpolygon
#
def tekenvlak (vc) :
  bgnpolygon()
  #vcarray (vc)
  for i in vc :
    c3f (i[1])
    v3f (i[0])
  endpolygon()

#
# tekendoos : draw a box
#
def tekendoos (col) :
  v = [(-5.0,0.0,0.0),(0.0,5.0,0.0),(5.0,0.0,0.0),(0.0,-5.0,0.0)]
  vc = [(v[0],col[0]),(v[1],col[1]),(v[2],col[2]),(v[3],col[1])]
  tekenvlak (vc)

#
# initialize gl
#
def initgl () :
  #
  # open window
  #
  foreground ()
  keepaspect (1, 1)
  prefposition (100, 500, 100, 500)
  w = winopen ('PYTHON RGB')
  keepaspect (1, 1)
  winconstraints()
  #
  # configure pipeline (2buf, GOURAUD and RGBmode)
  #
  doublebuffer ()
  zbuffer (1)
  shademodel (GOURAUD)
  RGBmode ()
  gconfig ()
  #
  # set viewing
  #
  perspective (900, 1, 1.0, 10.0)
  polarview (10.0, 0, 0, 0)
  #
  # ask for the REDRAW and ESCKEY events
  #
  qdevice(DEVICE.MOUSE2)
  qdevice(DEVICE.MOUSE3)
  qdevice(DEVICE.REDRAW)
  qdevice(DEVICE.ESCKEY)


#
# the color black
#
black = 0
#
# GoForIT : use 2buf to redraw the object 2n times. index i is used as 
# the (smoothly changing) rotation angle
#
def GoForIt(i) :
  col = [(255.0,0.0,0.0), (0.0,255.0,0.0), (0.0,0.0,255.0)]
  twist = 0
  freeze = 1
  while 1 :
    if freeze <> 0 :
      col[0],col[1],col[2] = col[1],col[2],col[0]
    #
    # clear z-buffer and clear background to light-blue
    #
    zclear()
    cpack (black)
    clear()
    #
    tekendoos (col)
    #
    swapbuffers()
    #
    if qtest() <> 0 :
      dev, val = qread()
      if dev == DEVICE.ESCKEY :
        break
      elif dev == DEVICE.REDRAW :
        reshapeviewport ()
      elif dev == DEVICE.MOUSE2 and val <> 0 :
        twist = twist + 30
        perspective (900, 1, 1.0, 10.0)
        polarview (10.0, 0, 0, twist)
      elif dev == DEVICE.MOUSE3 and val <> 0 :
        freeze = 1 - freeze


# the main program
#
def main () :
  initgl ()
  GoForIt (0)

#
# exec main
#
main  ()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.