Skip to content

apetsiuk/Procedural-Drawing-in-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Math & Code: A Simple Tutorial for Procedural Abstract Illustration in Python

'Title image'

This repository contains the complete implementation and source code for my Medium article. For details, see the Jupyter Notebook. 🪐

Inspired by the vintage vector aesthetic of Atari's 'Asteroids', this project explores how simple mathematical principles—like coordinate geometry and stochastic processes—can be used to generate cool digital art. While modern AI-based systems are powerful, this code demonstrates the beauty of the fundamental logic underlying the rendering of spatial forms.

'Procedural animation'

Key Features

  • Gaussian Noise Canvas: Simulates a "gritty," organic paper texture using controlled randomness.
  • Parabola Families: Generates flowing, mathematical curves using quadratic coefficients.
  • 3D Convex Hull Projection: Transforms a cluster of 3D coordinates into a structured, architectural centerpiece.
  • Depth-Weighted Anaglyph Effect: Implements "Atmospheric Perspective" by varying line thickness and color displacement based on Z-axis depth.
  • Procedural Animation: Scripts to generate an N-frame looping GIF of the rotating shimmering geometry.

Tech Stack

  • Python 3.x
  • NumPy: Vectorized math and coordinate transformations.
  • SciPy: Spatial algorithms and Convex Hull calculation.
  • Pillow (PIL): Raster image manipulation and GIF export.
  • Matplotlib: Visualization and rendering.

How to Use The core logic is broken down into modular functions:

  • generate_canvas: Creates the textured background.
  • generate_colored_area: Handles the central focal point. It generates a smooth linear gradient between two randomized RGB values. It supports dynamic directions (horizontal or vertical) for each color channel to create various non-uniform shifts.
  • generate_image: The master orchestration function. It initializes the canvas, applies the stochastic Gaussian noise, renders the family of parabolas, and sets the frame boundaries. This creates the "environment" for your 3D geometry.
  • generate_projection: Projects 3D hull vertices into 2D space. It calculates the depth-weighted linewidth and alpha for every edge to simulate atmospheric perspective.
  • rotate: Performs a 3D transformation around the object's centroid. This ensures that even during high-degree rotations, the object spins on its own axis and stays within the frame.

You can run the main script to generate a unique piece of procedural art every time, or use the animation loop to create a shimmering 3D GIF.

Releases

No releases published

Packages

No packages published