【发布时间】:2012-12-10 06:05:39
【问题描述】:
我需要使用算法Iterated Function System 绘制分形漩涡。
这个分形有系数:
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
这是我的代码:
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, 3);
x1 = x2;
y1 = y2;
} else {
x2 = x2(x1, y1);
y2 = y2(x1, y1);
g.fillOval(300 + (int) x2, 300 + (int) y2, 3, 3);
x1 = x2;
y1 = y2;
}
}
}
}
不幸的是,这段代码我得到了一张错误的图片:
如果有人能指出我的错误,那就太好了。
【问题讨论】:
-
系数是否正确完整?
-
局部变量和方法之间的命名冲突可能是个坏主意。
-
当您不仅迭代 10000 次而且迭代 100K 次或 1M 次时会发生什么
-
UmNyobe, 100k - s14.postimage.org/eoweh1zkx/100000.png, 1M - s1.postimage.org/y9wpano3z/1000000.png
-
我从大学的任务中得到了它们,我也在这里看到了它fractalworld.xaoc.ru/IFS_collection(寻找“漩涡”)
标签: java algorithm graph fractals