Showing posts with label Generative art. Show all posts
Showing posts with label Generative art. Show all posts

Tuesday, June 30, 2026

x̄ - > Generative Art: Five More Mathematical Wonders

Generative Art: Five More Mathematical Wonders

🎨 Generative Art: Five More Mathematical Wonders

When mathematics steps out of textbooks and onto canvas, it speaks in elegant symmetries, chaotic systems, and organic tapestries. By exploring deterministic chaos, sound resonance waves, and complex limits, we can uncover profound aesthetic structures hiding within pure algebra.

This second collection features a highly diverse 1 × 5 subplot array generated cleanly using NumPy and Matplotlib. No hand-drawn lines, no stochastic random walks—just pure math rendering art.

Key Idea: From infinite chaotic feedback loops to natural growth grids, these systems showcase how changing a single floating-point parameter can completely rewrite an entire visual ecosystem.

πŸ”’ The Five Dynamic Systems at a Glance

The layout spans a \(1 \times 5\) canvas scaled to \(20 \times 8\) inches. Each cell tests a unique paradigm of algorithmic visualization:

# Visual System Core Concept Colormap / Style
1 Clifford Attractor Nonlinear Strange Attractor Map inferno (Scatter)
2 Chladni Resonance Nodal Interference Patterns twilight_shifted
3 Mandelbrot Boundary Complex Polynomial Iterations magma
4 Vector Flow Field Dynamical Stream Differential Curves viridis
5 Phyllotaxis Spiral Golden Ratio Nature-Mimic Grid Cycled Color Array
Read More

πŸ“Š 1. Clifford Strange Attractor

A strange attractor maps a chaotic trajectory through iterative calculation. The Clifford Attractor updates a point's coordinates using four constant parameters over \(100,000\) iterations: \(x_{n+1} = \sin(a \cdot y_n) + c \cdot \cos(a \cdot x_n)\) and \(y_{n+1} = \sin(b \cdot x_n) + d \cdot \cos(b \cdot y_n)\). Plotted as tiny scatter coordinates with high transparency, it yields silky, smoke-like cosmic curtains.

Technique: High-performance point rendering with ax.scatter() using an ultra-fine alpha value (\(\alpha = 0.01\)) and color maps bound to local array density.

πŸŒ€ 2. Chladni Resonance Patterns

When a physical plate vibrates at a resonant frequency, sand settles naturally along stable, non-vibrating nodal lines. We simulate this phenomenon via the classic mathematical formula for acoustic plates: \(Z = \cos(n \pi x) \cdot \cos(m \pi y) - \cos(m \pi x) \cdot \cos(n \pi y)\). Using integers like \(n=6, m=2\), a deep contour mesh captures beautiful symmetrical geometric cells.

πŸ”¬ 3. Mandelbrot Fractal Boundary

By analyzing the complex number escape sequence \(Z_{n+1} = Z_n^2 + C\), we look into the edge of infinity. This panel zooms tightly into a busy boundary coordinate region of the Mandelbrot Set. The color intensity reflects the exact iteration count at which the sequence diverges past an escape radius of 2, producing high-contrast fractal feedback halos.

🌊 4. Vector Flow Field

Every coordinate point on a grid can house a velocity vector pointing in a specific direction. By defining derivatives \(U = \sin(Y)\) and \(V = \cos(X \cdot Y)\) across a 2D mesh, we generate a smooth, churning vector field. Utilizing Matplotlib's streamplot, we follow imaginary particles flowing gracefully along these field lines.

🌻 5. Logarithmic Phyllotaxis Spiral

Nature packs seeds in sunflower heads with maximum spatial efficiency using the Golden Angle (\(\approx 137.5^{\circ}\)). Spawning \(1,500\) coordinate markers where radius scales as \(r = \sqrt{i}\) and angle scales as \(\theta = i \cdot 137.508^{\circ}\) creates an interlocking spiral matrix. Points expand radially outwards, mimicking natural plant growth structures.

Natural Geometry: The intersecting spiral tracks visible to the human eye correspond directly to consecutive numbers in the Fibonacci sequence.

⚙️ Reproduction Code

The entire five-panel visual gallery is produced seamlessly via a single execution of the native Python script below:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(20, 8), facecolor="black")

