我真的被卡住了,并且出于这个想法,我应该画一个圆圈,这很好。但它可以用不同的分辨率来绘制,而且我无处可去,请帮助!我在这里展示的代码并不是试图使用不同的解决方案,但我不知道该怎么做。画一个低分辨率的圈子
我会安排我遇到麻烦的课程,然后我会安排课程的其余部分。还有一个简要说明,该程序稍后将用于Mandlebrot套件。
问题是,圆形在高分辨率下工作正常,但是一旦我尝试减少它,我会得到奇怪的线条样式,就像它只绘制某些线条,然后绘制它不应该的线条, m怀疑问题是方法render()
。我也怀疑这个问题更具体的是for循环,或者是我的向量的索引。如果我不清楚我的解释,请告诉我。
的RESOLUTION_VERY_HIGH到RESOLUTION_VERY_LOW具有值2048,1024,...,128
package mandelbrot;
import java.awt.Color;
import se.lth.cs.ptdc.fractal.MandelbrotGUI;
public class Generator {
public Generator() {
}
public void render(MandelbrotGUI w) {
w.disableInput();
int resolution = 1;
switch (w.getResolution()) {
case MandelbrotGUI.RESOLUTION_VERY_HIGH:
resolution = 1;
break;
case MandelbrotGUI.RESOLUTION_HIGH:
resolution = 3;
break;
case MandelbrotGUI.RESOLUTION_MEDIUM:
resolution = 5;
break;
case MandelbrotGUI.RESOLUTION_LOW:
resolution = 7;
break;
case MandelbrotGUI.RESOLUTION_VERY_LOW:
resolution = 9;
break;
}
Complex complex[][] = mesh(w.getMinimumReal(), w.getMaximumReal(), w.getMinimumImag(),
w.getMaximumImag(), w.getWidth(), w.getHeight());
Color[][] picture = new Color[w.getHeight()][w.getWidth()];
for (int i = 0; i<w.getHeight(); i+=resolution) {
for (int j = 0; j<w.getWidth(); j+=resolution) {
if ((complex[i][j]).getAbs()>1) {
picture[i][j] = Color.WHITE;
}
else {
picture[i][j] = Color.BLUE;
}
}
}
w.putData(picture, 1, 1);
w.enableInput();
}
private Complex[][] mesh(double minReal, double maxReal, double minImaginary,
double maxImaginary, int width, int height) {
Complex[][] matrice = new Complex[height][width];
for (int i = 0; i<height; i++) {
for (int j = 0; j<width; j++) {
matrice[i][j] = new Complex((minReal + ((maxReal-minReal)/width)*j),
((maxImaginary - (((maxImaginary - minImaginary)/height)*i))));
}
}
return matrice;
}
}
我怀疑你需要他们,但这里有其它类;
我的主要;
package mandelbrot;
import se.lth.cs.ptdc.fractal.MandelbrotGUI;
public class Mandelbrot {
public static void main (String[] args) {
MandelbrotGUI w = new MandelbrotGUI();
Generator generator = new Generator();
boolean zoomValue = false;
while (true) {
switch(w.getCommand()) {
case MandelbrotGUI.QUIT: System.exit(0);
break;
case MandelbrotGUI.RENDER:
generator.render(w);
break;
case MandelbrotGUI.RESET:
w.clearPlane();
w.resetPlane();
zoomValue = false;
break;
case MandelbrotGUI.ZOOM:
if (zoomValue) {
w.clearPlane();
generator.render(w);
break;
}
else {break;}
}
}
}
}
这里是我写的Complex类;
package mandelbrot;
public class Complex {
double real;
double imaginary;
public Complex (double real, double imaginary) {
this.real = real;
this.imaginary = imaginary;
}
double getReal() {
return real;
}
double getImaginary() {
return imaginary;
}
double getAbs() {
return Math.hypot(real, imaginary);
}
void add(Complex c) {
real += c.getReal();
imaginary += c.getImaginary();
}
void multiply(Complex c) {
real = (real*c.getReal()) - (imaginary*c.getImaginary());
imaginary = (real*c.getImaginary()) + (imaginary*c.getReal());
}
}
您可以在这里找到GUI的规范; http://fileadmin.cs.lth.se/cs//Education/EDA016/javadoc/cs_eda016_doc/
感谢您的任何帮助,非常感谢! :)
你不会碰巧有一个链接到GUI类的来源吗?不是必需的,但是如果你能够清楚地看到你在说什么,并且可以从规范中复制,那么调试就会变得更加容易,那就是很多输入。 :) – 2014-12-02 00:35:50
圆和Mandelbrot分形有什么共同点?如果我必须画一个圆,我会使用正弦和余弦函数,这会产生一个_true_圆。 – karatedog 2014-12-02 11:21:40