fisheye.py from gzz at Krugle
Show fisheye.py syntax highlighted
#
# Copyright (c) 2003, Janne Kujala, Tuomas Lukka and Benja Fallenstein
#
# This file is part of Gzz.
#
# Gzz is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Gzz is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with Gzz; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
from __future__ import nested_scopes
execfile("gfx/libpaper/papermill.py")
pdfbase = "../mstmpimg/0000000008000000E9377484930004EE0856BC11F38551006325788A14C474081350DF47A8280C-144-%s"
page = 1
pdftex = None
texpage = page
showpdf = 0
def pdfimg(): return pdfbase % (page,)
def globalkey(k):
global benchmark
global currentScene
if k == "d":
global dbg
dbg = not dbg
if k == "b":
benchmark=1
AbstractUpdateManager.setNoAnimation()
AbstractUpdateManager.chg()
def addpdftex(pap):
passno = pap.getNPasses()
# passno = 0
pap.setNPasses(passno + 1)
ppass = pap.getPass(passno)
global pdftex, texpage
if pdftex == None or page != texpage:
pdftex = getTex(pdfimg())
texpage = page
texid = pdftex.getTexId()
print "TEXID: ",texid
ppass.setSetupcode("""
PushAttrib ENABLE_BIT TEXTURE_BIT
ActiveTexture TEXTURE1
Disable TEXTURE_2D
ActiveTexture TEXTURE0
Enable BLEND
BlendFunc ZERO SRC_COLOR
Disable DEPTH_TEST
Color 1 1 1
SecondaryColorEXT 0 0 0
Enable TEXTURE_2D
Disable ALPHA_TEST
Disable REGISTER_COMBINERS_NV
BindTexture TEXTURE_2D %(texid)s
TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT
TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
""" % locals() )
ppass.setTeardowncode("""
PopAttrib
""")
ppass.setNTexGens(1)
ppass.putNormalTexGen(0, [.5,0,0,.25,
0,.5,0,.2,
0,0,1,0,
0,0,0,1])
def getfisheyepaper(seed):
pap = ThePaperMill().getPaper(seed)
global showpdf
if showpdf:
addpdftex(pap)
pfq = GLRen.createFisheyePaperQuad(pap, -1, -1, 1, 1, gridsize, gridsize, btype)
return pfq
bx = 600
by = 450
bs = .75
ba = 0
bl = 0
bm = 2
px, py = 625, 400
ps = 1
gridsize=16
btype=0
rng = java.util.Random()
benchmark = 0
def dobenchmark(w, vs):
global benchmark
if benchmark:
benchmark = 0
iters = 10
t = w.timeRender(vs, iters)
print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Time of", iters, "renders:", t, "s"
class FisheyeScene:
def __init__(self):
self.bgcolor = (1,1,1)
self.seed = 0
self.initpaper()
self.renderPaper = 1
def initpaper(self):
self.fpq = getfisheyepaper(self.seed);
def key(self, k):
global bx, by, bs, ba, bl, bm, px, py, ps, page
global gridsize, btype
if k == "Up": py += 50
elif k == "Down": py -= 50
elif k == "Left": px += 50
elif k == "Right": px -= 50
elif k == "Prior": page = max(1, page-1); self.initpaper()
elif k == "Next": page = min(10, page+1); self.initpaper()
elif k == "*": ps += .05
elif k == "/": ps -= .05
elif k == "e": by -= 100
elif k == "c": by += 100
elif k == "s": bx -= 100
elif k == "f": bx += 100
elif k == ",": px += 10
elif k == ".": px -= 10
elif k == "+": bs += .05; print "bs ", bs
elif k == "-": bs -= .05; print "bs ", bs
elif k == "a": ba += .2; print "ba ", ba
elif k == "A": ba -= .2; print "ba ", ba
elif k == "l": bl += .1; print "bl ", bl
elif k == "L": bl -= .1; print "bl ", bl
elif k == "m": bm += .5; print "bm ", bm
elif k == "M": bm -= .5; print "bm ", bm
elif k == "g": gridsize *= 2; print "gridsize", gridsize; self.initpaper()
elif k == "G": gridsize /= 2; print "gridsize", gridsize; self.initpaper()
elif k == "t": btype += 1; print "bulge type", btype; self.initpaper()
elif k == "T": btype -= 1; print "bulge type", btype; self.initpaper()
elif k == "v":
self.seed = rng.nextInt(2000000000)
self.initpaper()
AbstractUpdateManager.setNoAnimation()
elif k == "p":
global showpdf
showpdf = not showpdf
self.initpaper()
AbstractUpdateManager.setNoAnimation()
def scene(self, vs):
putnoc(vs, background(self.bgcolor))
cs1 = vs.coords.affineCoordsys(0, "1", 10, px, py, 400 * ps, 0, 0, 400 * ps)
cs2 = vs.coords.affineCoordsys(0, "2", 1.0/bm, bx, by,
400 * bs * math.exp(+bl) * math.cos(ba),
400 * bs * math.exp(+bl) * math.sin(ba),
400 * bs * math.exp(-bl) *-math.sin(ba),
400 * bs * math.exp(-bl) * math.cos(ba))
vs.map.put(self.fpq, cs1, cs2)
dobenchmark(w, vs)
currentScene = FisheyeScene()
See more files for this project here