# --- 1. Clifford Attractor ---
ax1 = fig.add_subplot(1, 5, 1)
n_points = 100000
x, y = np.zeros(n_points), np.zeros(n_points)
a, b, c, d = -1.4, 1.6, 1.0, 0.7
for i in range(1, n_points):
    x[i] = np.sin(a * y[i-1]) + c * np.cos(a * x[i-1])
    y[i] = np.sin(b * x[i-1]) + d * np.cos(b * y[i-1])
ax1.scatter(x, y, s=0.1, c=x, cmap='inferno', alpha=0.02)
ax1.set_title("Clifford Attractor", color="white", fontsize=12, pad=10)
ax1.axis('off')

# --- 2. Chladni Resonance ---
ax2 = fig.add_subplot(1, 5, 2)
X, Y = np.meshgrid(np.linspace(-1, 1, 300), np.linspace(-1, 1, 300))
n, m = 6, 2
Z = np.cos(n * np.pi * X) * np.cos(m * np.pi * Y) - np.cos(m * np.pi * X) * np.cos(n * np.pi * Y)
ax2.imshow(np.abs(Z), cmap='twilight_shifted', extent=[-1, 1, -1, 1])
ax2.set_title("Chladni Resonance", color="white", fontsize=12, pad=10)
ax2.axis('off')

# --- 3. Mandelbrot Boundary ---
ax3 = fig.add_subplot(1, 5, 3)
h, w, max_iter = 300, 300, 80
# Zooming closely into a boundary region
x_lim = np.linspace(-0.75, -0.73, w)
y_lim = np.linspace(0.1, 0.12, h)
m_grid = np.zeros((h, w))
for i in range(h):
    for j in range(w):
        c_val = complex(x_lim[j], y_lim[i])
        z = 0.0j
        for it in range(max_iter):
            z = z*z + c_val
            if abs(z) > 2.0:
                m_grid[i, j] = it
                break
ax3.imshow(m_grid, cmap='magma', extent=[-0.75, -0.73, 0.1, 0.12])
ax3.set_title("Mandelbrot Boundary", color="white", fontsize=12, pad=10)
ax3.axis('off')

# --- 4. Vector Flow Field ---
ax4 = fig.add_subplot(1, 5, 4)
Yf, Xf = np.mgrid[-3:3:15j, -3:3:15j]
U = np.sin(Yf)
V = np.cos(Xf * Yf)
ax4.streamplot(Xf, Yf, U, V, color=U, cmap='viridis', linewidth=1.2, arrowsize=0.8)
ax4.set_facecolor('black')
ax4.set_title("Vector Flow Field", color="white", fontsize=12, pad=10)
ax4.axis('off')

# --- 5. Phyllotaxis Spiral ---
ax5 = fig.add_subplot(1, 5, 5)
n_seeds = 1500
phi = (1.0 + np.sqrt(5.0)) / 2.0
golden_angle = (2.0 - phi) * 2.0 * np.pi
indices = np.arange(n_seeds)
r_vals = np.sqrt(indices)
theta_vals = indices * golden_angle
x_seeds = r_vals * np.cos(theta_vals)
y_seeds = r_vals * np.sin(theta_vals)
ax5.scatter(x_seeds, y_seeds, c=indices, cmap='hsv', s=6, alpha=0.8)
ax5.set_facecolor('black')
ax5.set_title("Phyllotaxis Spiral", color="white", fontsize=12, pad=10)
ax5.axis('off')

plt.tight_layout()
plt.savefig("generative_art_wonders.png", dpi=150, bbox_inches='tight', facecolor='black')
plt.show()
  

⏭️ Summary & Variations

By combining distinct algorithmic methodologies, the script runs entirely out-of-the-box using only core numeric tools. To expand these further, try animating the variables in the Chladni Resonance module to see patterns shift dynamically as audio frequencies rise, or explore deeper coordinate zooms inside the complex fractal planes.

Friday, June 19, 2026

x̄ - > Generative Art: Five Mathematical Visualizations using python

Generative Art: Five Mathematical Visualizations

🎨 Generative Art: Five Mathematical Visualizations

Mathematical functions, when rendered visually, reveal stunning hidden geometry. From 3D wave-driven bar fields to psychedelic interference grids, these five plots demonstrate how pure equations can produce compelling art.

Each subplot below is generated entirely from NumPy and Matplotlib — no external data, just mathematics.

