@Override
    public void paintComponent(Graphics g) {

        int thisWidth = getWidth();
        int thisHeight = getHeight();


        /* Only compute the color for each pixel value if the height or width
         * has changed OR if the mustRepaint flag is TRUE (e.g. when the value
         * of maxIterations has changed and the image hasn't been recomputed.
         */

        if (thisWidth != width || thisHeight != height || mustRepaint) {
            mustRepaint = false;

            width = thisWidth;
            height = thisHeight;
            makeNewImage();

            Graphics2D gc = (Graphics2D) image.getGraphics();
            int iteration;

            float luminosity;
            float saturation = 1.0f;
            float color;

            double xTemp;
            double x, y;
            double x0, y0;
            int c, r;


            double yRange = yEnd - yStart;
            double xRange = xEnd - xStart;

            for (c = 0; c < thisHeight; c++) {
                // y scaled to be in interval (-1, 1)
                y0 = (yRange * c / thisHeight) + yStart;

                for (r = 0; r < thisWidth; r++) {
                    // x scaled to be in interval(-2.5, 1)
                    x0 = (xRange * r / thisWidth) + xStart;

                    x = 0;
                    y = 0;
                    iteration = 0;
                    while (iteration < maxIteration && x*x + y*y <= (2*2)) {
                        xTemp = x*x - y*y + x0;
                        y = 2*x*y + y0;

                        x = xTemp;
                        iteration++;
                    }

                    if (iteration == maxIteration) {
                        color = 0f;
                        luminosity = 0f;
                    } else {
                        // scale color to range of 0 to 1
                        color = (float) iteration / maxIteration;
                        luminosity = 1f;
                    }

                    Color colorInstance = Color.getHSBColor(color, saturation, luminosity);

                    image.setRGB(r, c, colorInstance.getRGB());
                    //                    gc.setColor(colorInstance);
                    //                    gc.fillRect(r, c, 1, 1);
                }
            }
            applyHueOffset();

        }



        g.drawImage(outputImage, 0, 0, null);


        if (drawingBox) {
            int zoomW = zoomX1 - zoomX0;
            int zoomH = zoomY1 - zoomY0;

            g.setColor(Color.white);

            g.drawRect(zoomX0, zoomY0, zoomW, zoomH);

        }

        Toolkit tk = Toolkit.getDefaultToolkit();
        tk.sync();

//        System.out.printf("Finished drawing for %dx%d.\n", thisWidth, thisHeight);
    }