ifs

command module
v0.0.0-...-5e03b05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

What is this?

Some experimentation with Go's image library, goroutines, complex numbers and http server to generate and serve ifs-based fractal images.

Some of the core image-generation code is adapted from the mandelbrot example in The Go Programming Language.

How to run it

  1. Install go if you do not already have it installed (see https://go.dev/doc/install).
  2. Clone this repo git clone https://github.com/psteitz/ifs.git
  3. From the base directory of the cloned repo, go run main.go
  4. Open a browser and hit http://localhost:8080/julia to see an example animated fractal image.

Step 2. starts an http server. When you are finished playing with it, use ctrl-C to kill it.

What it does

The generated images are related to Julia sets. The brightest points in the images are close to points in the Julia set associated with the process. The request path http://localhost:8080/juliaSingle expects two request parameters, re and im. The generated image shows the eventual behavior of the iterative function system z -> z^2 + c where z is a complex number corresponding to a point in the window of the image and c is the complex number with real part equal to re and imaginary part equal to im.

The window is the square from -1.5 to 1.5 in both real and imaginary dimensions in the complex plane. If a point is colored black, that means that when z is set initially to that point and z -> z^2 + c is iterated repeatedly, the value remains small in modulus (i.e., the point does not "escape to infinity"). Points that do escape to infinity are colored according to how many iterations it takes for their modulus to exceed 10. The very bright points are likely close the the Julia set for the process. For example, http://localhost:8000/juliaSingle?re=-0.8&im=0.156 generates an image whose brightest points correspond to points in the Julia set for z -> z^2 + (-0.8 + 0.156i)

The request path http://localhost:8080/julia generates animated gifs that do what http://localhost:8080/juliaSingle does, but for a range of c values that move in and out of the Mandelbrot Set. The path that c traverses is determined by the paramPath request parameter.

  1. Angor moves c along the real axis, back and forth between -1.25 and 1.25 (near edges of the Mandelbrot set).
  2. Exp moves c around the circle, .7885e^i*alpha where alfpha goes from 0 to 2pi.
  3. Wabbit moves c back and forth along a line near the point .3887 - .2158i which is near the boundary of the Mandelbrot set. Use http://localhost:8080/julia?paramPath=Wabbitor Angor to see animations along the other paths.

The request path http://localhost:8080/newton generates a single image showing the eventual behavior of Newton's method applied to find complex roots of the equation z^4 - 1 = 0 (primitive 4th roots of unity) when starting with a point in the complex plane. In this case, the window goes from -2 to 2 in both real and complex coordinates and points are colored according to which root the iterates converge to:

Root Color
1 red
-1 blue
i green
-i purple

Points that don't converge to any root are colored black and brightness of the colored points is determined by how long the iterates take to converge to the respective root.

Request parameters

/juliaSingle has two request parameters:

Parameter Meaning Default value
re Real part of c parameter -1.25
im Imaginary part of c parameter 0

/julia recognizes 3 parameters:

Parameter Meaning Default value
paramPath name of paramter path function Exp
numframes Number of frames to compute along paramPath 64
numworkers Number of goroutines to concurrently build frames 4

/newton recognizes numframes and numworkers as above.

Increasing the number of frames will make the animation go more slowly and smoothly, but will take longer to compute. Increasing the number of workers can speed things up if the run host has a lot of available compute.

Documentation

Overview

A little image server that generates and serves PNG and animated GIF images illustrating the eventual behavior of some classic iterated function systems.

The newton function generates a png showing Newton's method IFS seeking roots of p(z) = z^4 - 1. The julia function generates Julia sets showing eventual behavior under the process z -> z^2 + c for a range of c values creating an animated GIF with each frame corresponding to a different c value.

Portions of the image-generation code are a adapted from code in gopl.io/ch3/mandelbrot from the wonderful book _The Go Programming Language_ by Alan A. A. Donovan & Brian W. Kernighan. The adapted code is provided under License: https://creativecommons.org/licenses/by-nc-sa/4.0/

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL