📄 s1.java
字号:
import java.applet.Applet;
import java.awt.*;
public class S1 extends Applet implements Runnable{
int j = 0;
double x;
Image memImg = null;
Image memImg1=null;
Graphics memImgGraphics = null;
Graphics memImgGraphics1 = null;
int speed;//=50;绘图速度
Thread t = null;
/*double f(double x,int h,int w,int s){
return h/6-(Math.sin((x+w-s)*Math.PI/50))*h/10;
}
double f2(double x,int h,int w,int s){
return 5*h/6-(Math.sin((w-x-s)*Math.PI/50))*h/10;
}
double f3(double x,int h,int w,int s){
return h/2-(Math.sin((x+w)*Math.PI/50))*(Math.sin(s*Math.PI/50))*h/5;
}
double f4(double x,int h,int w){
return h/2-(Math.sin((x+w)*Math.PI/50))*h/5;
}
double f5(double x,int h,int w){
return h/2-(Math.sin((x+w)*Math.PI/50))*h/(-5);
}*/
double f(double x){
return 100-(Math.cos(x*Math.PI/50))*50;
}
double f1(double x){
return 100-(Math.sin(x*Math.PI/50))*50;
}
public void init(){
memImg = createImage(getSize().width, getSize().height);
memImgGraphics = memImg.getGraphics();//获得memImg的绘图
memImg1= createImage(getSize().width, getSize().height);
memImgGraphics1= memImg1.getGraphics();
speed = Integer.parseInt(getParameter("speed"));//画线速度
}
public void start(){
t = new Thread(this);
t.start();
}
public void run(){
while(true) {
if(j==0){
int h= getSize().height;
int w= getSize().width;
memImgGraphics1.drawImage(memImg1, 0, 0, null);
drawStaticCurve(memImgGraphics1,0,w,h/6,h/2,5*h/6);
memImgGraphics.drawImage(memImg1, 0, 0, null);
}
j++;
repaint();
try{
Thread.sleep(speed);
}
catch(Exception _ex) { }
}
}
public void paint(Graphics g){
int h= getSize().height;
int w= getSize().width;
memImgGraphics.drawImage(memImg1, 0, 0, null);
memImgGraphics.setColor(Color.red);
//for(x=0;x<w;x++){
memImgGraphics.fillOval((int)f(j),(int)f1(j),10,10);
//memImgGraphics.drawLine((int)x,(int)f(x,h,w,j),(int)(x+1),(int)f(x+1,h,w,j));
//memImgGraphics.drawLine((int)x,(int)f3(x,h,w,j),(int)(x+1),(int)f3(x+1,h,w,j));
//memImgGraphics.drawLine((int)x,(int)f3(x,h,w,j)-1,(int)(x+1),(int)f3(x+1,h,w,j)-1);
//memImgGraphics.drawLine((int)x,(int)f2(x,h,w,j),(int)(x+1),(int)f2(x+1,h,w,j));
//}
g.drawImage(memImg, 0, 0, this);
}
public void update(Graphics g){
paint(g);
}
public void drawStaticCurve(Graphics g,int x0,int x,int y1,int y2,int y3){
g.drawOval(55,55,100,100);
/*int h= getSize().height;
int w= getSize().width;
Font font=new Font("Times New Roman",Font.ITALIC|Font.BOLD,32);
g.setColor(Color.black);
g.setFont(font);
g.drawLine(x0,y1,x,y1);
g.drawLine(x0,y2,x,y2);
g.drawLine(x0,y3,x,y3);
g.drawString("STATIONARY WAVE",100,35);
g.setColor(Color.blue);
for(x=0;x<w;x++){
g.drawLine((int)x,(int)f4(x,h,w),(int)(x+1),(int)f4(x+1,h,w));
g.drawLine((int)x,(int)f5(x,h,w),(int)(x+1),(int)f5(x+1,h,w));
}*/
}
public void destroy(){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -