利用Java的对象,继承,重绘,多态来绘画Wallpaper
程序员文章站
2022-07-15 08:44:53
...
利用Java的对象,继承,重绘,多态来绘画Wallpaper.
package FirstJavachengxu; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; @SuppressWarnings("serial") public class FirstJavachengxu extends JFrame { private Graphics g; private double //a = 0.4, b = 1, c = 0; a = 1, b = 4, c = 60; //a = -1000, b = 0.1, c = -10; //a = -1,b = -2, c = -3; public static void main(String[] args) { FirstJavachengxu show = new FirstJavachengxu(); show.Init(); } public void Init() { // 设置标题 this.setTitle("Wallpaper"); // 设置窗体大小 this.setSize(1200, 1000); // 给窗体设置背景 this.getContentPane().setBackground(Color.black); // 窗体显示 this.setVisible(true); g = this.getGraphics(); } public void paint(Graphics g) { // 调用父类的paint方法,用来绘制窗体 super.paint(g); System.out.println("my name is luozhong"); // xn+1 = yn - sign(xn) | b xn - c |1/2 // yn+1 = a - xn double x = 0f, y = 0f; // g.setColor(Color.CYAN); g.setColor(Color.pink); int tiems = 0; while (tiems < 600000000) { tiems++; // xn+1 = yn - sign(xn) | b xn - c |1/2 // yn+1 = a - xn double temx = y - Math.signum(x) * Math.sqrt(Math.abs(b * x - c)); double temy = a - x; // double temx=y-Math.signum(x)*Math.sqrt(Math.abs(b*x-c)); // double temy=a-x; System.out.println("x1=" + x); System.out.println("y1=" + y); System.out.println("temx=" + temx); System.out.println("temy=" + temy); double x1 = temx * 未知数 + 600; double y1 = temy * 未知数 + 300; g.drawLine((int) x1, (int) y1, (int) x1, (int) y1); x = temx; y = temy; } } } 注意:未知数关系到图像的清晰,不会挤在一起。未知数为图像像素的松弛度。 The URL of Wallpaper is http://paulbourke.net/fractals/wallpaper/.
运行结果:
上一篇: 优先队列与堆的解析