Install Python

Python may already be installed.

For Windows, Python can be downloaded from here https://www.python.org/downloads/windows/. Typically the best one is Python 3 in Stable Releases and is 64-bit.

For Ubuntu, Python 3 is typically already installed. Ubuntu requires the "python3" command to run the software.

If you don't have it, it can be installed from www.python.org.

Install Packages

The first demonstration programs do not require installing packages.
Using Jupyter does not require installing packages.
Install pip using instructions here https://pip.pypa.io/en/stable/installing/

Install pygame

For Ubuntu, open a terminal and run:

    $ pip3 install python3-pygame
Or

    $ sudo apt-get install python3-pygame
Or follow the instructions here: www.pygame.org/wiki/GettingStarted

Install opencv

This is only required for programs in the image-proc folder.

For Ubuntu, open a terminal and run:


    $ pip3 install python3-opencv
Or

    $ sudo apt-get install python3-opencv
Or follow the instructions here: https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html
Or here: https://docs.opencv.org/master/d5/de5/tutorial_py_setup_in_windows.html

Open a Command Console or Terminal

For Ubuntu:

Running Programs

There are many ways to run the Python demo programs.

Python program can be run from the Idle program.

Python programs can be run from a terminal. First open a terminal, and then enter the text required to run the program. In the Demos documentation, the text to run is shown.

Another way is to right click on the file that you would like to edit and run, then select "Open With Other Application", then select "Idle". Then select "Run/Run Module" or the key F5.

The demo programs can also be run from Jupyter.

Editing Programs

Editing Python programs can be done with any text editor. The default Python editor is "Idle" and has colored text so that it is easier to read.

For Ubuntu: The menu Run/Run Module will run the program. The Python Shell may not show anything, but most demos will show a new window somewhere on the screen.

Solving Problems

Often searching on the internet will help to find out how to solve a problem. Other types of problems require debugging.

Debugging Programs

It is possible to debug Python programs by inserting statements into the program. Some examples are:
StatementDescription
print('1')This will print a "1" to the terminal when the print statement is run.
print(object)This will print the content values of an object or variable
print(dir(object))This will print the methods or members of an object or variable
print(type(object))This will print the type of an object or variable
print('place1', str(obj))This will print 'place1' and information about an object.

There are some Python editors that allow debugging. Search the internet for "Python IDE" to find different editors.

Grab a Screenshot (Image)

An image can be saved of the current screen or window.

For Ubuntu:

Grab a Screencast (Video)

A movie can be saved of the activities during some animation, or selections on the screen. For Ubuntu:

Edit Video with WinFF or ffmpeg

Install "WinFF" using Synaptic or command line. A video can also be edited in Gimp to change individual frames.

Cut and Crop

It seems like both Crop and changing the video size don't work at the same time. So load the already cropped video, and use the Video tab to set the output size.

Set Image Size

A complete example for the game/bug-data/Bug-Source/Bug.mp4 is:

Extract Frames

To extract frames, first open a terminal, and then run:

/usr/bin/ffmpeg -i "/dir/game/bug-data/Bug.mp4" /dir/game/bug-data/Bug/frame_%03d.png
The dir in italics must be replaced with your actual folder.