Visit our site to listen to past episodes, support the show, join our community, and sign up for our mailing list.
Summary
Wouldn’t it be nice to be able to generate interactive 3D visualizations of physical systems in a declarative manner with Python? In this episode we spoke with Ruth Chabay and Bruce Sherwood about the VPython project which does just that. They tell us about how the use VPython in their classrooms, how the project got started, and the work they have done to bring it into the browser.
Brief Introduction
- Hello and welcome to Podcast.__init__, the podcast about Python and the people who make it great.
- Subscribe on iTunes, Stitcher, TuneIn or RSS
- Follow us on Twitter or Google+
- Give us feedback! Leave a review on iTunes, Tweet to us, send us an email or leave us a message on Google+
- Join our community! Visit discourse.pythonpodcast.com for your opportunity to find out about upcoming guests, suggest questions, and propose show ideas.
- I would like to thank everyone who has donated to the show. Your contributions help us make the show sustainable. For details on how to support the show you can visit our site at pythonpodcast.com
- Linode is sponsoring us this week. Check them out at linode.com/podcastinit and get a $20 credit to try out their fast and reliable Linux virtual servers for your next project
- I would also like to thank Hired, a job marketplace for developers and designers, for sponsoring this episode of Podcast.__init__. Use the link hired.com/podcastinit to double your signing bonus.
- Your hosts as usual are Tobias Macey and Chris Patti
- Today we are interviewing Ruth Chabay and Bruce Sherwood about their work on VPython
Interview
- Introductions
- How did you get introduced to Python? – Chris
- What is VPython and how did it get started? – Tobias
- What problems inspired you to create VPython? – Chris
- How do you design an API that allows for such powerful 3D visualization while still making it accessible to students who are focusing on learning new concepts in mathematics and physics so that they don’t get overwhelmed by the tool? – Tobias
- I know many schools have embraced the open curriculum idea, have any of your physics courses using VPython been made available to the non matriculating public? – Chris
- How does VPython perform its rendering? If you were to reimplement it would you do anything differently? – Tobias
- One of the remarkable points about VPython is its ability to execute the simulations in a browser environment. Can you explain the technologies involved to make that work? – Tobias
- Given the real-time rendering capabilities in VPython I’m sure that performance is a core concern for the project. What are some of the methods that are used to ensure an appropriate level of speed and does the cross-platform nature of the package pose any additional challenges? – Tobias
- How does collision detection work in VPython, and does it handle more complex assemblies of component objects? – Chris
- Can you talk a little bit about VPython’s design, and perhaps walk us through how a simple scene is rendered, say the results of the sphere() call? – Chris
Keep In Touch
Picks
- Tobias
- Land of Lisp by Conrad Barsky M.D.
- Chris
- Bruce
- Ruth
Links
The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA
Hello, and welcome to podcast.onit, the podcast about Python and the people who make it great. You can subscribe to our show on Itunes, Stitcher, or TuneIn Radio, or add our RSS feed to your podcatcher of choice. You can also follow us on Twitter or Google plus, and please give us feedback. You can leave a review on iTunes to help other people find the show, send us a tweet or an email, leave us a message on Google plus or our show notes. And you can also join our community. Visitdiscourse.pythonpodcast.com for your opportunity to find out about upcoming guests, suggest questions, and propose show ideas.
I would like to thank everyone who has donated to the show. Your contributions help us make the show sustainable. For details on how to support the show, you can visit our site at python podcast.com. Linode is sponsoring us this week. You can check them out at linode dotcom/podcastinnit and get a $20 credit to try out their fast and reliable Linux virtual servers for your next project. I would also like to thank Hired, a job marketplace for developers and designers, for sponsoring this episode of podcast.init. Use the link hired.com/podcastinit to double your signing bonus.
Your hosts, as usual, are Tobias Macy and Chris Patti. And today, we're interviewing Ruth Chabay and Bruce Sherwood about their work on v Python. So could you each introduce yourselves, please? How about you first, Ruth?
[00:01:28] Unknown:
Hi. I'm Ruth Chabay. I'm a professor emeritus of physics at North Carolina State University. I'm particularly interested in integrating computational modeling into all of the science and technological curriculum at the undergraduate level, especially physics since that's my field and that's how I got involved with Python.
[00:01:47] Unknown:
My name is Bruce Sherwood. I'm professor emeritus from North Carolina State University. I share our essentials. Together we've developed a curriculum for the introductory physics course and we'll have more to say about that. That includes computation. Both of us have been involved with computers for many decades, and we look forward to talking with you all.
[00:02:11] Unknown:
So how did you folks get introduced to Python?
[00:02:16] Unknown:
We were at Carnegie Mellon in the 19 nineties, and it was, I think, just in the air there. There was a lot of interest in it. For example, Randy Pausch's Alice project where students got to use import models, fancy models and new animations was based on Python. We loved it because of its clean structure, its gentle learning curve, and decided it was a a really good first programming language. And its modular structure, meant that it was easily extendable, so we could add modules that did what we needed to do.
[00:02:50] Unknown:
And so you mentioned that you created v Python. So what is v Python, and how did you guys get that started?
[00:02:59] Unknown:
Well, v Python stands for visual plus Python. That is Python plus a module which was called visual. And it's an environment that lets ordinary mortals generate navigable real time 3 d animations as a side effect of computational models. And it's also included in the original classic package was a modified version of idled. It was originally the idea of David Scherer when he was an undergraduate at Carnegie Mellon. He had been in our introductory physics course where Ruth had introduced some computational modeling, And he saw a way to do it in 3 d, which sounded very exciting.
And he chose Python as the foundation because of its extensibility, its object orientation, its simplicity, its clarity. During the, spring semester of 2000, he and we worked together to design what became d Python. He did all of the coding, all of the implementation. We spent most of every day together thinking through the design, how to make it work well for people who may not have ever written a computer program before or being asked to generate programs that made 3 d animations.
[00:04:25] Unknown:
So what problems inspired you to create v Python?
[00:04:29] Unknown:
It really was originally a side effect of of trying to bring introductory physics courses into the 21st century, which is harder than it sounds. Most introductory physics courses are completely happy to stop around 18 60 or sometimes even 1700. So most introductory physics courses don't admit that the 20th century ever happened. A part of that was was introducing computational modeling so that students would have a chance to see, fundamental physics principles in action and to explore the range of possible behavior instead of settling for the the 2 problems that are easily solvable with introductory calculus, so constant acceleration or simple harmonic motion.
A problem with that, though, was that most college freshmen, Carnegie Mellon was an exception, but most college freshmen actually have essentially no programming experience. They're really good with computers, but they've almost never written a program. So if we wanted them to actually write models themselves without any black boxes, we needed a language, that environment that was clean, that was easy to learn, and that we could make look very much like the algebraic expressions that we're using on paper. We also really felt strongly that we needed interactive 3 d animations so students could observe how their models behave, observe the behavior of the system. You could see planets going around stars, or you could see springs oscillating in weird patterns and not just look at graphs.
[00:06:06] Unknown:
Have you noticed, have you noticed that the students are more engaged after introducing this tool to the classroom the the prior than they were prior to being able to interact more viscerally with the principles that they're trying to understand in the figs in the physics course?
[00:06:23] Unknown:
I think it really depends on the students and the context. Some of them absolutely are. Others see it as an extra burden of something else to learn until they do something that's really cool. And then they see a really interesting strange orbit involving 3 objects, which is something they never could calculate by hand, or if they see their mass on a spring going around in strange wobbly circles, then then they start to get interested.
[00:06:51] Unknown:
That's that's really very cool. I know I certainly would have probably been much more motivated to struggle through intro to physics than I was if there had been something like this involved. So I can definitely see myself finding more motivation, more sort of connection with the material. I I think what you said about, you know, your standard intro to physics course stopping in the 1700 is totally fascinating, and I and I sort of wonder sometimes about that aspect of academics, you know, like like, how many other subjects are there where even just sort of conceptualizing things in a different way would really help students connect with them better?
[00:07:39] Unknown:
It it's an interesting question. 1 of the things that's that our students can do is make computational models not only in big macroscopic systems, but actually on the microscopic level, they can connect masses and springs and model solid objects, which are actually modeled in many ways very well as a network of masses and springs. So they can see they can actually see and sort of experience how things react at a microscopic level. For example, if you put a heavy book on a table, it looks like the table is not changing. So how can it be exerting an upward force? But you can actually see the network of balls and springs that comprise the solid table being compressed by the weight of the book if you could model it at the microscopic level. So there are there are a lot of different kinds of insights you can get from thinking about things this way and from from, using computational technology to support making and exploring these physical models.
[00:08:40] Unknown:
As you were saying earlier, the fact that there is this extra tool that you're introducing into the classroom at the same time as all of these new physical and mathematical principles. How do you design an API that allows for such powerful 3 d visualization while still making it accessible to students who are tackling those new concepts in mathematics and physics so that they don't get overwhelmed by the tool?
[00:09:03] Unknown:
Well, that's an important question, and it's a big issue because, of course, students have a lot to learn anyway, and so overloading them is a really bad idea. A a lot of care did go into the design of the API, And 1 of the most important things are intelligent defaults. If if you've done any work in 3 d and any kind of 3 d system, you may know you may realize that the most common thing that happens is you get a black screen because you've forgotten to point lights at the object or or the camera's pointing in the completely the wrong direction or or something like that. So it's frustrating.
So v Python starts out making sure that you will see any object you create. And if you don't specify any special parameters, it'll occur in some default location and be lit and the camera will point at it. And that's helpful. There's the the syntax, like all Python syntax, is very clean. We don't have to contend with missing semicolons or unmatched curly braces, which is also a big help. And in the Python, we tried the students can actually do vector it supports vector algebra. So you can do vector algebra as you would on paper by adding vectors and operator overloading make that possible, of course. So what they write in in code matches to a significant extent what they would write algebraically on paper. So the translation is a little less complicated.
I have to say though that it's it's not just the API. You actually need to surround it with the curriculum and not overwhelm students to start out with. So it's it's really important to to stress a very, very small number of key computational concepts that'll let you do what you need to do, and then introduce them slowly, step by step in the context of physics activities so that students get a chance to master them a little bit at a time instead of telling them to go off and model the solar system as their first homework assignment.
[00:11:11] Unknown:
In fact, just today, we got an email from a colleague at a liberal arts college who said, oh, it's going so much better this year. In the past, he's new there, colleagues there that developed materials, curriculum materials that way overloaded the student. There was way too much stuff, and the kinder, gentler curriculum materials we've provided together with this nice API makes a huge difference. So the details do matter. And it's and we've had 15 years of experience refining this approach. So it's And Ruth and her graduate students at, NC State did a lot of work to make those curriculum materials better and more workable.
I have to quote Ruth on 1 thing. Ruth had a wonderful saying, every brace is an opportunity for an error.
[00:12:08] Unknown:
I I love that. I think that's I think that's very true. And as any of us who who who started up, you know, learning how to program with something like Java or even, you know, worse, something like c or Pearl or something like that. You we we've felt that pain.
[00:12:26] Unknown:
Indeed. And still do with JavaScript and other languages.
[00:12:32] Unknown:
So, I know many schools have embraced the open curriculum idea. Have any of your, physics courses using v Python been made available to the non matriculating public?
[00:12:44] Unknown:
In fact, a colleague of ours, Mike Schatz at Georgia Tech, ran through Coursera, a MOOC that was an in introductory physics course that used our materials and also had used the Python. And they had the students doing significant modeling projects, Some of which would involve students going out with their cell phones and taking a video of some motion and then coming back and digitizing it with tracker and then writing a d Python program to model the motion and try to to unravel it. And it was, like, 10, 000 students. Well, it yes. Yes. Like all these groups, it started out with many thousands of students. But, but the students were pretty enthusiastic about it. And some of the videos they made reporting on their projects were really very impressive. So that ran for a couple semesters, and I think was a very successful thing.
[00:13:34] Unknown:
Very cool. I hope we can get I think I found it. But just, just in case I didn't, I'll, I'll pass it your way, and hopefully, we can get the verified link in our show notes because I think that would be really neat for people to take a look at.
[00:13:50] Unknown:
It but I think it's no longer running. I don't think it's running at the moment, but it it It required way too much work. Well, every requires a lot of work from the instructor. But I don't know if it's gonna be offered again, but it did happen. And it was it was a pretty good experience, I think.
[00:14:08] Unknown:
So how does v Python perform its rendering? And if were to reimplement it, would you do anything differently?
[00:14:18] Unknown:
Well, that that is a timely question because as we wrote to you earlier, there's a group of us who are deeply involved in the process of restructuring what was the classic version of e Python for a bunch of reasons. What we're calling classic e Python, which started in 2000, and it's still in use quite widely around the world, Used Open GL, CPU based, did not exploit the GPU, certainly could not exploit the modern browser. So, essentially, all we were asking graphics card to do was to draw triangles and just didn't exploit modern hardware nor modern software, namely a browser environment. So what we're engaged in doing, in a way, we're 0.87% of the way there, 87%, is 2, kinds 2 implementations of the v Python syntax that will supersede the classic version.
1 is called Goloscriptvpython, available at goloscript.org. That's glowscript.org. And the other is Jupyter epython, which runs in a Jupyter notebook in the IPython architecture. And the glow script version, to run-in a browser where the your program is both compiled and executed in the browser, not not on the server, which just sends you libraries. The Ghostscript version is possible because of the rapid script compiler that would transpire that would go from Python to JavaScript, the language of the browser. And that plus GPU code does what it needs to do. It's necessarily limited in terms of the Python ecology because you can't import an arbitrary Python module.
And so but this is a very suitable environment for beginners, for the introductory physics course in our case. And then there is the Jupyter version. Jupyter Notebooks are now increasingly popular among professional computer people. Computer scientists, computational science really love that environment. And so that's sort of the professional choice. We don't consider to be a very good place to put a novice student who's never programmed before because it is a sophisticated environment. So we're in the process now of rethinking the implementation and having these 2 kinds, 1 for the novice, the casual programmer, and 1 for the professional.
[00:17:04] Unknown:
The both of those environments, the new ones use the glow script rendering engine, which makes very good use of GPUs and graphics cards, which have improved a lot since 2000. So that it's possible to do pretty sophisticated rendering. We can write for text shaders and fragment shaders and and have a lot of that. The computational load of the rendering is almost all done by the GPUs. And that's a big win. And that's that's possible in the browsers using WebGL, which is moderately new, but allows 1 to access the the capabilities of the graphics card within the browser context. And for example, we're able to do pixel level
[00:17:45] Unknown:
correct transparency, which is not easy to do, and it's essentially impossible with a CPU based renderer like the standard OpenGL. Well, that's the old OpenGL. The new OpenGL will do that.
[00:18:03] Unknown:
I think that's that's really great. Have I know WebGL for a very long time was really heavily browser dependent and, you know, like, you'd see a WebGL demo when it would say requires Chrome or Firefox of this or that version to run, has it gotten better such that you can actually write and and and, you know, publish a WebGL based application and have it work with reasonable degree of certainty on most of the major browsers?
[00:18:32] Unknown:
All the browsers now supported, including Edge. Every everybody does. But it's that's a recent thing. It it's it's really in the past year or so almost that all the browsers have stepped up and and now really do support WebGL.
[00:18:46] Unknown:
And in the Jupyter case, when you you run your Python program on typically a local server, it could be remote, but typically a local server, you run your standard Python program, Then the output is piped over to a browser, a browser of your choice, which is where the Jupyter Notebook is rendered with its cells of code, images, equations, whatever. But now also, a v Python rendering there using the goscript GPU renderer so that you have 3 d animations, navigable 3 d animations of the cell in a Jupyter notebook.
[00:19:26] Unknown:
And you're mentioning that your newer versions include vertex shading and pixel level transparency. So is that something that you've had to develop, you know, to to have you have you had to hand develop that specifically, or are you using libraries for being able to do those, those graphical computations?
[00:19:45] Unknown:
No. We wrote the shaders. They're it's, we're doing some things that aren't entirely standard with using the GPU, and it was it was essential that we write our own.
[00:20:04] Unknown:
And is that a difficult undertaking, or is it something that's fairly standard and low, low requirement? Personally, I've never done anything like that, so it sounds pretty difficult. But
[00:20:18] Unknown:
Well, the the initial the learning curve is steep. Okay? So you have to learn the shader language and you have to have a model. You have to learn a model of how the GPU actually works, including some hardware operations that you don't have control over. And so there's there's a fair amount to learn, but once you learn it, then it's not that it's not that bad. You learn a new language. You you spend a lot of time thinking about geometry, really a lot of time thinking about geometry. And you have to think about the GPU hardware. But it's kind of it was kind of interesting. It's not something 1 would ask a student to do.
[00:21:00] Unknown:
So 1 of the remarkable points about v Python is the fact that it does have the ability to execute the simulations in the browser environment like you mentioned. So I'm wondering if you can dig a little deeper into the technologies that are involved there to make that work.
[00:21:16] Unknown:
Sure. The the key thing is that the Go script piece of this, which is also exploited in the Jupyter notebook, it's all JavaScript code plus the GLSL language for writing the vertex and fragment sheaters. Fragment sheaters, and the communication between them. Basically, the the structure is this. There are a bunch of so called primitives, box, sphere, ring, cone, etcetera. There when the program starts up, there are stored into GPU memory so called models for each of those things. That is, the data that says a box has these, 8 vertexes.
There are normals to the the faces. Here are the triangles that are gonna be drawn by the GPU because that's what it draws, these triangles. And so those are the generic structures. It's the generic description of your platonic ideal of of a cube. And then at you in your user program, you say box, left parens, right parens. And what that does is make an instance of the box class. And at render time, the data corresponding with that instance is all that's sent to the GPU, which then refers to the model of a cube and performs things like stretching it to not be cube, changing the color, rotating it in some position, locating it in 3 d space with a projection 2 d onto your screen.
All that happens in the shaders in the GPU. The amount of data for 1 instance of a box, or any of these other models is quite small. It's 5 4 vectors of float 60 fours for a total of only a 160 bytes. So you have a very large number of instances of box objects, and all you're sending the GPU each time you go to render is these 160 byte quantities. The rendering is done about 60 times a second so that you have good looking animation. Obviously, if you really load that with lots and lots of computation, that frame rate will necessarily suffer.
But computation and rendering, all are made. The the way we're able to use Python, which doesn't run-in a browser, is, as I mentioned earlier, there's a rapid script transpiler, which will convert Python to JavaScript and and then compile the JavaScript. And all that is actually done in the browser. The compiler is is written in in JavaScript. It's not exactly perfect Python. For example, the creators, the main creators, Alexander Sephkov, reasoned that while in Python, division by 0 throws an error and division by 0 JavaScript just produces an infinity. If you were to try to mimic Python exactly, you would have to put in tests on every division operation to see whether the divisor was 0 or not. And that's just a simple example of a more general principle.
So there are many projects attempting to transpile Python to JavaScript. But RabbitScript is particularly has this particular goal of saying, we're gonna do a pretty good job of mimicking Python, but it won't be absolutely correct at the tip level. So But it will be fast. And it'll be fast. In fact, basically, these programs are just as fast as any JavaScript program. I don't see any difference in the the Python programs rather than the browser and the JavaScript ones. Now in the Jupyter case, the situation is rather different. Typically, you've got a local browser sorry, a local server running on your system where you're running true Python, true standard Python with full access to the huge ecology of of Python modules.
There the the the server communicates with the browser. Very similar to you going to google.com, and there's a server, and it sends stuff to your browser and displays it. Well, in this case, this local server sends stuff to a local browser on your machine. And what does it send? Well, in the simplest case, if you write print 3+5, it says an 8 over there. It shows up in the in the notebook that you're running in the browser. And this notebook looks sort of like a back like, mathematical notebook or a Sage notebook, that kind of a thing. And what John Cody invented was that he he did 2 very interesting things.
He wrote a pure Python version implementation of the v Python API. Now that means that it's not as fast as the original classic c plus plus code, but it's fast enough to get going. And here we hope later on when we get things most of the API done is to go look and using Sciphon or other tool to speed up the hot spots. But already the performance is pretty decent. So that was 1 thing he did, which was that was really good. The second thing he did was he mastered the the Jupyter notebook environment and figured out how to send this output of of changes to this box. Okay? You change the position.
So he sends that change information over to the browser. He has a JavaScript program that picks up that data and calls the glow script liberms to change the position attribute of this box instance. And the net effect is that the box on your screen moved. And so the chain is Python in a bra in a server, a JavaScript program running in a browser, calling it by the Goldstrip libraries with their GPU usage to actually make the presentation in a notebook cell. And the performance is actually quite good.
[00:27:54] Unknown:
Yeah. So given the real time rendering capabilities in v Python, like you said, performance is a pretty big concern for the project. And you mentioned some of the ways in which you're tackling that. I'm wondering if there are any other techniques that you have implemented or are planning to implement that will help ensure an appropriate level of speed. And I'm wondering also if the cross platform nature of the package poses any additional challenges to that work.
[00:28:19] Unknown:
Well, given that you're running in a browser, the cross platform problem is much simpler than it was 16 years ago when you needed very specific code to to do graphics on all the different platforms. That was hard. A lot of the cross platform stuff is now taken care of by browsers, which have to be sure to run on all platforms. And, and since there is now WebGL support in the all the major browsers, it that's made the cross platform problem almost not quite, but almost a non problem. And in fact, the glow script versions,
[00:29:02] Unknown:
actually run-in a mobile devices. You can actually write and run v Python programs on your smartphone. I didn't expect to live long enough to see that.
[00:29:13] Unknown:
So our students can take their phones home and show their parents what they did in physics class, which is sort of cool. The the original classic was written in c plus plus for speed, and and we're just not doing that anymore. That's too challenging, and that ends up being very platform dependent. You need a a binary for every platform. The, in the glow script v Python environment, the almost Python environment, Since we're going down to JavaScript, that's pretty JavaScript is pretty fast. And I think this is a a moving target. Stay tuned. Maybe Witherspend will be even faster or something. But but the performance is is typically
[00:29:59] Unknown:
good enough. In fact, I'll interject that in pure Python, for loops have a large overgen. And so it's important to vectorize things and use NumPy. Our experience so far in the browser world, in the Ghostscript version in Python, is that because the the JavaScript for loops don't have a high overhead, we actually sort of don't need NumPy for that most basic reason for using NumPy. JavaScript is actually a pretty fast language.
[00:30:31] Unknown:
In, in the Jupyter environment, which is still really in beta, although it's it's usable by, anyone who wants to try it. We are the performance isn't bad, actually. It's surprisingly good for having the basic implementation of the the core API and pure Python. But And the communications. Yeah. And and then all the communications using JSON strings between Python and and JavaScript. So it's it's it's sort of miraculous that it runs as well as it does in my opinion. But it's not bad. But we will once we get everything about the API nailed down. Then the next project is to start looking at how we could speed it up. And it's possible that Cython will will help us in some key areas, maybe making vector operations siphonized or whatnot.
But it's actually usable now. In fact, colleagues including both instructors and professional physics researchers are actually using this beta environment very happily.
[00:31:32] Unknown:
How does collision detection work in v Python? And does it handle more complex assemblies of com of component objects?
[00:31:39] Unknown:
Basically, there there there is no collision detection built into v Python. In fact, there's no physics built into v Python. It's basically a neutral platform. What it's what it does know is it knows about vectors. It can add and subtract them. It can multiply them by constants, divide them by constants. There's a whole bunch of vector methods pertaining dot products, cross patterns. All that kind of stuff is built in. And with operator overload, you could say a plus b instead of a dot and left parens, b right parens. So it's it's good at facilitating your vector calculations. You can actually do vector calculations with vectors, which by the way is kind of a first for physics students because although vectors ostensibly play a big role, this is the first environment where students or faculty for that matter have been able to use vectors as vectors rather than separately as components.
I digress. So then there's no physics building either. Our students are experiencing no black boxes. They are actually writing the physics calculations themselves. And if they wanna detect collisions, they're gonna have to look at the the distance between the centers of 2 spheres and see if that distance is less than the diameter of these spheres and do something if they need to do that. So it's not a physics engine. You could certainly, use you could import a physics engine to to do this stuff, But in the educational sphere, that's not what we're after. And we didn't wanna build into the Python anything other than this sort of minimal capability of being able to render things in 3 d, to be able to navigate through the scene, I am to be able to do it with vector calculations.
[00:33:35] Unknown:
That's that's really that's really interesting. I guess I guess I had just assumed because of what I was seeing, the kinds of simulations that I was seeing that the that v Python had some kind of object boundary detection and collision detection built in. But in a sense, I can see what you're saying, not having that built in means that it it becomes it's wide open for even more sort of flexibility and and and, and and more broadly, more more types of applications can be built with it.
[00:34:12] Unknown:
Yeah. There aren't any constraints, so that you could do various things. But but the goal was not was was to make a a general purpose programming environment that that knew about living in a three-dimensional world and could really, enable the user to to use vectors which describe living in 3 dimensions easily and fluently, and then let the user build the models.
[00:34:42] Unknown:
And in fact, in a certain sense, it's neutral. You can use it for whatever you want it is it for. Maybe you wanna use it to render something that a physics engine calculates for you, or maybe you wanna use it to present
[00:34:56] Unknown:
chemistry molecules as balls as the states. Or maybe you're doing topology or something. It's
[00:35:02] Unknown:
it's a It's an engine, but not a physics engine. It's a rendering engine.
[00:35:09] Unknown:
That's great. It just struck me as as you folks were were talking about this, given that given that my sort of conception of v Python was a little bit off kilter, it it occurred to me, Has anyone used it in the in the sort of genre of creating 3 d computational art?
[00:35:30] Unknown:
There's certainly things people do that are very beautiful. We don't know everything that everybody does. We know that there have been, you know, 100 of thousands of downloads, but we don't know what people are doing with it.
[00:35:46] Unknown:
Right. I think I think that's becoming a theme for me. We've certainly discussed it in a couple of other podcasts. You know, for all of us who use open source software every day, you know, take some time to send some love back to your project maintainers even if it's just a note saying, hey, I built this cool thing or even, hey, I really love your project. I think I think we all sort of owe that to this amazing ecosystem, you know, on whose should the individual project maintainers whose shoulders we we build things on every day. So can you talk a little bit about VPython's design and perhaps walk us through how a simple scene is rendered, say the results of the sphere call?
[00:36:29] Unknown:
When did you first say something about this design principles? I mean, you know, I'll follow the box through the system.
[00:36:39] Unknown:
Well, 1 of the things we wanted so as I mentioned alluded to earlier, 1 of the things we thought was important was to make it easy for the programmer to create an object of the the shape and size and surface properties or whatever that they actually want at the right location. And to make that very easy to do, the first piece is just, not requiring them to do that at all. So if you just said box or sphere with no arguments at all, you get a box or a sphere at the origin with, size of 1 and and lights pointing at it and a camera pointing at it. So that that part would be easy. But then make it easy to to specify other parameters. So different length and width and height for a box and the axis pointing in some direction or whatnot.
And those are just those look like just they look like standard Python objects with standard Python attribute syntax. So you can say box axis equals vector 3 1 minus 1 or something like that to specify it.
[00:37:57] Unknown:
So let's let's follow a box to the system. Suppose you've written this this gigantic program that consists of box, left parens, right parens. And I'm gonna take the glow script version of v Python just for concreteness. And because so the the Jupyter version is is just an extension of using this machinery. So as as we said earlier, on setup, we get the model of a box and sphere and so on over the GPU memory so that thereafter we can just give instance information. The instance information for the box or the sphere or the cone or the pyramid or the whatever It involves the following attributes, a position, which is a 3 d vector, a color, which is actually a 3 d vector also. The size, length, width, height is a 3 d vector.
An axis, again, a 3 d vector about the direction. At this this the default is 100, mainly x direction, but you could be have it be something else. How shiny it should be, how what its opacity should be. And, and by default, and you can also specify a texture and even a bump map to go with the texture. So this is this package of of a 160 bytes. It represents that, instance of the class box, which is what was made. You made b o x left brands, right brands. But as Ruth said, having created this object box, that causes the Ghostscript machinery also to create a WebGL canvas and display it in the browser. And then put the box in the in the that scene with the the camera pointed in the right direction and right distance away so that the box sort of fills the the canvas.
It also turns on mouse interactions to let you rotate and zoom this, the camera to look at the scene from different places and all. So 1 way of saying this is, oh, and and the cube will be white. It'll be oriented along the x axis, all these things by default because when we said box, left brands, right brands, we didn't say anything else in that constructor. We could have included in there, for example, color equals cyan or length equals 5 instead of 1. But so very intelligent defaults. You get something going with almost nothing. Just this 1, 2, 3, 4, 5 character program.
Now that's not the interesting part in some ways because what's really cool is you let's say you write a while loop. And that's we we we teach our students at the intro level 1 way to make a loop, namely a wild loop. And it's typically wild true as it has an infinite loop actually. And the next statement in that while loop is typically rate 50. Don't do more than 50 iterations of this loop per second because you have to control the speed of the animation to be independent of how fast your particular computer happens to be. And then what you might have is your next statement is let's say you call say you the program actually said ball equals box.
By default, its initial position will be 0, the origin, etcetera of the canvas. If in your loop, you write box dotpos, which is ball. Sorry. Ball, the instance of the box cast. Ball dotpos equals ball dot POS plus a vector that might be a short displacement in the northwest direction. And now you run this program, and I've described the whole program. Wild shrimp rate 50, ball dot position equals the existing ball dot position plus a vector of minus 110. If you run that program, what you'll see is a box moving off in the northwest direction.
Even though in that loop, there are no obvious graphic statements at all. You're just recalculating the position of this object. But that restatement not only clamps the execution to no more than 50 iterations per second, But when the time comes right, every 60th of a second, it drives the GPU machinery to make a new display on the canvas using the current attributes of the objects, in this case,
[00:42:52] Unknown:
a box named ball. I think Bruce lives in an alternate reality where Raw balls are cute. Yeah. Raw balls are cute. Right?
[00:43:00] Unknown:
So anybody that doesn't care, it'll it'll let you call a sphere call it Cuba a ball. So the effect is you did an animation, a 3 d animation with no obvious graphic statements there at all. I mean, compare with what you're doing 3 JS or something, and it's just off scale different. So it's literally the case that your physics calculations, your calculations of repeated changes to position attribute of the ball instance of box class will give you a 3 d animation that's navigable with mouse controls. And and that was David Scherer's great insight. He he was a he was and is an extremely powerful programmer, but he was interested in the problem of how could you make 3 d animation programming accessible to ordinary mortals. And his ingenious solution was do it for them. Make it be a side effect.
If they change the position, we should show the position we should show the thing in a different place. So it's very cool.
[00:44:10] Unknown:
Under the hood, there's a fair amount going on. Suppose you have a scene with a 100 different boxes in them at different locations, and they're all rotating or bouncing up and down or something like that. 60 times a second, the the scene gets rerendered. And in each case, because you have a mod this model of a cube is a box is stored in the GPU. What the vertex shader does is say, oh, I see that this object is an instance of this model. So all I'll do is I'll take this model, and I'll just do transformations to locate its center at the right place and orient its axis off in the right direction and maybe stretch it if it's larger or compress it if it's smaller.
But that that calculation is all done by the GPU, by the vertex shader in the GPU. And, and it does and it says, and, okay, given where the camera is exactly, what would you be seeing of this box on the screen? Is it completely hidden, or are you gonna see 1 corner, or are you gonna see the whole thing at what angle?
[00:45:22] Unknown:
And Is it transparent?
[00:45:24] Unknown:
Yeah. But so the and the the fragment shader goes well. Now I have to worry about where the lights are and if there's something if it's transparent, what's behind it that I'm gonna see and what color it is and maybe there's a texture on it. But all of that stuff is is all of that really computational intensive stuff is now done in the GPU, which is really good at it and does a lot of it in parallel. So it's doing this computation pixel by pixel, but lots of them at once, which is why it can be fast.
[00:45:59] Unknown:
And in fact, in terms of performance, it's it's it's sort of a special case in a way, but, I took it as a challenge. I had something like 10, 000 boxes all swirling around. It it was slightly a trick. 1 of the interesting objects is a compound object where you take a bunch of objects of this and you compound them, And now you can treat it as 1 object. As soon as 10, 000 boxes is actually 1 object being hurting.
[00:46:31] Unknown:
You know, it it's really interesting hearing you folks talk about this. I I just wanted to say, I'm a logo programmer from way back, and my my version of logo was Atari logo, which just gets to show you how old I am. And, that version of logo had Dyna Turtles exactly, where you could actually animate the turtle and move it around the screen. And and and it's interesting because as I was playing with v Python in preparation for making the show today, I had that kind of feeling of, you know, like, just being able to with really simple programmatic statements, box, sphere, etcetera, etcetera, I was able to pop 3 d objects up all over the screen at my at you know, to do my bidding. And I I really 1 of the things that that occurred to me as I was sitting there playing with this is, wow, if I can, you know, manage to get the 5 seconds to rub together, I think it would be really cool to write a a 3 d squirrel using cubes with this thing, because anybody who remembers logo remembers that squirrels were always 1 of the the big examples they taught you how to how to make. So it's really nifty that you folks thought through making this giving this the immediacy, you know what I mean, of you can type simple invocations and get simple but really satisfying results that look good and that look like what you think they should look like immediately. I think that kind of the quick positive feedback is so critical for driving adoption in technology.
[00:48:05] Unknown:
I think box, left parens, right parens, is a lot nicer way to start learning about how to write computer programs than printing hello world.
[00:48:15] Unknown:
Yeah. It's definitely a much more visceral and impactful experience than just seeing a computer print something out to the screen, and it's also a lot more impressive, particularly for people who have become used to the, capabilities of modern computers. And, you know, may maybe 30 years ago, Hello World was a was a novelty and, you know, worth calling somebody over to take a look at. But these days, it's, yeah, what whatever.
[00:48:42] Unknown:
Not not so exciting right now. Right. Yeah. That's a big piece of it. It's it's visually you can make something fairly easily that's visually engaging and and, and it actually can be visually engaging on its own or because it's the output of a scientific model that you've created. So you're actually seeing how is a real how your model of a system would behave, and you're able to compare it to the behavior of a real system.
[00:49:12] Unknown:
Actually, it strikes me talk since you were talking also about the integration between v Python and and Jupyter Notebook, I would think that v Python could be a really nifty data visualization tool. Right? I was thinking in terms of using some of these primitives to make some really effective and mind blowingly, cool looking graphs for some of your datasets. That could be really neat.
[00:49:37] Unknown:
Yeah. And not just and I think some some of our colleagues who are computational physicists actually do use it for that. An interesting thing about it is that you can go beyond graphs and do volume representations or the fact that you can do it easily in 3 d, I think, is is a big plus and that it that it can be dynamic.
[00:49:59] Unknown:
And then you can run-in your friend's phone when you send them a link. Well, some of these things might not run on my phone.
[00:50:07] Unknown:
I I suppose it depends on if you've got the latest and greatest phone. And if not, then, tell tell them to go out and upgrade.
[00:50:16] Unknown:
I have to say though, I share I share your enthusiasm for the fact, you know, those of us who are old enough to remember when computers were something that, you know, you loaded the data off cassettes and it took, you know, half an hour or 40 minutes to to get anything going, having this device that you can pull out of your pocket or out of your book bag that is totally self contained and has the ability to create, you know, eye popping 3 d visualizations interactively, that's like that's miraculous. Actually, talking about this and and Jupyter Notebook and things like that, it it makes me hearken back to a, a cartoon that was popular when I was a kid, Tennessee Tuxedo with mister Whoopi and his 3 d blackboard, 3 d BB.
That's that's kinda what I think of these days because it's it's you can, you know, these these tablets, you can do so much with. I mean, the computational power in these things is is mind boggling. And and for those of us who remember, it's it's it's all the more miraculous.
[00:51:22] Unknown:
Yeah. I started out with punch cards and teletype output. So so it's we've come a long ways. And it and it's and it's great. I mean, this is so much more interesting, and it's so you can see the results of what you're thinking so rapidly
[00:51:41] Unknown:
and it and change it and try it again. So exploration of model spaces is so much easier. A very small comment, which you might wanna delete because it's not that important, but I'll just mention that the Ghostscript version of vpythons had an interesting important impact, in that often in in many kinds of educational settings, especially pre college, the IT department will not install Python on school computers because it's open source and that's known to be very dangerous. Well, they actually sort of can't not let you use browsers. And so some some people interested in our work who are teaching at high school level or even earlier, were very pleased that they can write and run v Python programs on their Chromebooks, which the schools have and are very inexpensive, whereas they could never possibly actually use standard Python.
[00:52:41] Unknown:
The fact that there's nothing to install for the glow scope version also means that the the barrier to getting started is very low.
[00:52:51] Unknown:
Absolutely. I mean, when you think about sort of walking a computer novice through and things like Anaconda make it an awful lot easier, but walking them through the process of installing Python and all the necessary dependencies, having something that's browser accessible makes all the difference in the world. Absolutely.
[00:53:12] Unknown:
Absolutely. It it really lowers the barrier to getting started.
[00:53:17] Unknown:
So is there anything that we didn't cover that you think we should have or anything else that you wanna bring up before we move on?
[00:53:25] Unknown:
I don't think so. You ask good questions.
[00:53:27] Unknown:
Thank you. Appreciate that. We try. For anybody who wants to keep in touch with you guys or follow what you're up to, what would be the best way for them to do that?
[00:53:37] Unknown:
Well, there are there there's the v Python forum. There's a Google forum. There's also a glu glow script forum at the moment for historical reasons. Probably those 2 forums in the not distant future will merge into 1, the Python forum. So that's that's a good place to go. We'll give you our our picks are gonna be URL's to our work. Okay. Both physics and and computers. So that those offer contact mechanisms also. Okay. A lot of our the the major projects, the classic the classic v Python, Ghostscript v Python, and Jupyter v Python are all in GitHub, of course.
[00:54:24] Unknown:
Alright. Well, I guess, with that, we'll move it on to the picks then. So I'll start us off. And for my pick today, I'm going to choose a book that I just started reading a couple of days ago on the train, called Land of Lisp, and it's actually very enjoyable. The author does a really good job of introducing a lot of humor to the narrative to keep you interested in learning some of the principles of lisp, and there are a lot of very amusing illustrations throughout. So it's a much different take on a technical book than I've read in a while, and I've been thoroughly enjoying it. It, really makes it flow a lot better than some of the more dry technical treatises that I've read recently. So definitely recommend checking that out for anybody who has even a tangential interest in LISP.
And with that, I will pass it to you, Chris.
[00:55:16] Unknown:
For my first pick this week, I'm gonna pick a TV show. The Syfy channel, as I mentioned in the previous pick, after producing, like, nothing but utter dreck since they were pretty much since they, you know, came on the air, has all of a sudden somehow gotten a budget or or a clue or something, because they've produced not 1, but 2 shows that I really like. I already picked the first 1 in a previous week, The Expanse, and this week, I'm gonna pick another 1 called The Magicians. I was really once again very surprised at this. I was expecting it to be really horrific, quite frankly, but it wasn't.
They seem to really have actually, you know, spent some money on special effects, and the writing is is pretty good. It's it's entertaining. It's interesting, and I definitely am looking forward to seeing more. My next pick is Swift, the Apple programming language for, writing iOS and and Mac OS X applications. I just wanna pick the language itself because I have always found objective c to be kind of intimidating. I'll admit it. I I mean, I've used c and c plus plus in the past, and and they they you know, I I can do it, but it's not necessarily my favorite place to live. And Swift is just at a level of abstraction that my brain is more comfortable sort of living in, and I've really kind of appreciated that and it's allowed me to sort of make inroads into building, iOS and Mac OS X applications, which is great because I've been a, you know, an enormous Apple fanboy for for years years as Tobias can attest. We've had a number of Linux Mac conversations.
So, yeah, I'm definitely loving that. And for my 3rd and final pick, I am going to pick, Atari Logo. I realize this is kind of a silly thing to pick because it's a retro, you know, tool that nobody in their right mind these days would use unless they are sort of, you know, people who've used it in the past. But I really this programming language and programming visual programming environment is really what inspired me to to get a career in computer science. You know, it's for all the reasons that we discussed, being able to create a turtle that looks, you know, and change its appearance to a spaceship or, you know, whatever because that's that's where I was at at that particular point in time, and have it fly around the screen and and, you know, collide with and detect those collisions with other sprites, all using a really high level language that's really, really accessible was a a, mind expanding, discovery for me at the time.
And I think it's wonderful that, you know, certain some aspects of modern technology like v Python have embraced that kind of, you know, enable enabling that enable that kind of interactive exploration and positive feedback loop. And I'll stop there for this week. Bruce, what kind of picks do you have for us?
[00:58:26] Unknown:
We have 3. Okay. Me. Alright. Fine. Me. Vpython.org, vpyth0n.org. That's the sort of mother ship of original classic dpythontot, but now has links to other pieces. Atglowscript.org. It's glowscript. It stands silly by meaning graphics library on web. Glowscript.org, that's the whole place where you can register and write programs that are saved for you in the cloud. You can run them there, debug them there, export them to your own web page, or or give a link to that spot in an email address to somebody and they can click on it, they're running your program. And then there is, wanna do this 1?
[00:59:29] Unknown:
Well, I have 2. If you're interested in our our physics work or even just seeing some a lot of physics demonstration programs written in the Python, matter and interactions, all 1 word, dot org. So matter and interactions dot org slash student will take you to a bunch of demo programs written in the Python, both from mechanics involving spaceships and balls and springs and also electricity It's a It's a very interesting contemporary incarnation of logo that lets that that's used by people exploring exploring complex systems.
It's a it's another great first first language for kids learning to program, and it lets you take lots and lots of interactive things and see see patterns emerge from simple rules. So that's a very cool contemporary incarnation of logo.
[01:00:30] Unknown:
I I have actually. I I've looked at NetLogo and I and I played with it quite a bit, and I I have to admit, I and I'm totally guilty of this. I sort of got into it and thought to myself, oh, it's gonna have dino turtles and maybe we'll do the same thing as they used to do with the entire logo. And it's kind of not built for that. It's built for something totally different and even more awesome as you say, these sort of creating these complex systems with all kinds of interacting, you know, objects going on, but it it it kind of it it's it's a different awesome thing that I really should definitely definitely spend some time to dig into.
I I have not yet, though, because I like I say, I'm guilty of sort of looking at it, playing with it, it not doing what I had hoped it would do and bouncing off. So I I will definitely invest some more time in that. Thank you for the suggestion. And, for anybody who's not aware, I'm sure that, you all are aware of it, but there's also an and and and there is an implementation of logo in the Python standard library. So if you import turtle,
[01:01:34] Unknown:
then you can actually write logo programming you you can write logo programs in Python.
[01:01:41] Unknown:
Well, turtle programs. Yes. Sorry.
[01:01:47] Unknown:
Yep. Yeah. So if you import turtle, then you can use your turtle to draw on the screen.
[01:01:53] Unknown:
Cool.
[01:01:56] Unknown:
Well, I appreciate you both taking the time out of your day to join us and tell us more about bPython. It's definitely a very interesting project. And after learning some more about it, I'm probably gonna start using it as a way to get my children introduced to programming. I started using the turtle module a little bit, but this seems like it might be an even better environment for experimentation and, teaching them about Python. So thank you for that.
[01:02:22] Unknown:
Let us know how that goes. A lot of people have done that with their kids and with with good success. So Alright. Thank you for having us. Yes. Thank you very much for taking time to talk with us.
Introduction and Podcast Information
Meet the Guests: Ruth Chabay and Bruce Sherwood
Introduction to vPython
Challenges in Teaching Physics with Computational Tools
Designing an Accessible API for Students
Evolution and Modernization of vPython
Technologies Behind vPython's Browser Execution
Performance and Cross-Platform Challenges
Collision Detection and Physics in vPython
Rendering a Simple Scene in vPython
Educational Impact and Accessibility
Closing Remarks and Contact Information