Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import se.lth.cs.ptdc.fractal.MandelbrotGUI;
- import java.awt.Color;
- public class Generator {
- public Generator(MandelbrotGUI gui) {
- }
- public void render(MandelbrotGUI gui) {
- gui.disableInput();
- int resDiff = 1;
- switch(gui.getResolution()) {
- case MandelbrotGUI.RESOLUTION_VERY_HIGH:
- resDiff = 1;
- break;
- case MandelbrotGUI.RESOLUTION_HIGH:
- resDiff = 3;
- break;
- case MandelbrotGUI.RESOLUTION_MEDIUM:
- resDiff = 5;
- break;
- case MandelbrotGUI.RESOLUTION_LOW:
- resDiff = 7;
- break;
- case MandelbrotGUI.RESOLUTION_VERY_LOW:
- resDiff = 9;
- break;
- }
- Complex[][] complex = mesh(gui.getMinimumReal(),
- gui.getMaximumReal(),
- gui.getMinimumImag(),
- gui.getMaximumImag(),
- gui.getWidth(),
- gui.getHeight());
- Color[][] picture = new Color[gui.getHeight() / resDiff + 1][gui.getWidth() / resDiff + 1];
- for (int i = resDiff / 2; i < gui.getHeight(); i += resDiff) {
- for (int j = resDiff / 2; j < gui.getWidth(); j += resDiff) {
- Complex c = complex[i][j];
- if (c.getAbs2() > 1)
- picture[i / resDiff][j / resDiff] = Color.WHITE;
- else if (c.re > 0 && c.im >= 0)
- picture[i / resDiff][j / resDiff] = Color.RED;
- else if (c.re < 0 && c.im >= 0)
- picture[i / resDiff][j / resDiff] = Color.BLUE;
- else if (c.re > 0 && c.im <= 0)
- picture[i / resDiff][j / resDiff] = Color.YELLOW;
- else if (c.re < 0 && c.im <= 0)
- picture[i / resDiff][j / resDiff] = Color.GREEN;
- }
- }
- gui.putData(picture, resDiff, resDiff);
- gui.enableInput();
- }
- private Complex[][] mesh(double minRe, double maxRe, double minIm,
- double maxIm, int width, int height) {
- Complex[][] complex = new Complex[height][width];
- double resRe = (maxRe - minRe) / width;
- double resIm = (maxIm - minIm) / height;
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- complex[i][j] = new Complex(minRe + j * resRe, maxIm - i * resIm);
- return complex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement