笛卡尔曲线
发布:老七 日期:2009年10月16日
终于拾起扔了很久的Java书了。唉
不容易啊。先敲敲代码熟悉下。

笛卡尔公式:r = a(1-sin弧度)
笛卡尔公式使用的是极坐标.可以转化为直角坐标..代码如下:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class Descartes extends Applet {
int AppletWidth,AppletHeight;
Image OffScreen;
Graphics drawOffScreen;
public void init() {
setBackground(Color.black);
AppletWidth=getSize().width;
AppletHeight=getSize().height;
OffScreen=createImage(AppletWidth,AppletHeight);
drawOffScreen=OffScreen.getGraphics();
}
public void paint(Graphics g) {
drawOffScreen.clearRect(0,0,AppletWidth,AppletHeight);
drawOffScreen.setColor(Color.blue);
int i,j;
double x,y,r;
for(i=0;i<=90;i++)
for(j=0;j<=90;j++){
r=Math.PI/45*i*(1-Math.sin(Math.PI/45*j))*18;
x=r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45*i)+AppletWidth/2;
y=-r*Math.sin(Math.PI/45*j)+AppletHeight/4;
drawOffScreen.fillOval((int)x,(int)y,2,2);
}
g.drawImage(OffScreen,0,0,this);
}
}
不容易啊。先敲敲代码熟悉下。

笛卡尔公式:r = a(1-sin弧度)
笛卡尔公式使用的是极坐标.可以转化为直角坐标..代码如下:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class Descartes extends Applet {
int AppletWidth,AppletHeight;
Image OffScreen;
Graphics drawOffScreen;
public void init() {
setBackground(Color.black);
AppletWidth=getSize().width;
AppletHeight=getSize().height;
OffScreen=createImage(AppletWidth,AppletHeight);
drawOffScreen=OffScreen.getGraphics();
}
public void paint(Graphics g) {
drawOffScreen.clearRect(0,0,AppletWidth,AppletHeight);
drawOffScreen.setColor(Color.blue);
int i,j;
double x,y,r;
for(i=0;i<=90;i++)
for(j=0;j<=90;j++){
r=Math.PI/45*i*(1-Math.sin(Math.PI/45*j))*18;
x=r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45*i)+AppletWidth/2;
y=-r*Math.sin(Math.PI/45*j)+AppletHeight/4;
drawOffScreen.fillOval((int)x,(int)y,2,2);
}
g.drawImage(OffScreen,0,0,this);
}
}
评论: 5 | 引用: 0 | 浏览:
连接已通过
本来整理中目前不与新站交换链接了 不过你blog有些还挺不错 破例一下
多多交流
[reply=老七,2009-10-16 02:20 PM]我都觉得太简单了博客 你居然说不错。。感动。常交流[/reply]
本来整理中目前不与新站交换链接了 不过你blog有些还挺不错 破例一下
多多交流
[reply=老七,2009-10-16 02:20 PM]我都觉得太简单了博客 你居然说不错。。感动。常交流[/reply]
上一篇
下一篇
Tags:
相关文章:
[reply=老七,2009-10-16 01:09 PM]松松? 欢迎啊。。问什么呢?[/reply]