Key Idea: Every visual pattern here emerges from trigonometric functions, meshgrids, and carefully tuned color mappings — no artistic hand-drawing involved.

πŸ”’ The Five Charts at a Glance

The full figure is a 1 × 5 subplot layout rendered at 20 × 8 inches. Each panel targets a different mathematical structure:

# Chart Name Core Math Colormap
1 3D Bar Chart 3 + 2sin(2.2u) + 2cos(2.8v) cool
2 Radial Vortex Spiral: ΞΈ + 1.5r plasma
3 Color-Interference sin(2x² + 2y²)·cos(2xy) Custom psychedelic
4 Isosurface Contours sin(1.5X)cos(1.5Y) + sin(0.5X)sin(0.8Y) gist_earth
5 Noise Topography Fractal Brownian motion mimic Black contour lines
Read More

πŸ“Š 1. 3D Patterned Bar Chart

A 15 × 15 grid of bars is generated using a meshgrid, then heights are computed from a wave equation: top = 3 + 2sin(2.2u) + 2cos(2.8v), where u and v are normalized coordinates centered at the grid. Bar colors map height values through the cool colormap, creating a smooth cyan-to-magenta gradient.

Technique: ax.bar3d() with shade=True and per-bar color array derived from plt.cm.cool(top / max(top)).

πŸŒ€ 2. Radial Vortex

Twenty concentric rings (radii 0.1 → 0.9) are subdivided into 60 angular steps. Each step spawns a rotated Rectangle patch with spiral distortion applied as ΞΈ' = ΞΈ + 1.5r. Width scales as 0.06(1.1 - r) and height as 0.015r, making inner rectangles wider and outer ones taller, reinforcing the vortex depth illusion.

Key Detail: Rectangle orientation uses angle=degrees(ΞΈ') + 45, giving each tile an angled tilt that drives the swirling effect.

πŸ”¬ 3. Color-Interference Grid

A 40 × 40 grid of Circle patches is drawn over a black background. Each circle's radius and color are driven by the interference value val = sin(2x² + 2y²) · cos(2xy), normalized to [0, 1]. A custom colormap transitions through #00F0FF → #FF007F → #FFAA00 (cyan, magenta, amber), producing a vivid psychedelic moirΓ©.

πŸ”️ 4. Isosurface Contours

A surface is computed over a 100 × 100 meshgrid on [-3, 3]^2 using layered sine/cosine: Z = sin(1.5X)cos(1.5Y) + sin(0.5X)sin(0.8Y). The plot_surface call uses stride 3 with alpha 0.8 and the gist_earth colormap, while ax.contour() projects level curves onto the floor at z_{min} - 0.5.

Surface + Floor Contours

Isosurface preview

Full 5-Panel Layout

Full chart preview

πŸ—Ί️ 5. Perlin Noise Topography

The final panel mimics fractal Brownian motion over a 150 × 150 grid on [-5, 5]^2 using three octaves:

  • Octave 1 (amplitude 1.0): sin(X)cos(Y)
  • Octave 2 (amplitude 0.5): sin(2X)sin(2Y)
  • Octave 3 (amplitude 0.25): cos(4X)cos(4Y)

The result is plotted as 18 black contour lines (linewidths=1.2) on a white background, evoking a topographic survey map with clean, high-contrast readability.

Fractal Property: Each successive octave doubles the spatial frequency and halves the amplitude — a direct analogue to the standard fBm construction used in Perlin noise.

⚙️ Reproduction Code

The full figure is assembled with a single plt.figure(figsize=(20, 8)) call. Run the snippet below to reproduce all five panels:

Dependencies: numpy, matplotlib (including mpl_toolkits.mplot3d). No external datasets required.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Circle
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(20, 8), facecolor="white")

# --- 1. 3D Bar Chart ---
ax1 = fig.add_subplot(1, 5, 1, projection='3d')
_x = np.arange(15); _y = np.arange(15)
X, Y = np.meshgrid(_x, _y)
x, y = X.ravel(), Y.ravel()
u = (x - 7.5) / 5.0; v = (y - 7.5) / 5.0
top = 3 + 2 * np.sin(2.2 * u) + 2 * np.cos(2.8 * v)
ax1.bar3d(x, y, np.zeros_like(top), 0.7, 0.7, top,
          shade=True, color=plt.cm.cool(top / np.max(top)))
