A maior rede de estudos do Brasil

Grátis
433 pág.
Apostila PyOpenGL

Pré-visualização | Página 2 de 50

Exercises ...................................................................................................320 
Chapter 9 3D and 3D Animation .................................................................322 
Section 9.1 Rotating Objects in Space...................................................322 
Exercises ...................................................................................................330 
Section 9.2 Real Time Interactive Computer Animator (RTICA) ............336 
The German Bell........................................................................................345 
Exercises ...................................................................................................350 
illiTorus ......................................................................................................353 
Exercises ...................................................................................................359 
Chapter 10 Animation and Display Lists .......................................................370 
Electron Orbitals ........................................................................................370 
The Quaternion Julia Set ...........................................................................375 
Alternate Quaternion Julia Set and Mandelbrot Set...................................381 
Chapter 11 Miscellaneous Programs ............................................................388 
The Random Walk .....................................................................................388 
The 3D Sierpinski Sponge .........................................................................391 
Rendering Teapots ....................................................................................393 
 4
A Midpoint Conjecture ...............................................................................397 
Fog ............................................................................................................405 
PyLorenz ...................................................................................................409 
Nate Robins and Multiview ........................................................................415 
Chapter 12 VPython....................................................................................421 
The Sphere................................................................................................421 
The Bouncing Ball......................................................................................421 
Bouncing Ball 2..........................................................................................423 
VPython Lorenz .........................................................................................424 
VPython Mandlebrot ..................................................................................426 
Index .................................................................................................................428 
 
 5
 
 
 
 
 
 
 
 
My heartfelt thanks to Professor George K. Francis 
 
 
Without his inspiration, interest, and mentoring, NONE of this would have 
been possible 
 
 6
Python Programming in OpenGL/GLUT 
 
Chapter 1 Introduction 
 
 Before we begin our journey with Python and OpenGL, we first need to go back 
in time. History serves many purposes, but one of its more important functions is to 
provide us with a reference point so that we may see how far we’ve traveled. We’ll go 
back to about 1980 and the first computer programming class in our high school. We 
were the proud “owners” of a single new Commodore VIC-20 and an old black and white 
TV that served as a monitor (almost). There were about 5 or 6 students in the class and 
we began to learn to program in BASIC.1 There were no graphics worth mentioning and 
the only thing I remember is that we made such a fuss about getting the VIC to find the 
prime numbers from 2 to 997. If memory serves, it took about 30 minutes for the VIC to 
run this “sophisticated”2 prime finding program. We had no disk storage and the memory 
in the computer was 4K.3 I think the processor speed was about 1 Mhz and might have 
been much lower4, but we didn’t care because we were computing! 
 
 The next step occurred the following year when we purchased 10 TI 99/4a 
computers for $50 each.5 They were not much better than the VIC-20, but we at least 
were able to store programs using cassette tape recorders. Cassette storage wasn’t 
much fun, extremely slow, and unreliable. I remember some slow, crude rudimentary 
graphics, but nothing that stands out in my mind. Finally, in 1982, things began to get 
exciting. We were able to purchase several Apple II+ computers with disk drives. We 
thought we were in heaven! The Apples were neat looking, nearly indestructible6, and 
much faster than anything we had used previously. Plus, they could actually produce 
usable GRAPHICS. Not just crude blocky stuff (which you could choose if you wanted… 
but why?), but nice points and lines on the screen! These Apples had 64K of memory 
(all you could ever use… or so we thought) and the disk storage was amazing. We 
could store 140K of programs on one floppy disk!7 Our prime number generator took 
only 53 seconds on the Apple, which was over 30 times faster than the VIC- 20. Had I 
been acquainted with my friend George Francis at that time, we would have been able to 
do even more with these dependable machines.8 
 
 Our final conversion was to the PC platform in 1987-88. We now had a lab of 12 
true-blue IBM PC’s with color monitors and hard drives running Windows 3.0 (or was it 
 
1 BASIC is a computer language… Beginner’s All-Purpose Symbolic Instruction Code. It has 
been much maligned over the years; unjustly in my opinion. 
2 Here, “sophisticated” means ‘brute strength and ignorance”. But the program worked and we 
were thrilled! 
3 This is 4 thousand bytes of memory. Compare this to my current laptop which has 2 BILLION 
(gigabytes) of memory. 
4 Again, my current laptop has a processor that runs at 2 Ghz, over 2000x faster! 
5 These were truly awful computers. Texas Instruments introduced them at a price of over $1000 
and ended up selling them at Wal-Mart for $49.95. I’m not certain they were worth that much. 
6 I personally saw one dropped on a concrete sidewalk. It bounced once or twice and worked fine 
for several years afterward. No, I wasn't the one who dropped it. 
7 Again, my trusty laptop has a 60 gigabyte hard drive. That’s 60 billion bytes. I also have a 
portable USB "diskless" drive that holds nearly 2000x the capacity of that Apple disk! 
8 UIUC Math Prof. George K. Francis had a lab of Apples then that did some amazing graphics 
with a 1983 Forth compiler written by one of his colleagues. It would have been nice to have that! 
 7
3.1?). By today’s standards, they were painfully slow, but at the time we thought that we 
were cutting edge. Memory was now in the megabyte range and processor speed was 
over 10 Mhz. I remember plotting Mandelbrot sets in less than 10 minutes, which was 
relatively fast for that era. We have steadily improved to our present lab setup of PC 
machines running nearly at 1 Ghz (or faster) with at least 128 mb of RAM (or more) and 
dedicated video cards for graphics.9 The computers in our labs are supercomputers 
compared to where we started! In fact, if we were to take the computer in front of you 
back to 1980, it would have been one of the fastest on the planet! 
 
 So this was a brief history of our high school computer lab. The programming 
class curriculum followed the lab, as you might guess. We would spend 3 quarters 
learning to program and then the 4th quarter was reserved for student projects. 
Invariably, once graphic capabilities were available,

Crie agora seu perfil grátis para visualizar sem restrições.