0

As in the title , i want to add 2-3 colors with shades to my Julia set . But I dont have any idea how to do it . I know how to add 1 color , and i do it . But i must to add 2-3.

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import javax.swing.JApplet;

public class ComplexTester extends JApplet {
    Color c;

    public void init() {

        resize(600, 600);
    }

    public Color setC1() {
        c = new Color(250, 250, 0);
        return c;
    }

    public void paint(Graphics g) {

        Random generator = new Random();

        Complex c = new Complex(-0.123, 0.745);
        Complex b = new Complex();

        for (int k = 0; k < 600; k++)
            for (int j = 0; j < 600; j++) {

                Complex a = new Complex((k / 200.0) - 1.5,
                        (600 - j) / 200.0 - 1.5);
                int i = 0;
                b = a;

                do {
                    b = b.kwadrat().dodaj(c);
                    i++;
                    if (b.moduł2().getX() > 2)
                        break;

                } while (i < 30);

                if (i == 30) {

                    g.setColor(setC2());

                    g.drawOval(k, j, 1, 1);

                }
            }
    }
}

setColor() method add only one color . Is any methor which add few colors ?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2344333
  • 147
  • 1
  • 1
  • 9
  • 1
    Don't override the paint() method of a top level container like JApplet. Custom painting is done by override the `paintComponent()` method of a JPanel (or JComponent) and then you add the panel to the applet. And don't forget to invoke super.paintComponent(...) at the start of the method. – camickr May 21 '13 at 15:04

1 Answers1

2

You can create a fixed palette of colors using an enum, as shown here and here. In this case, you might want to create a gamut of colors using getHSBColor(), as shown here in List<Color>. A related example using Queue<Color> may be found here. Once you have such a collection, you would chose the color by index based on the number of iterations required.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045