Glyph-graph - A simple, yet versatile, package for graphing equations on a 2-dimensional text canvas

Overview

Glyth Graph

Revision for 0.01

A simple, yet versatile, package for graphing equations on a 2-dimensional text canvas

List of contents:

  1. Brief Introduction
  2. Process Overview
  3. Technical Overview
  4. Function Glossary
  5. Code Example
  6. Legal (MIT license)

Brief Introduction


Glyth Graph is an open-source python package, for graphing equations onto a 2-dimensional array (named the canvas) with a variety of arguments to draw within a specific range and bound. Scaling to the width and height of the canvas in proportion

.

Process Overview


glyth_graph_basic():

Upon attaching the constructor to an object a 2D array with the declared resolution size will be filled with the chosen blank_glyth, named the canvas.

draw_graph():

  1. Check whether the given char_x (x-axis position of the canvas) is within the bounds of the canvas width as stated in the resolution.
  2. If not formatted the equation will be simplified into an expression without 'y', '=' and any spaces.
  3. If not given the y-axis bounds for the equation within the x-axis range will be calculated by repetedly incrementing the x variable.
  4. Then an x variable will be calculated by mapping the char_x from the width to the x-axis range of the equation, equally distributing each increment of char_x in the x-axis.
  5. The x variable will be substitued into the equation to form a y-axis value, which will be mapped from the y-axis bounds of the equation to the canvas height.
  6. Finally, the 2D coordinate of the char_x and char_y value on the canvas will be replaced by the chosen glyth.

Technical Overview


The package operates on mapping values between the x and f(x) from the graph equation to the given resolution of the canvas, translating coordinates with a non-uniform scaling factor to draw a glyth by a 2D index.


Notation form of the equation for mapping charx to x


x-axis Value Equation


where rangefrom and rangeto are respectively the given x-axis region of the equation to draw.



Notation form of the equation for mapping f(x), equal to y, to chary


y-axis Canvas Index Equation


where max and min are respectively the calculated (or given) maximum and minimum y-axis values for the equation within the x-axis region.

Function Glossary


graph_basic(resolution: str, blank_glyth: str = None) -> None

The constructor of the class to create an attached object, setup the canvas array with the arguements given, both the size and blank (background) glyth

 - resolution: the width by the height of the canvas measured in character glyths | 'x'.join([width, height])
 - blank_glyth: the background glyth used for spacing the graph

format_equation(equation: str) -> str

Format the graph equation such that all unecessary characters are removed to be processed, this includes removal of 'y' and '=' if given an equation to form an expression and all ' ' (spaces) present

- equation: the mathematical equation of the graph going to be drawn

y_bounds(self, equation: str, x_range: tuple) -> tuple

Calculate the upper and lower bounds in the y-axis of a graph equation between the given x-axis range, to be used later for mapping positions

- equation: the mathematical equation of the graph going to be drawn
- x_range: a tuple of the x-axis range between which the graph will be used, all outside this is unnecessary

draw_graph(char_x: int, equation: str, glyth: str, x_range: tuple, y_bounds: tuple = None) -> list:

Draw a glyth onto the canvas array dependent on given arguments in relation to the graph equation, including the x-axis range and y-axis bounds of the 2-dimensional section of the graph and character position along the canvas

- char_x: the x_axis glyth position of the canvas, such that it starts to the leftmost position (0) to the rightmost (canvas width - 1) | 0 <= char_x < canvas width
- equation: the mathematical equation of the graph going to be drawn
- glyth: the character/s to be drawn onto the canvas at the calculated coordinate relative to the graph equation
- x_range: a tuple of the x-axis range between which the graph will be used, all outside this is unnecessary | (range_from, range_to)
- y_bounds: a tuple of the y-axis bounds for the x-axis region of the graph, including both the minimum and maximum values | (min, max)

clear_canvas() -> None:

Clear the canvas by replacing all indicies in the array with the blank glyth assigned in the constructor, removing any graphs drawn

print_canvas(clear: bool = None) -> None:

Pretty print the canvas array into equal rows of the set width with newline character moving to the next row, as each index is printed incrementally

- clear: a boolean value (either True or False) whether to clear the each canvas array index after printing the index | True or False

Code Example


A simple code example showing the usage of all functions in the package, with the user inputting variables to produce the wanted graph/s onto the canvas array as random Base64 character glyths:

from glyth_graph import graph_basic
from random import choice

character_set = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'

print('---Glyth Graph---')

print('\n---Resolution---')
width = int(input('Width (chars): '))
height = int(input('Height (chars): '))

glyth_graph = graph_basic(
    resolution = 'x'.join([str(width), str(height)]),
    blank_glyth = '  '
)

while True:
    print('\n---Graph Properties---')
    equation = glyth_graph.format_equation(input('Equation: '))
    range_from, range_to = int(input('x-axis From: ')), int(input('x-axis To: '))
    print()

    bounds = glyth_graph.y_bounds(
        equation = equation,
        x_range = (range_from, range_to)
    )

    for char_x in range(0, width):
        glyth_graph.draw_graph(
            char_x = char_x,
            equation = equation,
            glyth = choice(character_set),
            x_range = (range_from, range_to),
            y_bounds = bounds
        )

    glyth_graph.print_canvas()


An example of an output to the program, which can vary with custom values for all given inputs, pretty printing the canvas array:

---Glyth Graph---

---Resolution---
Width (chars): 100
Height (chars): 30

Width: 100 | Height: 30

