MSet.javapackage RainsMSet;import java.awt.*;
import java.util.ArrayList;/**
 * Created by IntelliJ IDEA.
 * User: Rains.C
 * Date: 11-4-8
 * Time: 下午4:29
 * To change this template use File | Settings | File Templates.
 */
public class MSet {
    public MSet(int maxIteration) {
        this.maxIteration = maxIteration;
    }    //public strictfp MSet generate() {
    public MSet generate() {
        result = new ArrayList<Color[]>();
        int iteration = 0;
        double screenX, screenY;
        double xStep = 3.5 / WIDTH;
        double yStep = 2.0 / HEIGHT;
        screenX = -2.5;
        screenY = -1;
        double x = 0;
        double y = 0;
        double xTemp = 0;
        int index = 0;
        while (screenY <= 1.0) {
            Color[] colors = new Color[WIDTH + 1];
            result.add(colors);
            screenX = -2.5;
            index = 0;
            while (screenX <= 1.0) {
                x = y = iteration = 0;
                while (x * x + y * y <= 2 * 2.0 && iteration < maxIteration) {
                    xTemp = x * x - y * y + screenX;
                    y = 2 * x * y + screenY;
                    x = xTemp;
                    iteration += 1;
                }
                colors[index] = DEFAULT_COLORS[(iteration - 1) * DEFAULT_COLORS.length / maxIteration];
                screenX += xStep;
                index += 1;
            }
            screenY += yStep;
        }
        return this;
    }    public ArrayList<Color[]> getResult() {
        return result;
    }    private ArrayList<Color[]> result;
    private int maxIteration;    public static final int WIDTH = 1000;
    public static final int HEIGHT = 600;
    public static final Color[] DEFAULT_COLORS =
            {
                    Color.BLACK, Color.BLUE, Color.PINK, Color.RED,
                    Color.YELLOW, Color.GREEN, Color.WHITE
            };
}MSetPlane.javapackage RainsMSet;import javax.swing.*;
import java.awt.*;
import java.awt.geom.Line2D;
import java.util.ArrayList;/**
 * Created by IntelliJ IDEA.
 * User: Rains.C
 * Date: 11-4-8
 * Time: 下午4:57
 * To change this template use File | Settings | File Templates.
 */
public class MSetPlane extends JComponent{
    public MSetPlane(int maxIteration) {
        this.maxIteration = maxIteration;
    }    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        MSet mSet = new MSet(maxIteration);
        ArrayList<Color[]> result = mSet.generate().getResult();
        int height = 0;
        for(Color[] colors : result) {
            for(int i = 0; i < MSet.WIDTH; i += 1) {
                g2.setPaint(colors[i]);
                g2.draw(new Line2D.Double(i, height, i, height));
            }
            height += 1;
        }
    }    private int maxIteration;    public static void main(String [] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame f = new JFrame("MSetPlane");
                f.add(new MSetPlane(100));
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setSize(MSet.WIDTH + 20, MSet.HEIGHT + 40);
                f.setVisible(true);
            }
        });
    }
}PS:
不知道怎么上图,好像发帖还要我给分,可是这不是一个问题贴,不知道怎么办……似乎悖论又开始了