Thursday, February 27, 2014

GitHub Pages for Existing Repository from Command Line

$ cd /path/to/repo

$ git checkout -b gh-pages

$ git branch --list
* gh-pages
$ cat > index.html

Test Page for GitHub Pages

$ git add index.html
$ git commit -m "changed header" index.html

$ git push origin gh-pages

In this example, my git username is codetricity. My git repository is swarm_gen2. The URL is

Wednesday, February 26, 2014

SGC GUI Example Showing Data Written to File

My son developed a new GUI example with SGC during today's lesson.  He built the application from start to finish in about an hour.

This version writes the selected data to a file.

The code is here.

Teaching Kids Programming in Japan

My friend Yasukawa Tatsuro had this to say about his experiences teaching kids to program in Japan.  There's some really good points in his short note.

I started to study programming with IDE not with Scratch or Blockly so I don't know if they feel frustrated about text based programming or CUI after getting used to GUI. For some part, it's true I guess. For programming, (for everything I guess) most important point is weather they are really into or not.
For teaching kids, I did rather played hour of code. It was so awesome. I could enjoy because it was like a game and I thought
it teaches programming concept well. Programming's most difficult part for beginner, I believe, is concept of programming. So starting from hour of code(blocky ) is good idea.  After that, you can teach kids how to draw a picture using `swampy`(I think you study `Think Python` so you know it !) then kids can understand how real program work. Also using Raspberry pi is good to teach `unix system` , CUI and programming( hardware hacking and it is fun for kids !).
 In my opinion, kids can start learning a programming if they know basic math like Geometry because after some points, they will stack with difficult problem which they cannot solve. For example, I taught 7 or 8 years kids but he stacked with geometrical problem.

Sunday, February 23, 2014

9 Year Old Girl's First Exposure to Python

I started my 9 year old daughter with my revised Python curriculum today.  The results were very good.  She was able to accomplish these tasks:

  • Create a graphic screen on Linux with usable exit, minimize and maximize window functions;
  • Use the PyCharm IDE with code completion;
  • Run the program and understand terminal output.
The basic concepts she's dealing with:
  • import python modules;
  • while loop;
  • for loop running through an event queue;
  • graphic surface creation;
  • graphic screen update.
The primary challenge right now is the physical skill of typing.  She's learning to type with a typing game program in parallel with learning the Python curriculum.  Children are different than adults and that their ability to manipulate a mouse and keyboard needs to be taken into account.  It's a big factor in their learning speed.  I think that teaching them piano may help with typing since they'll get used to using their fingers to hit keys in rapid succession using complex patterns.    

So far, it seems like a modern IDE like PyCharm or Komodo makes programming a lot easier for children.  Although I did teach her to use Scratch, I feel that I should have gone directly into Python with PyCharm or Komodo from age 8.  Scratch also has some challenges with using the mouse to manipulate the blocks.  The challenges of learning this physical skill are similar to using the keyboard to type letters into PyCharm.  

Surprisingly, her interest level is about the same with Python as it is with Scratch.  

I am also supportive of Scratch and Alice or Blockly.  With the rather weak state of programming teaching curriculums in primary and middle school in the US, I am supportive of any effort to teach kids to program.  These tools seem to work for many children.  I applaud them.  

My teaching experiments focus on Python with an IDE for children.  My concern with Scratch, Blockly and Alice is that kids need to make the jump from a graphical IDE to a text IDE at some point.  There's a range of problems that come up when they have to use a text IDE, the main challenge is frustration when they encounter a syntax or logic error.    I'm trying to see how far young children can get by going straight to Python and then bridging to other languages like JavaScript, HTML, Ruby, and Java.  

My theory is that the main thing that children need to learn is not actually about programming constructs such as loops or data structures.  My theory is that the main thing the child needs to learn is how to deal with frustration and ways to get beyond the frustration of errors.  In my opinion, the graphical approaches reduce the frustration too much.

