package cglib;.net
public class jiekou {get
public static void drawLine(){
int usage = 700;
System.out.println("Test Begins...");
while(true){
long start = System.currentTimeMillis();
while(System.currentTimeMillis() - start < usage );
try{
Thread.sleep(1000-usage);
}catch(Exception e){
System.out.print(e);
}
}
}
public static void drawSin(){
double x = Math.PI / 2;
while(true){
//下面这一句+1是由于sinx可能为负数,最大为-1,加上1的话就保证为正了
//*0.5是应为加1以后,最大数可能达到2,为了限制在1之内,因此*0.5
long usage = (long)((Math.sin(x)+1)*0.5*1000);
System.out.println(usage);
long start = System.currentTimeMillis();
while(System.currentTimeMillis() - start < usage);
try{
Thread.sleep(1000 - usage);
}catch(Exception e){
System.out.print(e);
}
x += 0.1;
}
}
public static void drawSinSpeedup(){
double x = Math.PI / 2;
//加入了刷新时间,能够调控曲线弯曲程度
int flushtime = 5000;
while(true){
long usage = (long)((Math.sin(x)+1)*0.5*flushtime);
System.out.println(usage);
long start = System.currentTimeMillis();
while(System.currentTimeMillis() - start < usage);
try{
Thread.sleep(flushtime - usage);
}catch(Exception e){
System.out.print(e);
}
x += 0.1;
}
}
public static void main(String[] args) throws InterruptedException {
drawLine();
drawSin();
} io
}class