import java.applet.*;
import java.awt.*;
public class CartesianCurve extends Applet
{
int width,height;
Image image;
Graphics draw_Curve;
public void init()
{
setBackground(Color.black);
this.setSize(350,310);
width = getSize().width;
height=getSize().height;
image = createImage(width,height);
draw_Curve=image.getGraphics();
}
public void paint(Graphics g)
{
draw_Curve.clearRect(0,0,width,height);
draw_Curve.setColor(Color.red);
int i,j;
double x,y,r;
for(i=0;i<=90;i++)
for(j=0;i<=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)+width/2;
y=-r*Math.sin(Math.PI/45*j)+height/4;
draw_Curve.fillOval((int)x,(int)y,2,2);
}
g.drawImage(image,0,0,this);
}
}

本示例展示如何使用 Java Applet 和 AWT 库来绘制一个三维的动态曲线。通过数学公式计算出每个点的位置,并用红色像素点表示。此程序实现了自定义的图形绘制过程,包括窗口背景设置、窗口大小调整、图像缓存创建等。
142

被折叠的 条评论
为什么被折叠?



