[Edu-sig] Bitmaps in VPython

Joel Kahn jj2kk4 at yahoo.com
Tue Sep 7 23:44:39 CEST 2004


By using the attached script, in which a module from
the Python Imaging Library is combined with VPython,
you can display a bitmap image on a rectangular grid
of VPython objects. Once the basic image is in place,
of course, you can use VPython's strong capabilities
for animation &c to produce a wide variety of visual
effects. As I attempted to indicate in the script's
comment lines, I suggest starting out with rather
small bitmaps until you see what kind of results you
get on your particular hardware.

If anyone else has been experimenting with similar
algorithms, I would be interested in seeing their
work. This class of programs would seem to offer a
broad range of potential benefits for education and
lots of other areas. Email if you have questions.

Joel



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
-------------- next part --------------
# This program requires both
# the Python Imaging Library 
# and VPython.

import Image
from visual import *

# This program is designed for putting bitmap
# images into VPython; non-bitmap file types
# may require other approaches.

autocenter = 1

scene = display()
scene.width = 1024
scene.height = 738
scene.x = 0
scene.y = 0

Picture = Image.open ("bitmap.bmp")
# The preceding line is technically pseudocode;
# substitute the name of your own bitmap file (with
# appropriate path info &c) for the name "bitmap."
# For initial trials, stick to images with a
# resolution of 100 x 100 or less.

Pic_si = Picture.size
Pic_width = Pic_si[0]
Pic_height = Pic_si[1]

Pic = []

for xx in arange (Pic_width):
    for yy in arange (Pic_height):
        pxl = Picture.getpixel ((xx, yy))
        x2 = int (xx - Pic_width / 2)
        y2 = int (yy - Pic_height / 2)
        rr = pxl[0] / 256.0
        gg = pxl[1] / 256.0
        bb = pxl[2] / 256.0
        Pic = Pic + [box (pos = (x2, y2, 0.0), color = (rr, gg, bb))]

# Objects other than boxes should be just
# as usable and can produce a wide
# variety of visual effects.

Pic_Array = array (Pic)
lenn = len (Pic_Array)

# If your image initially appears upside down,
# use the following code to turn it right side up.

for aa in arange (lenn):
    Pic_Array[aa].rotate (angle = pi, axis = (0.0, 0.0, 1.0), origin = (0.0, 0.0, 1.0))


More information about the Edu-sig mailing list