Skip to main content

No project description provided

Project description

ASCII_PyGraphics

This is a python library for easy graphics in the terminal. See the example.py file of GitHub for an example with lots of comments

How To Use

Setup

  1. Download from pip with pip install ASCII-PyGraphics
  2. import with from ASCII_PyGraphics import * or import ASCII_PyGraphics as graphics

Boxes

Everything that can be displayed on screen is a box. Boxes have a plate (initial appearence), size, and position when first created. There are 4 main things that you can do with boxes: display, move, add them onto eachother, and update.

Creating Boxes

Box is a class. It has one required argument and three optional ones: size, pos, fill, and custom_pattern.

size

This is the only required argument for the Box class. It takes a tuple of two integers in the form of (x_width, y_height). The box instance will be this size.

pos

The position of the box class. It takes a tuple of two integers or floats (floats will be rounded when used) in the form of (x_pos, y_pos). The default value is (0, 0).

fill

How the box's plate will appear. It takes a string and will raise ValueError if it is not an fill option. Allowed values are ['box', 'rounded box', 'lines', 'grid', 'solid fill', 'solid empty', 'custom'].

custom_pattern

If fill = 'custom' then custom_pattern will be used. This takes a multiline string and turns it into the plate of the box instance. It is important to note that the size value must be equal to or larger than the size of the string. Otherwise a ValueError is raised.

Methods

draw(self, other_box, from_scratch=True)

Put the plate of other_box onto the plate of the calling object. If from_scratch is set to False this will have the same effect as draw_next

draw_next(self, other_box)

Put the plate of other_box onto the face of the calling object. The difference between draw and draw_next is that draw effectively clears all previous changes to the face. draw_next keeps previous cahnges.

move(self, x, y)

Change the pos value by x and y. It is important to note that the positive direction is down and to the right.

collide(self, other_box)

Returns True if the two boxes are overlapping at all.

Display

This is increadibly easy. Every time you want to render the box onto the screen, simply put it in the print fuction. print(Box(5, 5))

Important for Understanding

There are three important variables in the Box class. plate, face, and pos.

plate

plate is the basic "look" of a box. This is assighned upon creation and is never changed. It is affected using the fill and custom_pattern arguments. Under the hood this is a numpy array of characters.

face

This is the dynamic appearence of a box. It can be modified using the draw and draw_next methods. face is also a numpy array of values and is derived from the plate. The difference is that face is what is rendered when the instance is printed.

pos

A simple tuple that holds the sprites position. This can be changed with the move method. It dictates where the other_box goes when drawing.

User Input

This uses the pynput library to handle input from the keyboard. Some computers may complain about security. The solution to this is left asan excersise to the user.

pressed_keys is a set that contains all curently pressed keys. They are stored as strings such as 'a', 'B', '5', ')', 'up', 'esc', and 'enter'.

"Extra" Stuff

The tick(FPS), init() and qquit() functions.

init()

Clears the screen to prepare for displaying/ init also starts the keyboard_listener.

qquit()

Stops the keyboard listener and calls quit() Doesn't do anything else as of now.

It is only called qquit becuase quit was taken.

tick(FPS)

Pauses the program until enough time has passed to satisfy the FPS requirement. If the program takes longer than the necessary time thsi function does nothing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ASCII_PyGraphics-1.0.4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

ASCII_PyGraphics-1.0.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ASCII_PyGraphics-1.0.4.tar.gz.

File metadata

  • Download URL: ASCII_PyGraphics-1.0.4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for ASCII_PyGraphics-1.0.4.tar.gz
Algorithm Hash digest
SHA256 94d9ded7f714c629d0fd5ec3c9f5ec7710aa3b06af6279276dd2f0aab8df95a0
MD5 16c9fd0c0961c376df757c54ce5dd181
BLAKE2b-256 69582390be88119c4e890f1dc29b54571f72fe8b324f70e9dff7748d9435c2a6

See more details on using hashes here.

File details

Details for the file ASCII_PyGraphics-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ASCII_PyGraphics-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 373856ae216637ecba85e5794f6b99ceebe436bf29a66d102ef7c8a4153a89fc
MD5 88d9a0e135df87ac09fd11cd5c86412a
BLAKE2b-256 f3d78318565be6abaad2c335bdbdac43dec927744f703e7c6da81f59ece89def

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page