⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 李萨如图形.txt

📁 李萨如图形的JAVA实现
💻 TXT
字号:
/*
* @(#)test1.java 0.4 95/04/09 Hugh Anderson
*
* Up here I should really put in some excuse as to why 
* there are no comments in this code. But I'm not being
* paid for this so......
*
* 源程序可能太老,在Vj1.1下不能通过编译,经Starboy修改完成
*/

import java.awt.*;
import java.applet.*;


class test1 extends Applet implements Runnable {
double pi=3.14159265359;
Thread animate=null;
int fx=20,fy=99,diffx=0,diffy=0,phase=0;

public void init() {
resize(200, 200);
}

public void paint(Graphics g) {
int X,Y,YY=0,lastx=0,lasty=0,temp=0,rev=0;
g.drawRect(0, 0, size().width - 1, size().height - 1);
if ( fy < fx ) {
temp = fx;
fx = fy;
fy = temp;
rev = 1;
}
for (int x = 0 ; x <= 360 ; x += 4) {
X = (int) ( 50.0*Math.sin( x*2.0*pi/360.0 ));
YY = (x*fy/fx)+phase;
Y = (int) ( 50.0*Math.sin( YY*2.0*pi/360.0 ));
if (x==0) { lastx=X; lasty=Y; }
if (rev==1) { g.drawLine(lastx+100,lasty+100,X+100,Y+100); }
else { g.drawLine(lasty+100,lastx+100,Y+100,X+100); }
lastx=X;
lasty=Y;
}
if ( rev==1 ) {
temp=fx;
fx = fy;
fy = temp;
}
phase = YY;
/* Fix an error ... phase shouldn't increase forever..... */
if ( phase < 0 ) { phase += 360; };
if ( phase >= 360 ) { phase -= 360; };
g.drawString( fx + ":" + fy,10,20);
}


public void run() {
while (true) {
            try{
                repaint();
                Thread.sleep(100);
            }catch(InterruptedException e)
            {}
}
}

public void start() {
if ( animate == null ) {
animate = new Thread(this);
animate.start();
}
}
public void stop() {
if (animate != null ) {
animate.stop();
animate = null;
}
}

public boolean mouseDown(Event evt, int x, int y) {
diffx = fx-x;
diffy = fy-y;
        return true;
    }

public boolean mouseDrag(Event evt, int x, int y) {
fx = x+diffx;
if ( fx==0 ) { fx = 1; };
fy = y+diffy;
        return true;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -