Julia 在 Java 中的 JPanel 上设置渲染 - 仅对一个像素着色

Julia Set Rendering on JPanel in Java - colours only one Pixel

我正在尝试编写一个程序来呈现 Mandelbrot 集,然后在用户单击 Mandelbrot 集面板上的某个点时在另一个面板中呈现复数的 Julia 集。

但是,我的 Julia 设置的渲染代码由于某种原因不起作用。它似乎只为最左上角的像素着色,我不明白为什么会这样。我不知道渲染方法中的数学是否有误,或者着色是否有问题。任何指示或解决方案都会很棒 - 我为此绞尽脑汁了一段时间。

如果有人发现通过所有代码更容易解​​决这个问题,请告诉我 - 谢谢。

这里只是 Julia 的设置面板的代码,其他的都被省略了。

  class juliaPanel extends JPanel {

        ComplexNumber fixedNumber = new ComplexNumber(0,0);
        double newReal, newImaginary, oldReal, oldImaginary;

        public void setFixedNumber(ComplexNumber fixedNumberIn) {
            fixedNumber = fixedNumberIn;
        }

        public void paintComponent(Graphics g){
            super.paintComponent(g);
            newReal = 0;
            newImaginary = 0;
            int i;
            for(int y = 0; y < height; y++) {
                for(int x = 0; x < width; x++) {
                    for (i=0; i< iterationsToDo; i++) {
                        oldReal = newReal;
                        oldImaginary = newImaginary;
                        newReal = oldReal * oldReal - oldImaginary * oldImaginary + fixedNumber.getReal();
                        newImaginary = 2 * oldReal * oldImaginary + fixedNumber.getImaginary();
                        if((newReal * newReal + newImaginary * newImaginary) > 4) break;
                    }
                    if(i == 255){
                        g.setColor(Color.BLACK);
                    }else{
                         g.setColor(Color.getHSBColor(i/100.0F,1F,1F));
                    }
                    g.fillRect(x, y, 1, 1);
                }
            }   
        }

i开始内循环之前,即xy已经变为下一个像素点后,需要根据这个像素点设置初始复数, 像

newReal = minReal + x*deltaReal;
newImag = maxImag - y*deltaImag;

其中 minmax-2.02.0delta4.0/width4.0/height 或者取两者的最小值以获得 1:1 纵横比。