Java – generate fractal rotation

I need to use the algorithm iterated function system to draw fractal vortices

This fractal has coefficients:

0.745455 -0.459091  0.406061  0.887121 1.460279 0.691072 0.912675
-0.424242 -0.065152 -0.175758 -0.218182 3.809567 6.741476 0.087325

Here is my code:

import java.awt.Graphics;
import javax.swing.JPanel;

public class Surface extends JPanel {
double a1 = 0.745455;
double b1 = -0.459091;
double d1 = 0.406061;
double e1 = 0.887121;
double c1 = 1.460279;
double f1 = 0.691072;
double p1 = 0.912675;

double a2 = -0.424242;
double b2 = -0.065152;
double d2 = -0.175758;
double e2 = -0.218182;
double c2 = 3.809567;
double f2 = 6.741476;
double p2 = 0.087325;

double x1(double x,double y) {
    return a1 * x + b1 * y + c1;
}

double y1(double x,double y) {
    return d1 * x + e1 * y + f1;
}

double x2(double x,double y) {
    return a2 * x + b2 * y + c2;
}

double y2(double x,double y) {
    return d2 * x + e2 * y + f2;
}

public void paint(Graphics g) {
    drawFractal(g);
}

void drawFractal(Graphics g) {
    double x1 = 300;
    double y1 = 300;
    double x2 = 0;
    double y2 = 0;
    g.fillOval(300 + (int) x1,300 + (int) y1,3,3);
    for (int i = 0; i < 10000; i++) {
        double p = Math.random();
        if (p < 0.91675) {
            x2 = x1(x1,y1);
            y2 = y1(x1,y1);
            g.fillOval(300 + (int) x2,300 + (int) y2,3);
            x1 = x2;
            y1 = y2;
        } else {
            x2 = x2(x1,y1);
            y2 = y2(x1,3);
            x1 = x2;
            y1 = y2;
        }
    }
}
}

Unfortunately, using this code, I get a wrong picture:

It would be great if someone could point out my mistake

Solution

Your generation seems to be right (i.e. don't do X1 = x2 300; Y1 = Y2 300;), But your problem is to leave scale for rendering purposes This means that few points fall outside the center of the image

Your window is [0.. 600] x [0.. 600] Try multiplying x2 and Y2 by 50 so that you render the space of the [- 6.. 6] x [- 6.. 6] area instead of the [- 300.. 300] x [- 300.. 300] area

Notice that you draw a single pixel (as your own row) instead of 3 × The ellipse should be sufficient

int xp = 300 + (int) (x2 * scale);
int yp = 300 + (int) (y2 * scale);
g.drawLine(xp,yp,xp,yp);

Depending on what is rendered, you may need to adjust the scale slightly to get the whole image with a reasonable boundary Note that the second transform offset is - 6.7, so the scale of 30 should be correct

Also note that by using X1 = x2 300; y1 = y2 300; You change the transformation and get a different fractal (in the proportion you want)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>