Skip to content

olls/graphics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Text Based Graphics Module

This is a console based python3 graphics engine for simple Unicode games or animations.

clock.py, terrain.py, road.py, input_example.py and circle.py are example programs using the module (Note: < and > are used instead of arrow keys.), also see grit96's Physics Engine and my Tetris game, which use this module.

terrain.py road.py clock.py

Installation

Install using setup.py:

python3 setup.py install

Or install from PyPI: pypi.python.org/pypi/graphics.

Usage

Simple usage example:

import graphics as g

# Create the canvas, 20x20 pixels (characters).
screen = g.Canvas(size = (20, 20))

# Create a circle image, radius 5 pixels.
circleImage = g.shapes.Circle(5)

# Create a green sprite at position (7, 7) with the circle image.
circleSprite = g.Sprite(circleImage,
                        position = (7, 7),
                        color = g.colors.GREEN)

# Add the sprite to the canvas.
screen.sprites.append(circleSprite)

# Output the canvas to the terminal.
print(screen)

# Increase the circles radius by two.
circleSprite.image.radius += 2

# Output the canvas to the terminal.
print(screen)

Compatibility

This module was written and tested with python3 on Debian with gnome-terminal. It should work with most Linux terminals, but some things might be off.

  • Colours should work if your terminal supports them, otherwise they won't cause any problems.
  • The input module supports Windows, Mac and Unix. Linux works fine and testing is in progress for Windows.
  • In the Windows CMD it doesn't centre properly, colours don't work, it was slow and input doesn't work.

console.py is a small script to determine the terminal size. Works in my gnome-terminal in Debian, probably wont work in all environment. It was modified from Stack Overflow.

colors.py has functions for adding the correct escapes to strings to color them, modified from a blog, also not sure about environment support.

nbinput.py an object to get non blocking input in the terminal, this only works in Linux terminals. This was modified from code.activestate.com.

Bitdeli Badge

About

A console based graphics engine for simple Unicode games and animations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages