📄 newone.java
字号:
//<applet code=NewOne width=700 height=400></applet>
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.util.*;
class Point{
int x,y;
public Point(){
this.x=0;
this.y=0;
}
public Point(int x,int y){
this.x=x;
this.y=y;
}
}
class Line{
Point first=new Point();
Point last=new Point();
public Line(Point f,Point l){
first=f;
last=l;
}
public void pLine(Graphics g){
g.drawLine(first.x, first.y, last.x,last.y);
}
public boolean same(Line l2){
if(this.first.x==l2.first.x && this.first.y==l2.first.y && this.last.y==l2.last.y && this.last.x==l2.last.x)
return true;
else return false;
}
public boolean isIn(Iterator i){
while(i.hasNext()){
if(this.same((Line)i.next()))
return true;
}
return false;
}
}
public class NewOne extends Applet{
int num;
int sleeptime=50;
int x0=320,y0=230;
int n=21,i,j,k,r; //n是顶点个数,奇数才能一笔画!
float t=(float)(6.28318/n);
Point p[]=new Point[n];
Vector v=new Vector();
Iterator it;
public void init(){
r=200;
i=0;
j=0;
k=0;
for(i=0;i<n;i++){
num+=i;
}
this.resize(800,800);
this.setBackground(Color.black);
}
public void paint(Graphics g){
g.setColor(Color.green);
for(i=0;i<n;i++){
p[i]=new Point();
}
for(i=0;i<n;i++){
p[i].x=(int)(r*Math.cos(i*t)+x0);
p[i].y=(int)(r*Math.sin(i*t)+y0);
}
for(i=0;i<num;i++){
int m=1;
while(true){
k=j+m;
if(k>=n) k=k-n;
Line l=new Line(p[j],p[k]);
it=v.iterator();
if(!l.isIn(it)){
l.pLine(g);
v.add(l);
j=j+m;
if(j>=n) j=j-n;
try{
Thread.sleep(sleeptime);
}
catch(Exception f){
System.out.println("sleep error");
}
break;
}
else m++;
}
}
}
public static void main(String asdf[]){
Applet app=new NewOne();
JFrame frame=new JFrame("asdf");
frame.setSize(800,800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(app);
app.init();
app.start();
frame.setVisible(true);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -