Julia Set

The Julia set is a fractal. Fractals are mathematical sets that have a repeating pattern at every scale. For more information look at the bottom of this post. The Julia set is based on the Mandelbrot set, each c constant in the Julia set corresponds to a point in the Mandelbrot set.

The images above of the Julia set were created in processing. Source code can be seen below.

```boolean[] keyDown = new boolean[10];
//camera x
float xC = 0.0;
//camera y
float yC = 0.0;
//constant X
float constX = -1.3000027;
//constant Y
float constY = 0.0028000013;
//camera zoom
float zoom =  1.2;// * pow(10, -5)
//zoom speed
float zoomSpeed = 0.01;
//movement speed
float movementSpeed = 0.1;
//constant change speed
float constSpeed = 0.002;

void setup() {
//have a small resolution if you want to be able to move around
size(960, 640);
colorMode(HSB, 360, 100, 100);
}

void draw() {
//Julia set Escape time algorithm
for (int x = 0; x < width; x++) {
for (int y = 0; y < width; y++) {
float x0 = ((3 * (float)(x) / (float)width) - 1.5) * zoom + xC;
float y0 = (2 * (float)(y) / (float)height - 1) * zoom + yC;
int iteration = 0;
int max_iteration = 1000;
while (x0*x0 + y0*y0 < 4  &&  iteration < max_iteration) {
float xtemp = x0*x0 - y0*y0 + constX;
y0 = 2*x0*y0 + constY;
x0 = xtemp;
iteration = iteration + 1;
}
if (iteration == max_iteration)
stroke(color(0, 100, 0));
else {
//blue and black color scheme
stroke(color(230, 100, iteration % 100));
//multi color scheme
//stroke(color(iteration % 300, 100, 100));
}
point(x, y);
}
}
//movement code
movement();
}

private void movement() {
if (keyDown[0] == true) {
yC -= movementSpeed * zoom;
}
if (keyDown[1] == true) {
yC += movementSpeed * zoom;
}
if (keyDown[2] == true) {
xC -= movementSpeed * zoom;
}
if (keyDown[3] == true) {
xC += movementSpeed * zoom;
}
if (keyDown[4] == true) {
zoom -= zoomSpeed * zoom;
}
if (keyDown[5] == true) {
zoom += zoomSpeed * zoom;
}
if (keyDown[6] == true) {
constX -= constSpeed * zoom;
}
if (keyDown[7] == true) {
constX += constSpeed * zoom;
}
if (keyDown[8] == true) {
constY -= constSpeed * zoom;
}
if (keyDown[9] == true) {
constY += constSpeed * zoom;
}
}

public void keyPressed() {
if (key == 'w' || (key == CODED && keyCode == UP)) {
keyDown[0] = true;
}
if (key == 's' || (key == CODED && keyCode == DOWN)) {
keyDown[1] = true;
}
if (key == 'a' || (key == CODED && keyCode == LEFT)) {
keyDown[2] = true;
}
if (key == 'd' || (key == CODED && keyCode == RIGHT)) {
keyDown[3] = true;
}
if (key == '=') {
keyDown[4] = true;
}
if (key == '-') {
keyDown[5] = true;
}
if (key == '[') {
keyDown[6] = true;
}
if (key == ']') {
keyDown[7] = true;
}
if (key == ';') {
keyDown[8] = true;
}
if (key == '\'') {
keyDown[9] = true;
}
}

public void keyReleased() {
if (key == 'w' || (key == CODED && keyCode == UP)) {
keyDown[0] = false;
}
if (key == 's' || (key == CODED && keyCode == DOWN)) {
keyDown[1] = false;
}
if (key == 'a' || (key == CODED && keyCode == LEFT)) {
keyDown[2] = false;
}
if (key == 'd' || (key == CODED && keyCode == RIGHT)) {
keyDown[3] = false;
}
if (key == '=') {
keyDown[4] = false;
}
if (key == '-') {
keyDown[5] = false;
}
if (key == '[') {
keyDown[6] = false;
}
if (key == ']') {
keyDown[7] = false;
}
if (key == ';') {
keyDown[8] = false;
}
if (key == '\'') {
keyDown[9] = false;
}

//saves frame
if (key == 'p')
saveFrame("snapShot-####.png");
//prints movement, constant and zoom data
if (key == 'x')
print("float xC = " + xC +";\nfloat yC = " + yC + ";\nfloat constX = " + constX + ";\nfloat constY = " + constY + ";\nfloat zoom =  " + zoom + ";// * pow(10, -5)");
}
```