java 画正弦曲线怎么定顶点的位置?
importjava.awt.*;importjavax.swing.*;publicclassDrawSin2extendsJApplet{publicvoidpain...
import java.awt.*;
import javax.swing.*;
public class DrawSin2 extends JApplet
{
public void paint(Graphics g)
{
g.setColor(Color.green);
g.drawLine(420,120,420,480);//y轴
g.drawLine(420,300, 960, 300);//x轴
g.drawLine(950,290,960,300);
g.drawLine(950,310,960,300);//x轴箭头
g.drawLine(420,120,410,130);
g.drawLine(420,120,430,130);//y轴箭头
g.setColor(Color.black);
g.drawString("0", 410,300);
g.drawString("Y", 405, 120);
g.drawString("X", 960, 315);
int j = 420 + (590 - 100) / 10;
String s = "l";
for (int i = 1; i <= 10; i++)
{
g.drawString(s, j, 300);
j += (590 - 100) / 10;
}
g.setColor(Color.red);
int x,y,a,b;
for(x=640/20;x<=640;x+=640/200)
{
a=(int)(Math.sin((double)(x-640/20)/25)*100);
b=(int)(Math.sin((double)(x-640*9/200)/25)*100);
g.drawLine(x, 360/2-a, x+640/200, 360/2-b);
}
}
}
这是程序代码
这是运行图
怎么把函数图像移动到坐标轴上来呢? 展开
import javax.swing.*;
public class DrawSin2 extends JApplet
{
public void paint(Graphics g)
{
g.setColor(Color.green);
g.drawLine(420,120,420,480);//y轴
g.drawLine(420,300, 960, 300);//x轴
g.drawLine(950,290,960,300);
g.drawLine(950,310,960,300);//x轴箭头
g.drawLine(420,120,410,130);
g.drawLine(420,120,430,130);//y轴箭头
g.setColor(Color.black);
g.drawString("0", 410,300);
g.drawString("Y", 405, 120);
g.drawString("X", 960, 315);
int j = 420 + (590 - 100) / 10;
String s = "l";
for (int i = 1; i <= 10; i++)
{
g.drawString(s, j, 300);
j += (590 - 100) / 10;
}
g.setColor(Color.red);
int x,y,a,b;
for(x=640/20;x<=640;x+=640/200)
{
a=(int)(Math.sin((double)(x-640/20)/25)*100);
b=(int)(Math.sin((double)(x-640*9/200)/25)*100);
g.drawLine(x, 360/2-a, x+640/200, 360/2-b);
}
}
}
这是程序代码
这是运行图
怎么把函数图像移动到坐标轴上来呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询