我真的被卡住了,並且出於這個想法,我應該畫一個圓圈,這很好。但它可以用不同的分辨率來繪製,而且我無處可去,請幫助!我在這裏展示的代碼並不是試圖使用不同的解決方案,但我不知道該怎麼做。畫一個低分辨率的圈子
我會安排我遇到麻煩的課程,然後我會安排課程的其餘部分。還有一個簡要說明,該程序稍後將用於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