My curriculum is designed only for two kids, my own children.  Other parents can use the curriculum if there's commitment to spend time with your child.   It's designed so that the parent is sitting right next to the child during the whole lesson.  For a 9 year old girl, this is about 30 minutes per class with one class every week, possibly less. 

I love to hear about other experiments to teach children to program.  

Wednesday, February 19, 2014

Collision Detection and Zombie Chase - Lesson 7 in the Beginner Series

New video in the seven lesson beginner series focuses on a way to get a monster to chase the girl.  An important point here is the use of colliderect to detect when two rectangles hit each other.  Collision detection of two or more rectangles is the fundamental of shooter games.

In this example, I use two graphics for the Zombie to allow him to run left and right when he's facing the appropriate direction.  Since I'm using the same rectangle for both graphics, I just have one colliderect check.


    if player_rect.colliderect(zombie_rect):

player_rect is the girl's rectangle.

The algorithm to chase the girl is shown below:
    # chase the girl
    if player_rect.centerx < zombie_rect.centerx:
        zombie_rect.centerx -= 1
        zombie_horiz = "left"
    elif player_rect.centerx > zombie_rect.centerx:
        zombie_rect.centerx += 1
        zombie_horiz = "right"
    if player_rect.centery < zombie_rect.centery:
        zombie_rect.centery -= 1
    elif player_rect.centery > zombie_rect.centery:
        zombie_rect.centery += 1

New to PyChildren, the drill-based Python learning curriculum for teenagers?  Check out the link below to get started learning Python from zero.

An eleven lesson video set is available.

Code repository on GitHub.

Download entire code repository as a Zipped file.

Monday, February 17, 2014

Using the Android Keyboard with Pygame

I modified the GUI example I posted on GitHub yesterday to include an example of using the Android software keyboard  for text input.

I had to build my own text box input since I couldn't get it to work with SGC.   There's still a few glitches with the keyboard and I don't suggest you use the code in a production application, but it should be suitable for my son's next class.

I'm sure there's an easier way to handle the text from the keyboard and I would love to see another person's code.  However, since the whole purpose of my project is to teach my son programming, it should be useful to teach him to build a text input box with the Android keyboard. 

This only works with individual keys right now and it won't work with Swype.

On the pgs4a forum, there was some question as to whether or not the soft keyboard actually worked.  I thought I would create a quick example to show that it does work.

Sunday, February 16, 2014

Best Python GUI for Pygame, pgs4a, Android Phones

Simple Game Code and Pygame

Three weeks ago, I wrote about testing PGU with Pygame.  After evaluating it yesterday, I gave up trying to get PGU to work on Android and moved to Sam Bull's Simple Game Code (SGC).  It may be possible, to get PGU to work, but I wasn't able to find anyone using it on Android when I searched through the pgs4a forums.

Sam Bull's code is nice and easy to use and I was able to get several nice menu widgets running on my test LG Optimus S Android phone within an hour.  There's extensive documentation the widgets drop right into a standard pygame code structure.

Radio buttons, switch, slider, and drop down

It's easy to connect the buttons to code to run things in your games.  For example, in the example above, the "Start" button will change the game level, which will run a different set of code.  The "Quit" button will exit the game.  The drop down menu and radio button work fine.

Easy to use text on Pygame surfaces

Running on LG Optimus S Android phone
I'll be doing additional experiments in the future.  In the meantime, I put my experiments for today up on GitHub.

If you end up using SGC on Android, I would be interested in hearing about it and seeing some code examples.

Everyone asks what the "best" library to use is.  It's going to be a matter of taste.  SGC on Android is the best for me and I thought I would share my opinion.   If you have a different opinion, I would like to learn about other GUI toolkits for Python/Android.

Update February 17, 2014
The blog Possibly Wrong has a description of getting PGU working with pgs4a.

I am having problems getting the software keyboard working with SGC InputBox.  I can't get the text to display properly inside of the text input box.  At this point, I'm still planning on using SGC unless I learn something more about PGU to make it worth digging into.