Question
I have the java program mandelbrot program below, but I don't want the axis showing. How can I correct this? And are there any way
I have the java program mandelbrot program below, but I don't want the axis showing. How can I correct this? And are there any way to create a menu that pops up first asking for the initial values Re, Im, length and color, so they are not prompted in the main script?
import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
import javax.swing.JOptionPane;
public class Mandelbrot { public static final int COLORDEPTH=256; public static final int GRID=768; private static double Re; private static double Im; private static double length; private static int[][] drawingData; private static int MAX = 255; private static Complex[][] complexGrid; public static void main(String[] args) throws FileNotFoundException { Re =-0.5; Im=0; length=2; int[][] colors = loadColors("blues.mnd"); Draw(colors); } public static void setCanvas(){ StdDraw.setCanvasSize(GRID, GRID); StdDraw.setXscale(0,GRID-1); StdDraw.setYscale(0,GRID-1); StdDraw.setPenRadius(1.0/GRID); StdDraw.text(GRID/2,GRID/2, "Creating mandelbrot."); StdDraw.show(0); } public static Complex[][] ComplexGrid(Complex center, double length){ Complex[][] Grid = new Complex[GRID][GRID]; for ( int j = 0; j
public static void Draw(int[][] colors){ setCanvas(); Complex center = new Complex(Re, Im); complexGrid = ComplexGrid(center, length); drawingData = getDrawingData(); drawMandelbrot(drawingData, colors); } public static int[][] getDrawingData(){ int[][] drawingData = new int[GRID][GRID]; for (int i=0; i for (int j=0; j drawingData[i][j]=(int)(Iterate(complexGrid[i][j])/((double)MAX/((double)COLORDEPTH-1))); } } return drawingData; }
public static void drawMandelbrot(int drawingData[][], int colors[][]){ StdDraw.clear(); for (int i=0; i for (int j=0; j if(colors!=null){ StdDraw.setPenColor(new Color(colors[drawingData[i][j]][0], colors[drawingData[i][j]][1], colors[drawingData[i][j]][2])); } else { StdDraw.setPenColor(new Color(drawingData[i][j], drawingData[i][j], drawingData[i][j])); //Equal amounts of R, G and B gives a grayscale } StdDraw.point(i, j); } } StdDraw.show(0); } public static int Iterate(Complex z0) { Complex z = new Complex(z0); for (int i = 0; i 2.0) { return i; } z = z.times(z).plus(z0); } return MAX; } public static int[][] loadColors(String filename) throws FileNotFoundException{ int[][] colors = new int[COLORDEPTH][3]; if (filename.equals("")){ return null; } File colorFile = new File("src" + File.separator + "mnd" + File.separator + filename); if(!colorFile.exists()){ System.out.print("Invalid filename! Mandelbrot is drawn without colors"); JOptionPane.showMessageDialog(null,"Invalid filename! Mandelbrot is drawn without colors","No such file!",JOptionPane.WARNING_MESSAGE); return null; } Scanner fileScanner = new Scanner(colorFile); //The following code assumes a properly formatted color file for (int i=0; i for (int j=0; j
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started