---Graph Properties---
Equation: y = math.sin(x)
x-axis From: 0
x-axis To: 6.283185

                     LbvwLB+K
                  Rp8        49D
                MB              FgW
              Kt                   O
            i6                      +w
           t                          f
          z                            LZ
        k7                               q
       9                                  q
      Y                                    G
     3                                      yP
    r                                         c
   9                                           h
  C                                             4
 f                                               K
l                                                 M                                               oe
                                                   o                                             7
                                                    y                                           n
                                                     O                                         e
                                                      tf                                      0
                                                        M                                    u
                                                         r                                  O
                                                          I                               lv
                                                           o8                            w
                                                             L                          A
                                                              Q2                      uO
                                                                w                   LD
                                                                 zvu              8x
                                                                    nGl        xMw
                                                                       XsohPTDx


License (MIT)



Permissions Conditions Limitations
Commercial use License and copyright notice Liability
Distribution Warranty
Modification
Private use
MIT License

Copyright (c) 2021 Ivan (GitHub: ivanl-exe, E-Mail: [email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Owner
Ivan
Advanced programmer, envisioning the future of technology and influence from Web3 and blockchains.
Ivan
kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns

kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns. The library builds on the

pyxem 53 Dec 29, 2022
TRREASURE_IMAGE is python lib by which you can hide anything in a .jpg image with Command-Line Interface[cli] feature

TRREASURE_IMAGE TRREASURE_IMAGE is a python third-party library with Command-Line Interface[cli] feature. Table of Contents General Info Python librar

Fatin Shadab 3 Jun 07, 2022
Xmas-Tree-GIF-Tool - Convert any given animated gif file into an animation in GIFT CSV format

This repo is made to participate in Matt Parker's XmasTree 2021 event. Convert a

Aven Zitzelberger 2 Dec 30, 2021
This Github Action automatically creates a GIF from a given web page to display on your project README

This Github Action automatically creates a GIF from a given web page to display on your project README

Pablo Lecolinet 28 Dec 15, 2022
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

1 Feb 02, 2022
Random collage/montage generator with drop-shadow

Random Collage Example Usage These are the sample input files in $PWD for the below examples: 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10

M B 1 Dec 07, 2021
DP2 graph edit codes.

必要なソフト・パッケージ Python3 Numpy JSON Matplotlib 動作確認環境 MacBook Air M1 Python 3.8.2 (arm64) Numpy 1.22.0 Matplotlib 3.5.1 JSON 2.0.9 使い方 draw_time_histgram(

1 Feb 19, 2022
A large-scale dataset of both raw MRI measurements and clinical MRI images

fastMRI is a collaborative research project from Facebook AI Research (FAIR) and NYU Langone Health to investigate the use of AI to make MRI scans faster. NYU Langone Health has released fully anonym

Facebook Research 907 Jan 04, 2023
PIX is an image processing library in JAX, for JAX.

PIX PIX is an image processing library in JAX, for JAX. Overview JAX is a library resulting from the union of Autograd and XLA for high-performance ma

DeepMind 294 Jan 08, 2023
📷 Python package and CLI utility to create photo mosaics.

📷 Python package and CLI utility to create photo mosaics.

Loic Coyle 7 Oct 29, 2022
Computational Xmas Tree lights!

Computational Xmas Tree This repo contains the code for the computational illumination of a Christmas Tree! It is based on the work by Matt Parker fro

GSD6338 146 Dec 23, 2022
Blue noise image stippling in Processing (requires GPU)

Blue noise image stippling in Processing (requires GPU)

Mike Wong 141 Oct 09, 2022
Fuzzware is a project for automated, self-configuring fuzzing of firmware images

Fuzzware Fuzzware is a project for automated, self-configuring fuzzing of firmware images. The idea of this project is to configure the memory ranges

190 Dec 21, 2022
Python scripts for semi-automated morphometric analysis of atolls from Landsat satellite Imagery.

AtollGeoMorph Python scripts for semi-automated morphometric analysis of atolls from Landsat satellite Imagery. The python scripts included allow user

1 Dec 16, 2022
Fixed Version Of Blender Low Poly Rock Generator For Blender 3.0.0

Blender (3.0.0) - Low Poly Rock Generator This is an addon for Blender 3.0.0 to generate low poly rocks. It was based on an addon that unfortunately h

3 Mar 24, 2022
Convert a DOS Punk image to text

DOS Punk Text Inspired by MAX CAPACITY's DOS Punks & the amazing DOS Punk community. DOS Punk Text is a Python 3 script that renders a DOS Punk image

4 Jan 13, 2022
Fast Image Retrieval is an open source image retrieval framework

Fast Image Retrieval is an open source image retrieval framework release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This framework implements most of the major binar

CISiP Lab 39 Nov 25, 2022
Png-to-stl - Converts PNG and text to SVG, and then extrudes that based on parameters

have ansible installed locally run ansible-playbook setup_application.yml this sets up directories, installs system packages, and sets up python envir

1 Jan 03, 2022
LSB Image Steganography Using Python

Steganography is the science that involves communicating secret data in an appropriate multimedia carrier, e.g., image, audio, and video files

Mahmut Can Gönül 2 Nov 04, 2021
A python script for extracting/removing exif data from images by @AbirHasan2005

Image-Exif A Python script for extracting exif metadata from images. How to use? Using this script you can extract exif data from image and save in .c

Abir Hasan 13 Dec 16, 2022