ax1.set_title("3D Bar Chart", fontsize=12, pad=10); ax1.axis('off')

# --- 2. Radial Vortex ---
ax2 = fig.add_subplot(1, 5, 2)
ax2.set_aspect('equal'); ax2.set_facecolor('white')
for r in np.linspace(0.1, 0.9, 20):
    for theta in np.linspace(0, 2*np.pi, 60):
        ct = theta + 1.5 * r
        rect = Rectangle(
            (r*np.cos(ct) - 0.03*(1.1-r), r*np.sin(ct) - 0.0075*r),
            0.06*(1.1-r), 0.015*r,
            angle=np.degrees(ct)+45,
            facecolor=plt.cm.plasma(r), edgecolor='none')
        ax2.add_patch(rect)
ax2.set_xlim(-1,1); ax2.set_ylim(-1,1)
ax2.set_title("Radial Vortex", fontsize=12, pad=10); ax2.axis('off')

# --- 3. Color-Interference ---
ax3 = fig.add_subplot(1, 5, 3)
ax3.set_aspect('equal'); ax3.set_facecolor('black')
cmap = LinearSegmentedColormap.from_list("psych",["#00F0FF","#FF007F","#FFAA00"])
for x in np.linspace(-2, 2, 40):
    for y in np.linspace(-2, 2, 40):
        val = (np.sin(2*x**2+2*y**2)*np.cos(2*x*y)+1)/2
        ax3.add_patch(Circle((x,y), 0.04*val+0.01,
                             facecolor=cmap(val), edgecolor='none'))
ax3.set_xlim(-2.2,2.2); ax3.set_ylim(-2.2,2.2)
ax3.set_title("Color-Interference", fontsize=12, pad=10); ax3.axis('off')

# --- 4. Isosurface Contours ---
ax4 = fig.add_subplot(1, 5, 4, projection='3d')
X,Y = np.meshgrid(np.linspace(-3,3,100), np.linspace(-3,3,100))
Z = np.sin(X*1.5)*np.cos(Y*1.5) + np.sin(X*0.5)*np.sin(Y*0.8)
ax4.plot_surface(X,Y,Z,rstride=3,cstride=3,cmap='gist_earth',alpha=0.8,edgecolor='none')
ax4.contour(X,Y,Z,zdir='z',offset=Z.min()-0.5,cmap='gist_earth',linewidths=0.8)
ax4.set_zlim(Z.min()-0.5, Z.max()+0.5)
ax4.set_title("Isosurface Contours", fontsize=12, pad=10); ax4.axis('off')

# --- 5. Noise Topography ---
ax5 = fig.add_subplot(1, 5, 5)
ax5.set_aspect('equal')
X,Y = np.meshgrid(np.linspace(-5,5,150), np.linspace(-5,5,150))
Z = (np.sin(X)*np.cos(Y) + 0.5*np.sin(2*X)*np.sin(2*Y)
     + 0.25*np.cos(4*X)*np.cos(4*Y))
ax5.contour(X,Y,Z,levels=18,colors='black',linewidths=1.2)
ax5.set_title("Noise Topography", fontsize=12, pad=10); ax5.axis('off')

plt.tight_layout()
plt.savefig("generative_art.png", dpi=150, bbox_inches='tight')
plt.show()
  

⏭️ Next Steps

Future extensions could replace the fBm mimic with true Perlin or Simplex noise via the noise library, animate the vortex and interference panels using FuncAnimation, or export each subplot as an individual SVG for web embedding.

Featured Post

3rd Place at the BAKE Blogger Awards: Thank You for the Support!

3rd Place at the BAKE Blogger Awards: Thank You for the Support! ...

Meet the Authors
Zacharia Nyambu’s blog features multiple contributors with clear activity status.
Active ✔
πŸ§‘‍πŸ’»
Zacharia Nyambu
Lead Author
Inactive ✖
πŸ‘©‍πŸ’»
Linda Bahati
Co‑Author
Inactive ✖
πŸ‘¨‍πŸ’»
Jefferson Mwangolo
Co‑Author
Inactive ✖
πŸ‘©‍πŸŽ“
Florence Wavinya
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Esther Njeri
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Clemence Mwangolo
Guest Author

Followers