backface.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » 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 » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Demo » sgi » gl » backface.py
#! /usr/bin/env python

#   backface
#
#   draw a cube that can run with backface() turned on or off.
#   cube is moved when LEFTMOUSE is pressed and mouse itself is moved.

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

CUBE_SIZE = 200.0
CUBE_OBJ = 1

def main () :
  #
  x = 0
  y = 0
  moveit = 0
  #
  initialize()
  #
  while (1) :
    #
    while (qtest()) :
      dev, val = qread()
      #
      if dev == ESCKEY :
        backface(0)
        return
        #
      elif dev == REDRAW :
        reshapeviewport()
        drawcube(x,y)
        #
      elif dev == LEFTMOUSE :
        #
        # LEFTMOUSE down
        moveit = val
        #
      elif dev == BKEY :
        backface(1)
        drawcube(x,y)
        #
      elif dev == FKEY :
        backface(0)
        drawcube(x,y)
        #
    if moveit :
      x = getvaluator(MOUSEX)
      y = getvaluator(MOUSEY)
      drawcube(x,y)


def initialize () :
  foreground ()
  keepaspect (1, 1)
  gid = winopen('backface')
  winset(gid)
  winconstraints()
  #
  doublebuffer()
  gconfig()
  shademodel(FLAT)
  #
  ortho(-1024.0, 1024.0, -1024.0, 1024.0, -1024.0, 1024.0)
  #
  qdevice(ESCKEY)
  qdevice(REDRAW)
  qdevice(LEFTMOUSE)
  qdevice(BKEY)
  qdevice(FKEY)
  qenter(REDRAW,gid)
  #
  backface(1)

#
# define a cube
def cube () :
  #
  # front face
  pushmatrix()
  translate(0.0,0.0,CUBE_SIZE)
  color(RED)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()
  #
  # right face
  pushmatrix()
  translate(CUBE_SIZE, 0.0, 0.0)
  rotate(900, 'y')
  color(GREEN)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()
  #
  # back face
  pushmatrix()
  translate(0.0, 0.0, -CUBE_SIZE)
  rotate(1800, 'y')
  color(BLUE)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()
  #
  # left face
  pushmatrix()
  translate(-CUBE_SIZE, 0.0, 0.0)
  rotate(-900, 'y')
  color(CYAN)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()
  #
  # top face
  pushmatrix()
  translate(0.0, CUBE_SIZE, 0.0)
  rotate(-900, 'x')
  color(MAGENTA)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()
  #
  # bottom face
  pushmatrix()
  translate(0.0, -CUBE_SIZE, 0.0)
  rotate(900, 'x')
  color(YELLOW)
  rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
  popmatrix()

def drawcube(x,y) :
  #
  pushmatrix()
  rotate(2*x, 'x')
  rotate(2*y, 'y')
  color(BLACK)
  clear()
  cube()        
  popmatrix()
  swapbuffers()


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.