ProgrammedMe : Python Teaching Aid for Kids Part 1 - Using Panda3D to Create Working POC

 

From this starting Panda Tutorial, we can create a great Python teaching aid for the kids!

Figure 1 - From this Panda Tutorial, we can create an attractive Python teaching aid for the kids

To be honest, I failed in my first CoderDojo opening. Sigh.. that's the sad truth.

Yeah, the kids got excited about seeing that they can calculate area of triangle and print the result. Yeiy! But.. what's next? I kinda feeling dumb trying to explain those marvelous Python concept using just a plain black BASH console. I know I really love console (or DOS Prompt to be exact). But as I remember it, at that time of my early introduction to computer programming (circa '95) , there are not much left to explore other than console application. Thinking it further,  it's not the console actually that get me excited. But its the game! I love programming because I love seeing I can programmed .. Digger using QuickBasic.

Now, realizing that, I start to think what Python tools I can use to get children excited in computer programming. Looking at python folder, I see.. turtle.py! Yeiy. It's the infamous Turtle Logo Programming! This seems promising.

But after working through some of its tutorial,  well, I don't think it will attract my young padawan either. Yes, it can draw lines, create great graphics and the kids can even see their computer marvelously draw cute circles on the computer. But.. its the year of two thousands! In the age where kids play 3D game using their touch capable devices such as a premium Galaxy Tab or iPad, how can I attract them to love .. drawing plain circles. Gosh, I kinda frustrate there... 

But from frustration there come ... inventions! From Turtle Logo concept, I know that somehow I need to get children directly saw their codes translated into some kind of great visualization. I need to find a more attractive visualization for it. Hence, come ProgrammedMe initative.  

ProgrammedMe Project

If you have a look at ProgrammedMe project page on CodePlex, you will see that my initial idea was to build an interactive pixel-art isometric world. And indeed that was my first attempt. But I suddenly realize that I need a dedicated pixel-art artist for that. Previously I had a colleague who would like to test his ability by drawing a pixel-art stock image at first. But eventually after creating one Rombong Bakso pixel-art stock image, he confess that it's a time consuming activity. He gave up and strike for another real job. Leaving me in the darkness. Not sure where to go..

.. well, not really Sealed

The Search for a Suitable Python Library/Framework

I began widening my project specification beyond just pixel-art isometric world and seeking other means to create a working Proof of Concept application for ProgrammedMe project. Using Cocos2d is a priority at first, but as I stumbled across using Python 3.3 with Cocos2D, I kept looking and finally (not sure how) .. I ended up in Panda3D project page. What caught my attention at first is, it already use Python as its language. Although developer can use C++, but Python is the main concern here. This makes my technical difficulty in trying to bring Python interactive scripting environment to the kids were cut in half. Panda3D is ready for me to be use in ProgrammedMe project. 

Sure, it will not be a retro Pixel-Art style visualization as what I first intended it to be, but it will be a 3D environment in which kids in this era already familiar enough. Hence, it maybe a better approach. 

The Core Concept

Actually, the concept of ProgrammedMe is very simple, here goes:

  1. From Python Turtle Graphics, take out that plain white background turtle drawing environment,
  2. .. replace  it with a nice 2D/3D environment,
  3. .. instead of arrow head, lets replace it with a cool 2D/3D actor,
  4. .. add a text editor where kids can type Python code to programmed the actor, and,
  5. .. upon hitting ENTER/pressing execute button, kids can see their actor walking, running, turning or other unlimited interactivity that you can think of!

Figure-2 below is a plain Python Turtle Grapics. Try to compare it with Figure-1 where a virtual 3D environment is being rendered in real time showing Panda walking with camera circling its movement. I am sure at first glance, kids will more intrigued by the Panda and not that one-pixel width black line! 

Plain python turtle drawing environment

Plain python turtle drawing environment

 

 

Take a Test Drive!

Got to say, I quite satisfied with the current release of ProgrammedMe project. And it's not just me. My daughter too. Have a look at my short video capturing initial test drive of the project with my daughter below: 

If you want to test it, you can go to download area and download an appropriate release for your operating system. To follow along its development (and hence, having the latest update), I suggest that you forked the project from ProgrammedMe website. After you have installed ProgrammedMe appropriately and running it, you will be presented with a virtual 3D environment with a nice Panda standing still, as depicted in Figure-1. You can type any one line Python command in the Python Interactive Environment window, but surely only command that being made to interact with Panda and its 3D world is the one that will get kids excited, as follow:

Python Interactive Environment being made by Tkinter

Python Interactive Environment being made by Tkinter

  1. walk() also accept an integer argument to indicate how far the Panda will walk. Defaulted to 1.
  2. left(), right() also accept a real argument to indicate how many degrees does the Panda will turn. Defaulted to 90.
  3. follow(), unfollow() to move along the camera with Panda movement.
  4. rollcam() together with follow() will make your Panda gain a much better camera tracking experience!
  5. stop() to stop Panda from walking.
  6. playmusic(), stopmusic() you can play background music too!

You can find the definition of those methods in file engine.py. As this is the first release of ProgrammedMe, I only manage to stuffed basic movement command so that you can get the idea of what further feature can be implemented. 

Or, maybe currently you are asking, "What if I want to create a longer script to further enhanced ProgrammedMe?". Try to press the r key in your keyboard. Now your window will display a some kind of monster jumping continuously. Any further movement command will affect this monster, not our Panda. 

More interactivity!

More interactivity!

The r key will call engine.Engine.readScript() which will read script.py from the current directory. Currently, this is the content of script.py (you can modify into anything Panda3D understand):

1
2
3
4
5
self.panda=Actor()
self.panda.loadModel('models/dancer')
self.panda.reparentTo(render)
self.panda.loadAnims({'walk':'models/dancer'})
self.panda.loop('walk')

 

It will bring dynamic interactivity into ProgrammedMe, which means you can add interactivity any time you want. As for me, I intended this feature to be the mean to create series of programming course that you can load anytime from within ProgrammedMe. Imagine being instructed to grab that Banana using a single jump. In which when you grab that banana (using Python code), you will have a 100 score!

That's the idea Cool

Working With Source Code

To easily use ProgrammedMe, instead of downloading a large installer, I suggest you do the following:

  1. Download Panda3D SDK. In Windows, it equipped with Python 2.7 already configured to use Panda3D
  2. Install Git in your system, and clone ProgrammedMe repository using the command : git clone https://git01.codeplex.com/programmedme
  3. If you use Windows, you can open ProgrammedMe.sln, which is a Visual Studio 2012 PTVS project and start working on the code. Hit F5 to run the application.
  4. Of if you are on OSX/*nix, to run the application you can simply execute python main.py.

Future Features and Special Notes

I think it's too early to write future features/wishlist now. This release is just a mere of Proof of Concept application. My focus is on getting my daughter to love programming, and by that, all future features will designed toward her likeness. Well, maybe eventually I will designed a girlie environment.... Tongue out 

As the time of this writing, ProgrammedMe won't work in OSX. The main reason is the Python Interactive Environment still using Tkinter, which unfortunately having a lot of trouble when running with multiple thread application such as Panda3D. As the thread implementation differ from OS to OS, the current solution work flawlessly in Windows 7, but the case is not in OSX Mountain Lion. I will have further refine the solution though.





Leave comments

 authimage

Copyright(c) 2014 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved