Pdraw - Generate Deterministic, Procedural Artwork from Arbitrary Text

Overview

pdraw.py: Generate Deterministic, Procedural Artwork from Arbitrary Text

pdraw allows users to generate line art from arbitrary text. It has no dependencies other than the Python standard library, and works with Python 3.10+ (3.7+ should work but are untested).

Demo

Thanks to Numberphile for the idea for this script.

Installation

Either copy the pdraw.py file or git clone the repository.

$ git clone [email protected]:Sonictherocketman/pdraw.git

Then simply run the script.

$ python3 pdraw.py -i a-file.txt [-e for arbitrary text]

IMPORTANT NOTICE: I have not confirmed this, but it looks like versions of Python installed via Homebrew are not suitable for this script as they do not come with the necessary tkinter libraries bundled in. I had to install Python direct from python.org

Testing

There are no tests. ¯_(ツ)_/¯

Usage Notes

Encoding Text as Base 10 Numbers

pdraw natively supports drawing strings of base 10 digits. However, pdraw can also sketch arbitrary text. To enable the drawing of arbitrary text, add the --encode flag to your command. This will instruct pdraw to first convert each character into its base 10 form (using a silly conversion that could probably be a lot more efficient).

Faster Drawing

pdraw is meant to be interactive, and so it renders its output fairly frequently. To speed up the drawing process, add the -r/--refresh-rate flag with a larger cycle count.

Changing Draw Distance & Angles

pdraw can also draw with arbitrary draw distances and angles to suit your needs. The -d/--distance flag allows you to set a distance multiplier for each line, and the -a/--angle flag allows you to set the rotation angle between each line. The default is 90 which draws squares. Use -a 60 for hexagons, -a 120 for triangles, and -a 160 for cool sharp ridges.

Saving Drawings

pdraw can save drawings as .eps files (which can be opened in Preview.app for macOS as well as other PDF viewers). Those files can then be converted to PNG/JPG/etc. Simply supply the -o/--output flag with a path to the desired file.

Optionally, you can close pdraw when your drawing is complete and saved by supplying the -c/--close flag.

Example Usage

Below are some quick recipes to get you started.

Drawing Digits of Pi (in hexagons)

You can download the first billion digits of Pi here and start plotting them. Make sure to give pdraw an iteration count though, otherwise it will attempt to draw the entirety of those billion digits, which would probably not work and take forever.

$ ./pdraw -i digits-of-pi.txt

pdraw

Note: pdraw also accepts an --offset parameter that tells pdraw how many bytes into the file to start reading. Use this to plot various sections of Pi (or other longer files)!

Drawing pdraw Itself!

Yup. pdraw can of course draw itself. Code is just text after all.

$ ./pdraw -i pdraw.py --encode

pdraw

Visualizing Song Lyrics

One thing I've been having fun with is graphing arbitrary song lyrics. I even printed some for family members of their favorite songs.

$ ./pdraw -i peaceful-easy-feeling.txt --encode -a 120

Peaceful Easy Feeling

Visualizing Randomness

pdraw can draw any digital data, and it can read from stdout! It cannot however deal with binary data, so you'll need to convert your random bytes into a string. Thankfully, we can do that easily on the command-line.

$ cat /dev/urandom | base64 | ./pdraw -n 5000 --encode

Note: Make sure to give pdraw an iteration count or it will draw forever!

About this Script

This script is based on a Numberphile Video about using procedural techniques to sketch the digits of Pi. Originally, I aimed to simply reproduce their work and play with the artwork I could generate from it. Eventually, that evolved into building a fully-fledged command-line application that could graph arbitrary digits, and since all data on a computer can be converted to numbers, I had effectively built a way to draw anything!

Thanks to Numberphile for putting out amazing videos and for inspiring me to write this script.

License

This script is available under the terms of the MIT License. See license.txt for more information.

Copyright © 2022 Brian Schrader

You might also like...
Easily Generate Revolut Business Cards

RevBusinessCardGen Easily Generate Revolut Business Cards Prerequisites Before you begin, ensure you have met the following requirements: You have ins

basic tool for NFT. let's spam, this is the easiest way to generate a hell lotta image

NFT generator this is the easiest way to generate a hell lotta image buckle up and follow me! how to first have your image in .png (transparent backgr

Generate Openbox Menus from a easy to write configuration file.

openbox-menu-generator Generate Openbox Menus from a easy to write configuration file. Example Configuration: ('#' indicate comments but not implement

tetrados is a tool to generate a density of states using the linear tetrahedron method from a band structure.

tetrados tetrados is a tool to generate a density of states using the linear tetrahedron method from a band structure. Currently, only VASP calculatio

Generate your personal 8-bit avatars using Cellular Automata, a mathematical model that simulates life, survival, and extinction
Generate your personal 8-bit avatars using Cellular Automata, a mathematical model that simulates life, survival, and extinction

Try the interactive demo here ✨ ✨ Sprites-as-a-Service is an open-source web application that allows you to generate custom 8-bit sprites using Cellul

Developed a website to analyze and generate report of students based on the curriculum that represents student’s academic performance.
Developed a website to analyze and generate report of students based on the curriculum that represents student’s academic performance.

Developed a website to analyze and generate report of students based on the curriculum that represents student’s academic performance. We have developed the system such that, it will automatically parse data onto the database from excel file, which will in return reduce time consumption of analysis of data.

A program to generate random numbers b/w 0 to 10 using time
A program to generate random numbers b/w 0 to 10 using time

random-num-using-time A program to generate random numbers b/w 0 to 10 using time it uses python's in-built module datetime and an equation which retu

python scripts and other files to generate induction encoder PCBs in Kicad
python scripts and other files to generate induction encoder PCBs in Kicad

induction_encoder python scripts and other files to generate induction encoder PCBs in Kicad Targeting the Renesas IPS2200 encoder chips.

Owner
Brian Schrader
independent software developer, writer, musician, space enthusiast, hiker, coffee drinker, mac user
Brian Schrader
Automated, progress quest-inspired procedural adventuring

Tales of an Endless Journey (TEJ) Automated, progress quest-inspired procedural adventuring What is this project? Journey is the result of many, many

null 8 Dec 14, 2021
Procedural modeling of fruit and sandstorm in Blender (bpy).

SandFruit Procedural modelling of fruit and sandstorm. Created by Adriana Arcia and Maya Boateng. Last updated December 19, 2020 Goal & Inspiration Ou

Adriana Arcia 2 Mar 20, 2022
Py4J enables Python programs to dynamically access arbitrary Java objects

Py4J Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as

Barthelemy Dagenais 1k Jan 2, 2023
Print 'text color' and 'text format' on Term with Python

term-printer Print 'text color' and 'text format' on Term with Python ※ It may not work depending on the OS and shell used. PIP $ pip install term-pri

ななといつ 10 Nov 12, 2022
Tool to generate wrappers for Linux libraries allowing for dlopen()ing them without writing any boilerplate

Dynload wrapper This program will generate a wrapper to make it easy to dlopen() shared objects on Linux without writing a ton of boilerplate code. Th

Hein-Pieter van Braam 25 Oct 24, 2022
A Bot Which Can generate Random Account Based On Your Hits.

AccountGenBot This Bot Can Generate Account With Hits You Save (Randomly) Keyfeatures Join To Use Support Limit Account Generation Using Sql Customiza

DevsExpo 30 Oct 21, 2022
Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build prortfolios

Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build prortfolios

Salma Saidane 64 Sep 28, 2022
Generate Azure Blob Storage account authentication headers for Munki

Azure Blob Storage Authentication for Munki The Azure Blob Storage Middleware allows munki clients to connect securely, and directly to a munki repo h

Oliver Kieselbach 10 Apr 12, 2022
🪄 Auto-generate Streamlit UI from Pydantic Models and Dataclasses.

Streamlit Pydantic Auto-generate Streamlit UI elements from Pydantic models. Getting Started • Documentation • Support • Report a Bug • Contribution •

Lukas Masuch 103 Dec 25, 2022
Plugin to generate BOM + CPL files for JLCPCB

KiCAD JLCPCB tools Plugin to generate all files necessary for JLCPCB board fabrication and assembly Gerber files Excellon files BOM file CPL file Furt

bouni 566 Dec 29, 2022