More writing

This commit is contained in:
2024-12-13 20:03:53 -05:00
parent a5e620f603
commit b526b02e7b
3 changed files with 93 additions and 43 deletions

View File

@ -6,20 +6,22 @@ authors: [bspeice]
tags: []
---
Now that we have a basic chaos game in place, it's time to spice things up. Transforms and variations create the
Now that we have a basic chaos game in place, it's time to spice things up. Variations create the
shapes and patterns that fractal flames are known for.
<!-- truncate -->
:::note
:::info
This post uses a set of [reference parameters](../params.flame) to demonstrate the fractal flame algorithm.
If you're interested in tweaking the parameters, or generating your own art, [Apophysis](https://sourceforge.net/projects/apophysis/)
can load that file and you can try tweaking things yourself!
This post covers section 3 of the Fractal Flame Algorithm paper
:::
## Transforms and variations
## Variations
:::note
This post covers section 3 for the Fractal Flame Algorithm paper
:::
import CodeBlock from '@theme/CodeBlock'
@ -28,8 +30,8 @@ playing the chaos game leads to an image of Sierpinski's Gasket. Even though we
the image it generates is exciting. But it's still not nearly as exciting as the images the Fractal Flame
algorithm is known for.
This leads us to the first big innovation of the Fractal Flame algorithm: using non-linear functions
for the transforms. These functions are known as "variations":
This leads us to the first big innovation of the Fractal Flame algorithm: applying non-linear functions
after the affine transform has happened. These functions are called "variations":
$$
F_i(x, y) = V_j(a_i \cdot x + b_i \cdot y + c_i, d_i \cdot x + e_i \cdot y + f_i)
@ -39,10 +41,10 @@ import variationSource from '!!raw-loader!../src/variation'
<CodeBlock language="typescript">{variationSource}</CodeBlock>
Variations, labeled $V_j$ above, are functions just like transforms (we use $j$ to indicate a specific variation).
They take an input point $(x,y)$, and give an output point. However, the sky is the limit for what variation functions do in between
input to output. The Fractal Flame paper lists 49 different variation functions,
and the official `flam3` implementation supports [98 different functions](https://github.com/scottdraves/flam3/blob/7fb50c82e90e051f00efcc3123d0e06de26594b2/variations.c).
Just like transforms, variations ($V_j$) are functions that map $(x, y)$ coordinates to new coordinates.
However, the sky is the limit for what we can do in between input and output.
The Fractal Flame paper lists 49 different variation functions,
and the official `flam3` implementation supports [98 different variations](https://github.com/scottdraves/flam3/blob/7fb50c82e90e051f00efcc3123d0e06de26594b2/variations.c).
To draw our reference image, we'll focus on four variations:
@ -59,16 +61,16 @@ import linearSrc from '!!raw-loader!../src/linear'
<CodeBlock language={'typescript'}>{linearSrc}</CodeBlock>
:::tip
In a way, we've already been using this variation! The functions that define Sierpinski's Gasket
In a way, we've already been using this variation! The transforms that define Sierpinski's Gasket
apply the affine coefficients to the input point, and use that as the output point.
:::
### Julia (variation 13)
This variation is a good example of the non-linear functions the Fractal Flame Algorithm introduces.
It still receives an input point $(x, y)$, but does some crazy things with it:
This variation is a good example of the non-linear functions we can use. It uses both trigonometry
and probability to produce interesting shapes:
TODO: Connection with the julia set?
$$
\begin{align*}
@ -91,8 +93,8 @@ import juliaSrc from '!!raw-loader!../src/julia'
### Popcorn (variation 17)
Some variations rely on knowing the transform's affine coefficients; these are known as "dependent variations."
For the popcorn variation, we use the $c$ and $f$ coefficients:
Some variations rely on knowing their transform's affine coefficients; they're known as "dependent variations."
For the popcorn variation, we use $c$ and $f$:
$$
V_{17}(x,y) = (x + c \cdot \text{sin}(\text{tan }3y), y + f \cdot \text{sin}(\text{tan }3x))
@ -104,7 +106,7 @@ import popcornSrc from '!!raw-loader!../src/popcorn'
### PDJ (variation 24)
Some variations have extra parameters that the designer can choose; these are known as "parametric variations."
Some variations have extra parameters we can choose; these are known as "parametric variations."
For the PDJ variation, there are four extra parameters we can choose:
$$
@ -132,14 +134,11 @@ import blendSource from "!!raw-loader!../src/blend";
<CodeBlock language={'typescript'}>{blendSource}</CodeBlock>
With that in place, we have enough to render a first full fractal flame. We'll use the same
chaos game as before, but use our new transforms and variations to produce a dramatically different image:
With that in place, we have enough to render a first fractal flame. We'll use the same
chaos game as before, but our new transforms and variations produce a dramatically different image:
:::tip
This image is interactive! The sliders change the variation weights ($v_{ij}$ parameters)
so you can design your own image.
Try using the sliders to find which parts of the image each transform controls.
Try using the variation weight sliders to figure out which parts of the image each transform controls.
:::
import {SquareCanvas} from "../src/Canvas";
@ -149,8 +148,8 @@ import FlameBlend from "./FlameBlend";
## Post transforms
Post transforms introduce a second affine transform, this time _after_ variation blending.
We'll use introduce some new variables, but the post transform function should look familiar by now:
Next, we'll introduce a second affine transform, known as a post transform, that is applied _after_ variation blending.
We'll use some new variables, but the post transform function should look familiar:
$$
\begin{align*}
@ -163,11 +162,11 @@ import postSource from '!!raw-loader!./post'
<CodeBlock language="typescript">{postSource}</CodeBlock>
The image below starts with the same initial transforms/variations as the previous fractal flame,
The image below uses the same transforms/variations as the previous fractal flame,
but allows modifying the post-transform coefficients.
<details>
<summary>If you want a challenge...</summary>
<summary>If you want to test your understanding...</summary>
Challenge 1: What post-transform coefficients will give us the previous image?
@ -180,10 +179,23 @@ import FlamePost from "./FlamePost";
## Final transforms
Our last step is to introduce a "final transform" ($F_{final}$) that is applied
regardless of which transform function we're using. It works just like a normal transform
(composition of affine transform, variation blend, and post transform),
but it doesn't change the chaos game state:
import chaosGameFinalSource from "!!raw-loader!./chaosGameFinal"
<CodeBlock language="typescript">{chaosGameFinalSource}</CodeBlock>
import FlameFinal from "./FlameFinal";
<SquareCanvas><FlameFinal/></SquareCanvas>
<SquareCanvas><FlameFinal/></SquareCanvas>
## Summary
Variations are the fractal flame algorithm's first major innovation over previous IFS's.
Blending variation functions and post/final transforms allows us to generate interesting images.
However, the images themselves are grainy and unappealing. In the next post, we'll clean up
the quality and add color.