Hi squids! This is Squiva here with a new blog post, and in this blog post I will be sharing my 5 sided Mandelbrot set (or as I like to call it, my Mandelstar). It didn’t take long, and I will post the code below after the image (NOTE: Some of this code was recycled code, but most of it was mine. Also, sorry about the low res :\).

mandistar

Code:

/**
 * 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 Mandelbrot extends JFrame {
 //Create the fractal JPanel
 DrawMandelbrot d = new DrawMandelbrot();

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

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

class DrawMandelbrot extends JPanel {
 //IMPLEMENTATION CODE
 final static int COUNT_LIMIT = 600;

 protected void paintComponent(Graphics g) {

 super.paintComponent(g);

 for (double x = -3.0; x < 3.0; x += 0.01)

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

 if (c == COUNT_LIMIT)

 g.setColor(Color.BLACK); // c is in a Mandelbrot set

 else

 g.setColor(new Color(c * 256 % 256, c * 243 % 256,
 c * 254 % 256));

 g.drawRect((int) (x * 100) + 400, (int) (y * 100) + 400, 1, 1); // Fill
 // a

 }

 }

 /** Returns the iteration count */

 static int count(Complex c) {

 Complex z = new Complex(0, 0); // z0

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

 z = z.pent(z, c); // Get z1, z2, ...
 // z = z.subtract(z.pow(2), new Complex(0.5,0.5));
 if (z.abs() > 2)
 return i;

 }

 return COUNT_LIMIT; // Indicates a bounded sequence

 }
}

NOTE: Put this in another class.

 public Complex subtract(Complex c) {
 double ex = (this.x - c.x);
 double why = (this.y - c.y);
 return new Complex(ex, why);
 }
 public Complex cubic(Complex z, Complex c) {
 return z.multiply(z).multiply(z).multiply(z).subtract(c);
 }
 public Complex quartic(Complex z, Complex c) {
 return z.multiply(z).multiply(z).multiply(z).multiply(z).subtract(c);
 }
 public Complex pent(Complex z, Complex c) {
 return z.multiply(z).multiply(z).multiply(z).multiply(z).multiply(z).subtract(c);
 }
 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);
}

 

Advertisements