NOTE: This was done by both Nicholas Phillips, and I. This is a Julia set Fractal. The source code is below the image.

/**
* This class draws a Mandelbrot fractal.
* @author Andrew Phillips
* @since 2/15/26
* @class Computer Graphics Semester 2
* @project Mandelbrot
*/
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class JuliaDaSet extends JFrame {
//Create the fractal JPanel
JuliaBot d = new JuliaBot();

public static void main(String args[]) {
//Call the main constructor.
new JuliaDaSet();
}

public JuliaDaSet() {
//Create the JFrame
setTitle("Mandy the brot");
setSize(600, 600);
add(d);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}

class JuliaBot extends JPanel {
//IMPLEMENTATION CODE
final static int COUNT_LIMIT = 100;
final static int fg = 255;
final static int bg = 0;
final static float g2 = .5f;
static float increase = 0.9f;
static float inc2 = .3f;
final static float cMin = -2;
final static float cMax = 0;
static int nStep = 10;
final static float dc = (cMax - cMin) / nStep;
static int j = 0;
//Complex c = new Complex(.4, .1);
//Complex c = new Complex(-.8, .1);

protected void paintComponent(Graphics g) {

super.paintComponent(g);

drawJuls(g,c);
}
public void drawJuls(Graphics g, Complex c) {
//Complex c= new Complex(cMin,0);
for (double x = -3.0; x < 3.0; x += 0.01)

for (double y = -3.0; y < 3.0; y += 0.01) {
int cnt = count(new Complex(x, y), c);


float s = (float) Math.pow((cnt/(float)COUNT_LIMIT) % 30, g2);

int colorScale = (int)(s * fg + (1 -s) * bg);
g.setColor(new Color(colorScale % 200,colorScale % 19, colorScale % 100));
g.drawRect((int) (x * 100) + 400, (int) (y * 100) + 400, 1, 1);
}
}
/** Returns the iteration count */

static int count(Complex z, Complex c) {


for (int i = 0; i < COUNT_LIMIT; i++) {

z = z.square().add(c);

if (z.abs() > 8)

return i;

}

return COUNT_LIMIT; // Indicates a bounded sequence

}
}

public class Complex {
//Create the complex numbers
private double x;
private double y;
public double answer;

public Complex(double x, double y) {
this.x = x;
this.y = y;
answer = this.x + this.y;
}
/*
* Add complex numbers
* @param Complex c
* @return Complex(ex, why)
*/
public Complex add(Complex c) {
double ex = (this.x + c.x);
double why = (this.y + c.y);
return new Complex(ex, why);
}
/*
* Subtract complex numbers
* @param Complex c
* @return Complex(ex, why)
*/
public Complex subtract(Complex c) {
double ex = (this.x - c.x);
double why = (this.y - c.y);
return new Complex(ex, why);
}
/*
* More subtracting of complex numbers
* @param Complex c, Complex z
* @return Complex(ex, why)
*/
public Complex juliaMath(Complex z, Complex c) {
return z.square().add(c);
}
public Complex square() {
return new Complex((this.x * this.x) - (this.y * this.y), 2*this.x * this.y);
}
public Complex subtract(Complex c, Complex z) {
double ex = (c.x - z.x);
double why = (c.y - z.y);
return new Complex(ex, why);
}
/*
* Multiply complex numbers
* @param Complex c
* @return Complex(ex, why)
*/
public Complex multiply(Complex c) {
double ex = (this.x * c.x - c.y * this.y);
double why = (this.y * c.x + c.y * this.x);
return new Complex(ex, why);

}
//THE REST IS UNNECESSARY
public Complex pow(int factor) {
double one = Math.pow(this.x, factor);
double two = Math.pow(this.y, factor);
return new Complex(one, two);
}


public double abs() {
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
}
}</pre>
<pre>
Advertisements