JAVA笛卡尔曲线
效果图如下:
1 import java.applet.*; 2 import java.awt.*; 3 4 public class Descartes extends Applet 5 { 6 int AppletWidth,AppletHeight; 7 Image OffScreen; 8 Graphics drawOffScreen; 9 public void init() 10 { 11 setBackground(Color.black); //设置背景为黑色 12 AppletWidth = getSize().width * 2; //获取applet的宽度 13 AppletHeight = getSize().height * 2; //获取appplet的高度 14 OffScreen = createImage(AppletWidth,AppletHeight); //创建一副使用了双缓冲技术的不可见的画布 15 drawOffScreen = OffScreen.getGraphics(); 16 } 17 public void paint(Graphics g) 18 { 19 //设置前景色为白色 20 drawOffScreen.clearRect(0,0,AppletWidth,AppletHeight); 21 drawOffScreen.setColor(Color.white); 22 double x,y,r; 23 for(int i=0; i<=90 ; i++) 24 { 25 for(int j=0; j<=90; j++) 26 { 27 r=Math.PI / 45 * i * ( 1 - Math.sin(Math.PI / 45 * j)) * 18; 28 x = r * Math.cos(Math.PI / 45 * j) * Math.sin(Math.PI / 45 * i)+AppletWidth / 2; 29 y = -r*Math.sin(Math.PI / 45 * j) + AppletHeight / 4; 30 drawOffScreen.fillOval((int)x,(int)y,2,2); //绘制椭圆形 31 } 32 } 33 g.drawImage(OffScreen,0,0,this); //生成图片 34 } 35 }
把每一件简单的事情做好,就是不简单;把每一件平凡的事情做好,就是不平凡!相信自己,创造奇迹~~