Use state variables in color expression

fractal {
	// Set region margins to left=-3.0, bottom=-1.5, right=0.0, top=1.5
	// Declare state vector as [x,n,p,q] where x and n are built-in variables, and p and q are custom variables
	orbit [<-3.0,-1.5>,<0.0,1.5>] [x,n,p,q] {
		// Initialize variables p and q
		begin {
			p = <0,0>;
			q = 0;
		}
		// Iterate for n from 0 to 200 stopping when re(x) > 1000000
		loop [0, 200] (re(x) > 1000000) {
			// Declare orbit equation where x is a state variable and w is current point of region
			x = x * x + w;
			m = |x|;
			if (m > re(q)) {
				p = x;
				q = m;
			}
			// Additional stop condition
			if (m > 2) {
				stop;
			}
		}
	}
	// Set background color to alpha=1, red=0, green=0, blue=0
	color [(1,0,0,0)] {
		// Initialize variables c1 and c2
		init {
			c1 = |p|;
			c2 = <p>;
		}
		// Apply rule when n > 0 and set opacity to 1.0
		rule (n > 0) [1] {
			// Compute alpha component
			1,
			// Compute red component
			(1 + sin(c1 / pi)) / 2,
			// Compute green component
			(1 + cos(c2 / pi)) / 2,
			// Compute blue component
			(1 + sin(c1 / pi)) / 2
		}
	}
}

Use state variables in color expression


Follow NextFractal on Facebook