Skip to content

Instantly share code, notes, and snippets.

@Michael0x2a
Created January 16, 2014 07:17
Show Gist options
  • Select an option

  • Save Michael0x2a/8450991 to your computer and use it in GitHub Desktop.

Select an option

Save Michael0x2a/8450991 to your computer and use it in GitHub Desktop.

Installation guide

Step 1: Download and install Python 2.7 (32 bit)

Download here:

http://python.org/ftp/python/2.7.6/python-2.7.6.msi

Accept all the default options.

Step 2: Add Python to your system path

  1. Open the systen environment variables
  • If you own Windows 8:
    1. Go to the start screen, and type "Edit the system environment variables".
    2. Click the option that appears
  • If you own a different Windows computer:
    1. Right-click on "My Computer"
    2. Click "Advanced System Settings" from the left.
  1. Click the "Environment Variables" in the bottom of the window

  2. Under "System Variables" look for the "path" variable. Click it to highlight it, and click the "Edit" button.

  3. At the very end, add the following:

    ;C:\Python27;C:\Python27\Scripts\

  4. Save and exit.

Step 3: Install easy_install

Download the following

http://peak.telecommunity.com/dist/ez_setup.py

  1. Open command line. (type 'cmd' in the "run" box from the start menu)

  2. Navigate to wherever you downloaded the file using the cd command. For example, if I saved the file under C:\Users\Michael\Downloads, then I would type:

    cd "C:\Users\Michael\Downloads"
    
  3. Run the following:

    python ez_install.py
    

Step 4: Install pip and other nifty libraries

Note: Make sure you're within the command line. You can execute the following set of lines from any folder

Type the following, one by one.

easy_install pip
pip install virtualenv
pip install future
pip install pylint
pip install radon
pip install pytest
pip install distribute
pip install yolk
pip install docopt
pip install requests

If any of these packages fails, note down the name, and move on to the next one.

Step 5: Install pygame

Download and install the following:

http://pygame.org/ftp/pygame-1.9.1.win32-py2.7.msi

Step 6: Test everything

Copy the following into a file called test.py. Navigate to it within the command line, and run python test.py. If everything went well, you should see a narrow window appear with a bunch of moving colored balls.

#!/usr/bin/env python

# Testing normal imports
import math
import random

# Testing pygame
import pygame

# Testing other imports (they're not used)
import future
import docopt
import requests

WIDTH = 400
HEIGHT = 600

def main():
    pygame.init()
    
    screen = pygame.display.set_mode([WIDTH, HEIGHT])
    
    balls = generate_random_balls(20)
        
    while True:
        screen.fill([0, 0, 0])  # Black
        
        for ball in balls:
            ball.move()
            ball.draw(screen)
        pygame.display.flip()
        
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            pygame.quit()
            break
            
def generate_random_balls(amount):
    balls = []
    for i in range(amount):
        x = random.randint(0, WIDTH)
        y = random.randint(0, HEIGHT)
        dx = random.randint(-2, 2)
        dy = random.randint(-2, 2)
        balls.append(Ball(x, y, dx, dy))
    return balls
            
def random_color():
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    return [r, g, b]
            
class Ball(object):
    def __init__(self, x, y, dx, dy):
        '''Creates a moving ball.'''
        self.x = x
        self.y = y
        self.dx = dx
        self.dy = dy
        self.color = random_color()
        
    def move(self):
        if not 0 < self.x < WIDTH:
            self.dx = -self.dx
        if not 0 < self.y < HEIGHT:
            self.dy = -self.dy
            
        self.x += self.dx
        self.y += self.dy
        
    def draw(self, screen):
        pygame.draw.circle(screen, self.color, [self.x, self.y], 5)
        
if __name__ == '__main__':
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment