At 07:27 PM 10/24/2004, you wrote:
> 1. RE: Bitmap Rendering (Joel Kahn)
>--__--__--
>
>Message: 1
>Date: Sun, 24 Oct 2004 03:12:44 -0700 (PDT)
>From: Joel Kahn <jj...@ya...>
>To: vis...@li...
>Subject: [Visualpython-users] RE: Bitmap Rendering
>
>Bruce Peterson described a method of using a screen
>capture utility from the Image Library to grab a
>series of frames that can be later hooked up to make
>an animation. I'm wondering if anyone has available
>any actual code implementing what he laid out. With my
>still-limited knowledge, I'm not sure how well I could
>put it all together just from Bruce's prose; I need to
>know more about exactly which commands to use and how
>to use them. Plus, of course, we all want to avoid
>wheel re-invention when we can. :-)
>
>Joel
Joel
I've attached some sample code using the VPython ball bounce example. A
number of items are hard coded in -- like the directories -- that you may
wish to change before testing it.
=========================code begins ===========================
import win32gui
import Image
from visual import *
from os.path import *
def animate_something():
strTitle="Demo Screen Capture"
strSaveFile="C:/temp/capfile.jpg"
demoscr=display(title=strTitle,width=800, height=600)
demoscr.select()
blnQuit=False
blnCapture=False
framecount=0
side = 4.0
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk
wallR = box (pos=( side, 0, 0), length=thk,
height=s2, width=s3, color = color.red)
wallL = box (pos=(-side, 0, 0), length=thk,
height=s2, width=s3, color = color.red)
wallB = box (pos=(0, -side, 0), length=s3, height=thk,
width=s3, color = color.blue)
wallT = box (pos=(0, side, 0), length=s3, height=thk,
width=s3, color = color.blue)
wallBK = box(pos=(0, 0, -side), length=s2, height=s2, width=thk,
color = (0.7,0.7,0.7))
ball = sphere (color = color.green, radius = 0.4)
ball.mass = 1.0
ball.p = vector (-0.15, -0.23, +0.27)
side = side - thk*0.5 - ball.radius
dt = 0.5
t=0.0
while not blnQuit:
if demoscr.kb.keys:
ukey=demoscr.kb.getkey()
if ukey=='Q':
blnQuit=True
elif ukey=='C':
blnCapture=not blnCapture
t = t + dt
ball.pos = ball.pos + ball.p*(dt/ball.mass)
if not (side > ball.x > -side):
ball.p.x = -ball.p.x
if not (side > ball.y > -side):
ball.p.y = -ball.p.y
if not (side > ball.z > -side):
ball.p.z = -ball.p.z
if blnCapture:
rate(1)
framecount+=1
my_scrndump(strTitle,demoscr,strSaveFile,framecount)
rate(99)
demoscr.visible=False
def my_scrndump(wintitle,actdisplay,svfile,frmno):
try:
# built-in driver (1.1.3 and later)
grabber = Image.core.grabscreen
except AttributeError:
return None
winhndl=win32gui.FindWindow("wglWindowC",wintitle)
scrntuple=win32gui.GetWindowRect(winhndl)
actdisplay.select()
imsize,imdata=grabber()
imtmp=Image.fromstring("RGB",imsize,imdata,"raw","BGR",(imsize[0]*3+3)
& -4,-1)
imtmp=imtmp.crop(scrntuple)
fntmp=svfile
## print "base name for file ",fntmp
fndir=dirname(fntmp)
fnbase=basename(fntmp)[:-4]
fntype=basename(fntmp)[-4:]
fncount=str('%06i' % frmno)
fn=fndir + '/' + fnbase +fncount + fntype
## print fn
try:
imtmp.save(fn)
except:
fn=fn[:-3]+"Jpeg"
imtmp.save(fn)
return None
if __name__=='__main__':
animate_something()
===============================code ends =========================
Bruce Peterson
425 466 7344
|