Skip to content

Commit

Permalink
Issue #48 Split Mandelbrot-Tab into Mandelbrot-Julia and Mandelbrot-Zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswoehlke committed Oct 11, 2020
1 parent 6fe17eb commit c47cce5
Show file tree
Hide file tree
Showing 28 changed files with 133 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal;
package org.woehlke.computer.kurzweil.commons.model.fractal;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal;
package org.woehlke.computer.kurzweil.commons.model.fractal;

import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.MandelbrotModel;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.extern.log4j.Log4j2;
import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
import org.woehlke.computer.kurzweil.commons.tabs.TabModel;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.state.MandelbrotTabStateMachine;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.MandelbrotTuringMachine;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;

import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.MandelbrotModel;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.woehlke.computer.kurzweil;

import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotTab;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotZoomTab;

import java.io.File;
import java.net.URL;
Expand All @@ -20,7 +20,7 @@ private MandelbrotZoomApplication() {
URL fileUrl = getClass().getResource(configFileName);
File configFile = new File(fileUrl.getFile());
ComputerKurzweilProperties properties = ComputerKurzweilProperties.propertiesFactory(configFile);
MandelbrotTab frame = new MandelbrotTab(properties);
MandelbrotZoomTab frame = new MandelbrotZoomTab(properties);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal;
package org.woehlke.computer.kurzweil.commons.model.fractal;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal;
package org.woehlke.computer.kurzweil.commons.model.fractal;

import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotModel;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotZoomModel;
import org.woehlke.computer.kurzweil.commons.model.turing.Point;

import java.util.ArrayDeque;
import java.util.Deque;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class GaussianNumberPlane {

//public static Logger log = Logger.getLogger(GaussianNumberPlane.class.getName());

public GaussianNumberPlane(MandelbrotModel model) {
public GaussianNumberPlane(MandelbrotZoomModel model) {
this.worldDimensions = model.getWorldDimensions();
this.lattice = new int[worldDimensions.getWidth()][worldDimensions.getHeight()];
this.complexWorldDimensions = new ComplexNumber(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;
package org.woehlke.computer.kurzweil.commons.model.turing;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand All @@ -9,7 +9,7 @@
*
* Created by tw on 18.08.15.
*/
public enum TuringDirection {
public enum MandelbrotTuringDirection {
UP,
RIGHT,
DOWN,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;
package org.woehlke.computer.kurzweil.commons.model.turing;

import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotModel;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.MandelbrotZoomModel;
import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand All @@ -16,13 +16,13 @@
public class MandelbrotTuringMachine {

private volatile GaussianNumberPlane gaussianNumberPlane;
private volatile TuringPositions turingPositions;
private volatile TuringPhaseState turingPhaseState;
private volatile MandelbrotTuringPositions turingPositions;
private volatile MandelbrotTuringPhaseState turingPhaseState;

public MandelbrotTuringMachine(MandelbrotModel model) {
public MandelbrotTuringMachine(MandelbrotZoomModel model) {
this.gaussianNumberPlane = model.getGaussianNumberPlane();
this.turingPhaseState = new TuringPhaseState();
this.turingPositions = new TuringPositions(model.getWorldDimensions());
this.turingPhaseState = new MandelbrotTuringPhaseState();
this.turingPositions = new MandelbrotTuringPositions(model.getWorldDimensions());
start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;
package org.woehlke.computer.kurzweil.commons.model.turing;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand All @@ -9,7 +9,7 @@
*
* Created by tw on 18.08.15.
*/
public enum TuringPhase {
public enum MandelbrotTuringPhase {
SEARCH_THE_SET,
WALK_AROUND_THE_SET,
FILL_THE_OUTSIDE_WITH_COLOR,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.woehlke.computer.kurzweil.commons.model.turing;

/**
* Mandelbrot Set drawn by a Turing Machine.
*
* (C) 2006 - 2015 Thomas Woehlke.
* https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html
* @author Thomas Woehlke
*
* Created by tw on 16.12.2019.
*/
public class MandelbrotTuringPhaseState {

private volatile MandelbrotTuringPhase turingTuringPhase;

public MandelbrotTuringPhaseState() {
start();
}

public void start(){
this.turingTuringPhase = MandelbrotTuringPhase.SEARCH_THE_SET;
}

public void finishSearchTheSet(){
turingTuringPhase = MandelbrotTuringPhase.WALK_AROUND_THE_SET;
}

public void finishWalkAround() {
turingTuringPhase = MandelbrotTuringPhase.FILL_THE_OUTSIDE_WITH_COLOR;
}

public void finishFillTheOutsideWithColors() {
turingTuringPhase = MandelbrotTuringPhase.FINISHED;
}

public MandelbrotTuringPhase getTuringTuringPhase() {
return turingTuringPhase;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;
package org.woehlke.computer.kurzweil.commons.model.turing;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand All @@ -9,25 +9,25 @@
*
* Created by tw on 16.12.2019.
*/
public class TuringPositions {
public class MandelbrotTuringPositions {

private volatile Point turingPosition;
private volatile Point worldDimensions;
private volatile Point firstSetPosition;

private volatile TuringDirection turingDirection;
private volatile MandelbrotTuringDirection turingDirection;

private volatile int steps;

public TuringPositions(Point worldDimensions) {
public MandelbrotTuringPositions(Point worldDimensions) {
this.worldDimensions = worldDimensions;
start();
}

public void start() {
this.steps = 0;
this.turingPosition = new Point((worldDimensions.getX()-2),(worldDimensions.getY()/2+11));
this.turingDirection = TuringDirection.LEFT;
this.turingDirection = MandelbrotTuringDirection.LEFT;
}

public synchronized void markFirstSetPosition(){
Expand Down Expand Up @@ -60,24 +60,24 @@ public synchronized void goForward() {
}

public synchronized void turnRight() {
TuringDirection newTuringDirection;
MandelbrotTuringDirection newTuringDirection;
switch (this.turingDirection){
case UP: newTuringDirection = TuringDirection.RIGHT; break;
case RIGHT: newTuringDirection = TuringDirection.DOWN; break;
case DOWN: newTuringDirection = TuringDirection.LEFT; break;
case LEFT: newTuringDirection = TuringDirection.UP; break;
case UP: newTuringDirection = MandelbrotTuringDirection.RIGHT; break;
case RIGHT: newTuringDirection = MandelbrotTuringDirection.DOWN; break;
case DOWN: newTuringDirection = MandelbrotTuringDirection.LEFT; break;
case LEFT: newTuringDirection = MandelbrotTuringDirection.UP; break;
default: newTuringDirection = this.turingDirection; break;
}
this.turingDirection = newTuringDirection;
}

public synchronized void turnLeft() {
TuringDirection newTuringDirection;
MandelbrotTuringDirection newTuringDirection;
switch (this.turingDirection){
case UP: newTuringDirection = TuringDirection.LEFT; break;
case RIGHT: newTuringDirection = TuringDirection.UP; break;
case DOWN: newTuringDirection = TuringDirection.RIGHT; break;
case LEFT: newTuringDirection = TuringDirection.DOWN; break;
case UP: newTuringDirection = MandelbrotTuringDirection.LEFT; break;
case RIGHT: newTuringDirection = MandelbrotTuringDirection.UP; break;
case DOWN: newTuringDirection = MandelbrotTuringDirection.RIGHT; break;
case LEFT: newTuringDirection = MandelbrotTuringDirection.DOWN; break;
default: newTuringDirection = this.turingDirection; break;
}
this.turingDirection = newTuringDirection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing;
package org.woehlke.computer.kurzweil.commons.model.turing;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* Date: 05.02.2006
* Time: 00:51:51
*/
public class MandelbrotCanvas extends JComponent {
public class MandelbrotZoomCanvas extends JComponent {

private volatile MandelbrotModel app;
private volatile MandelbrotZoomModel app;
private volatile Dimension preferredSize;

public MandelbrotCanvas(MandelbrotModel app) {
public MandelbrotZoomCanvas(MandelbrotZoomModel app) {
this.app = app;
int width = this.app.getWorldDimensions().getWidth();
int height = this.app.getWorldDimensions().getHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
* Date: 05.02.2006
* Time: 00:36:20
*/
public class MandelbrotController extends Thread implements Runnable {
public class MandelbrotZoomController extends Thread implements Runnable {

private volatile MandelbrotModel mandelbrotModel;
private volatile MandelbrotTab frame;
private volatile MandelbrotZoomModel mandelbrotModel;
private volatile MandelbrotZoomTab frame;

private final int THREAD_SLEEP_TIME = 1;

private volatile Boolean goOn;

public MandelbrotController(MandelbrotModel model, MandelbrotTab frame) {
public MandelbrotZoomController(MandelbrotZoomModel model, MandelbrotZoomTab frame) {
this.frame = frame;
this.mandelbrotModel = model;
goOn = Boolean.TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import lombok.Getter;
import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.state.ApplicationStateMachine;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.MandelbrotTuringMachine;
import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;
import org.woehlke.computer.kurzweil.commons.model.turing.Point;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.state.TabStateMachine;
import org.woehlke.computer.kurzweil.commons.model.turing.MandelbrotTuringMachine;

/**
* Mandelbrot Set drawn by a Turing Machine.
Expand All @@ -17,21 +17,21 @@
* Created by tw on 16.12.2019.
*/
@Getter
public class MandelbrotModel {
public class MandelbrotZoomModel {

private volatile GaussianNumberPlane gaussianNumberPlane;
private volatile MandelbrotTuringMachine mandelbrotTuringMachine;
private volatile ApplicationStateMachine applicationStateMachine;
private volatile TabStateMachine applicationStateMachine;

private volatile ComputerKurzweilProperties properties;
private volatile MandelbrotTab frame;
private volatile MandelbrotZoomTab frame;

public MandelbrotModel(ComputerKurzweilProperties properties, MandelbrotTab frame) {
public MandelbrotZoomModel(ComputerKurzweilProperties properties, MandelbrotZoomTab frame) {
this.properties = properties;
this.frame = frame;
this.gaussianNumberPlane = new GaussianNumberPlane(this);
this.mandelbrotTuringMachine = new MandelbrotTuringMachine(this);
this.applicationStateMachine = new ApplicationStateMachine();
this.applicationStateMachine = new TabStateMachine();
}

public synchronized boolean click(Point c) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public GaussianNumberPlane getGaussianNumberPlane() {
return gaussianNumberPlane;
}

public MandelbrotTab getFrame() {
public MandelbrotZoomTab getFrame() {
return frame;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.canvas.PanelButtons;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.canvas.PanelCopyright;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.canvas.PanelSubtitle;
import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
import org.woehlke.computer.kurzweil.commons.model.turing.Point;

import javax.accessibility.Accessible;
import javax.swing.*;
Expand All @@ -20,25 +20,25 @@
* Date: 04.02.2006
* Time: 18:47:46
*/
public class MandelbrotTab extends JFrame implements ImageObserver,
public class MandelbrotZoomTab extends JFrame implements ImageObserver,
MenuContainer,
Serializable,
Accessible,
WindowListener,
MouseListener {

private volatile MandelbrotController mandelbrotController;
private volatile MandelbrotCanvas canvas;
private volatile MandelbrotModel mandelbrotModel;
private volatile MandelbrotZoomController mandelbrotController;
private volatile MandelbrotZoomCanvas canvas;
private volatile MandelbrotZoomModel mandelbrotModel;
private volatile Rectangle rectangleBounds;
private volatile Dimension dimensionSize;

public MandelbrotTab(ComputerKurzweilProperties properties) {
public MandelbrotZoomTab(ComputerKurzweilProperties properties) {
super(properties.getMandelbrot().getView().getTitle());
this.mandelbrotModel = new MandelbrotModel(properties,this);
this.mandelbrotModel = new MandelbrotZoomModel(properties,this);
BoxLayout layout = new BoxLayout(rootPane, BoxLayout.PAGE_AXIS);
this.canvas = new MandelbrotCanvas(mandelbrotModel);
this.mandelbrotController = new MandelbrotController(mandelbrotModel, this);
this.canvas = new MandelbrotZoomCanvas(mandelbrotModel);
this.mandelbrotController = new MandelbrotZoomController(mandelbrotModel, this);
PanelButtons panelButtons = new PanelButtons(this.mandelbrotModel);
PanelSubtitle panelSubtitle = new PanelSubtitle(properties.getMandelbrot().getView().getSubtitle());
PanelCopyright panelCopyright = new PanelCopyright(properties.getAllinone().getView().getCopyright());
Expand Down Expand Up @@ -141,7 +141,7 @@ public void setModeZoom() {
canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
}

public MandelbrotCanvas getCanvas() {
public MandelbrotZoomCanvas getCanvas() {
return canvas;
}
}
Loading

0 comments on commit c47cce5

Please sign in to comment.