Code Monkey home page Code Monkey logo

graphics's Introduction

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

graphics's People

Contributors

olls avatar geraintwhite avatar bitdeli-chef avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.