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:
不知道怎么上图,好像发帖还要我给分,可是这不是一个问题贴,不知道怎么办……似乎悖论又开始了
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:
不知道怎么上图,好像发帖还要我给分,可是这不是一个问题贴,不知道怎么办……似乎悖论又开始了
解决方案 »
- 点击html能够运行applet,applerviewer无法运行,提示NoClassDeffoundError。在线等.............
- 怎么用正则表达式得到绝对路径的文件名和路径名?
- 20分,JTable中如何返回选中的行.谢谢.
- 帮帮我!画直线和画矩形混在一块了!<很简短的代码>
- 请教一个小问题,谢谢了
- 请问如何判断文件的行数?谢谢!
- 好几天都没头绪,查询按钮在jtable显示问题???
- 那里有Java可视化开发环境可下载,同时带有文档说明更好,谢谢
- snoopy学Java之JB8
- java的大数BigInteger最多可以存多少位数?
- j2se平台写的程序我想放到 win ce 的机子上运行
- 菜鸟求助 PKU 1002 runtime error 什么情况啊!!
或者到灌水区