Skip to content

Commit

Permalink
Ensuring grid drawing works when dividing box length by 2 each time
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpollard committed Nov 15, 2018
1 parent c9f1ee5 commit a144bd3
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 85 deletions.
86 changes: 47 additions & 39 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/mandelbrot/ArgandDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public ArgandDiagram(MandelbrotFrame mandelbrotFrame, FractalSet fractalSet, Dra

}

public ArgandDiagram(FractalSet fractalSet, DrawingConditions conditions, FractalColours colours) {
public ArgandDiagram(FractalSet fractalSet, DrawingConditions conditions, FractalColours colours, Dimension size) {

super();

this.setPreferredSize(new Dimension(800, 550));
this.setPreferredSize(size);
this.imgLocation = new Point();
this.fractalImg = new BufferedImage(fractalSet.getDimensions().width, fractalSet.getDimensions().height, BufferedImage.TYPE_INT_RGB);
this.fractalSet = fractalSet;
Expand Down
59 changes: 25 additions & 34 deletions src/mandelbrot/DimensionFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,38 @@

public class DimensionFrame extends JFrame {

JPanel content;

FractalSet fractalSet;

GridArgandDiagram argandDiagram;

JButton nextButton;
Dimension screensize;

int iteration;
int initialStep;
int boxes;
double[] logOfNoBoxes;
double[] logOfSideLengths;

public DimensionFrame(FractalSet fractalSet, FractalColours colours, DrawingConditions conditions) {

super();
super("Box Counting Calculator");

this.setSize(800, 600);
this.setResizable(false);
this.screensize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
this.setPreferredSize(screensize);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setResizable(true);
this.setIconImage(new ImageIcon("src\\images\\icon.png").getImage());
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

this.fractalSet = fractalSet;
this.iteration = 0;
this.initialStep = 512;
this.boxes = 0;

setupComponents(colours, conditions);

this.logOfNoBoxes = new double[argandDiagram.step - 1];
this.logOfSideLengths = new double[argandDiagram.step - 1];
this.logOfNoBoxes = new double[8];
this.logOfSideLengths = new double[8];

this.fractalSet.setDimensions(new Dimension(this.getWidth(), this.getHeight()));
this.fractalSet.iterate(false);
Expand All @@ -44,59 +48,46 @@ public DimensionFrame(FractalSet fractalSet, FractalColours colours, DrawingCond

public void setupComponents(FractalColours colours, DrawingConditions conditions) {

this.content = new JPanel();
this.content.setLayout(new BorderLayout());

this.nextButton = new JButton("Next");
this.nextButton.addActionListener(ae -> updateGridlines());

if (fractalSet.getType() == FractalType.MANDELBROT) conditions.drawJulia = false;
if (fractalSet.getType() == FractalType.JULIA) conditions.drawMandelbrot = false;

conditions.readyToCreateImage = true;
conditions.readyToDrawCoords = false;
conditions.readyToDrawInfo = false;

this.argandDiagram = new GridArgandDiagram(fractalSet, conditions, colours);
this.content.add(argandDiagram, BorderLayout.NORTH);
this.content.add(nextButton, BorderLayout.CENTER);
this.add(content);
this.argandDiagram = new GridArgandDiagram(this, fractalSet, conditions, colours, screensize, initialStep);

this.add(argandDiagram);
this.pack();

}

public void updateGridlines() {

if (!argandDiagram.finished) {
iteration++;
argandDiagram.currentStep /= 2;
argandDiagram.start = true;
updateGrids();
logOfNoBoxes[16 - argandDiagram.step] = Math.log(boxes);
logOfSideLengths[16 - argandDiagram.step] = Math.log(1.0 / argandDiagram.step);
argandDiagram.repaint();
argandDiagram.step--;
}
if (argandDiagram.step == 1) {
argandDiagram.finished = true;
argandDiagram.start = false;
argandDiagram.repaint();
RegressionCalculator dimensionRegression = new RegressionCalculator(logOfSideLengths, logOfNoBoxes);
System.out.println(dimensionRegression.calculateGradient());
logOfNoBoxes[iteration - 1] = Math.log(boxes);
logOfSideLengths[iteration - 1] = Math.log(1.0 / argandDiagram.currentStep);
}
argandDiagram.repaint();

}

public void updateGrids() {

boxes = 0;
for (int y = 0; y < argandDiagram.getHeight(); y += argandDiagram.step - 1) {
for (int y = 0; y < argandDiagram.getHeight(); y += argandDiagram.currentStep - 1) {

for (int x = 0; x < argandDiagram.getWidth(); x += argandDiagram.step - 1) {
for (int x = 0; x < argandDiagram.getWidth(); x += argandDiagram.currentStep - 1) {

boolean found = false;

for (int boxY = y; boxY <= y + argandDiagram.step && boxY < argandDiagram.getHeight() && !found; boxY++) {
for (int boxY = y; boxY <= y + argandDiagram.currentStep - 1 && boxY < argandDiagram.getHeight() && !found; boxY++) {

for (int boxX = x; boxX <= x + argandDiagram.step && boxX < argandDiagram.getWidth() && !found; boxX++) {
for (int boxX = x; boxX <= x + argandDiagram.currentStep - 1 && boxX < argandDiagram.getWidth() && !found; boxX++) {

if (argandDiagram.getColorAtPixel(boxX, boxY).equals(argandDiagram.colours.getInner())) {

Expand Down
Loading

0 comments on commit a144bd3

Please sign in to comment.