Module endo2d

Module endo2d 

Source
Expand description

§2D Endomorphisms

Mathematical transformations that map points from the unit square to itself. These functions are commonly used in fractal systems, particularly Iterated Function Systems (IFS), and provide various artistic and mathematical effects for generative art applications.

§What are Endomorphisms?

An endomorphism is a mathematical function that maps a space to itself. In this context, all functions map points within or around the unit square [-1, 1] × [-1, 1] to new positions, creating various visual effects.

§Available Transformations

§Trigonometric Functions

  • sinusoid(): Applies sine function to both coordinates
  • hankerchief(): Creates handkerchief-like distortions
  • heart(): Creates heart-shaped transformations

§Geometric Transformations

  • spherical(): Spherical inversion transformation
  • swirl(): Creates swirling, spiral effects
  • horseshoe(): Horseshoe-shaped transformation
  • disc(): Disc-based coordinate transformation

§Coordinate System Changes

  • to_polar(): Converts to polar coordinate representation

§Usage in Fractal Systems

use wassily_algorithms::*;
use wassily_core::*;

// Create an IFS (Iterated Function System)
let mut point = pt(0.5, 0.3);
let mut canvas = Canvas::new(800, 600);

// Apply transformations iteratively
for _ in 0..10000 {
    // Randomly choose a transformation
    point = match rand::random::<u8>() % 3 {
        0 => swirl(point),
        1 => heart(point),
        _ => spherical(point),
    };
     
    // Plot the transformed point
    let screen_x = (point.x + 1.0) * 400.0;
    let screen_y = (point.y + 1.0) * 300.0;
    canvas.dot(screen_x, screen_y, *WHITE);
}

§Mathematical Properties

Each transformation has unique mathematical properties:

  • Continuous: All transformations are continuous functions
  • Bounded: Most transformations keep points within reasonable bounds
  • Differentiable: Most functions are smooth and differentiable
  • Invertible: Some transformations are invertible, others are not

§Applications

  • Fractal Generation: IFS fractals and strange attractors
  • Artistic Effects: Distortion effects for images and shapes
  • Mathematical Visualization: Studying function behavior
  • Animation: Creating organic, flowing motion patterns

Functions§

cross
diamond
disc
ex
exponential
fisheye
hankerchief
heart
horseshoe
hyperbolic
sinusoid
Applies the sine function to both x and y coordinates.
spherical
Spherical inversion transformation.
spiral
swirl
Creates a swirling, spiral transformation.
tangent
to_polar