| Upper Directory |
////////////////////////////////////////////////////////// /* Bezier Surface, Copyright 2001-2010 Ryoichi Mizuno */ /* ryoichi[at]mizuno.org */ /* Dept. of Complexity Science and Engineering */ /* at The University of Tokyo */ ////////////////////////////////////////////////////////// |
|
|
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class branching extends Applet implements Runnable{
Thread th;
Image buf_i;
Graphics buf_g;
boolean goFlag=true,growFlag=true,lineFlag=true,plineFlag=true,fpolyFlag=true;
int w,h,xp0,yp0,stack,step;
int MAX=100;
double x[]=new double[MAX];
double y[]=new double[MAX];
double z[]=new double[MAX];
int t[]=new int[MAX];
int p[]=new int[MAX];
String str,str_next="";
int phi=25,alpha=32,beta=25,scale=35,stepmax=15,view=0;
//GUI
Button startstop,reset,b_line,b_polyline,b_fillpoly;
public void init(){
//get screen size
w=getSize().width-20;
h=getSize().height-100;
//create buffer layer
buf_i=createImage(w,h);
buf_g=buf_i.getGraphics();
init_values();
//GUI
setLayout(new FlowLayout(1,20,h+30));
add(b_line=new Button("hide"));
add(b_polyline=new Button("hide"));
add(b_fillpoly=new Button("hide"));
add(startstop=new Button("stop"));
add(reset=new Button("reset"));
b_line.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
linectrl();
}
});
b_polyline.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
polylinectrl();
}
});
b_fillpoly.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
fillpolyctrl();
}
});
startstop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
startstop_p();
}
});
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
reset_p();
}
});
}
public void start(){
th=new Thread(this);
th.start();
}
public void stop(){
goFlag=false;
}
public void run(){
while(goFlag){
repaint();
try{Thread.sleep(750);}
catch(InterruptedException e){}
}
}
public void update(Graphics g){
this.paint(g);
}
public void paint(Graphics g){
//initialize
if(growFlag)step++;
else view+=5;
if(goFlag) draw();
//System.out.println(str);
g.drawImage(buf_i,10,10,this);
if(step>=stepmax)growFlag=false;
//start message
g.drawString("frame",w/2-125,h+75);
g.drawString("polygon",w/2-70,h+75);
g.drawString("filled",w/2-5,h+70);
g.drawString("polygon",w/2-10,h+80);
g.drawString("start",w/2+55,h+70);
g.drawString("/stop",w/2+55,h+80);
g.drawString("initialize",w/2+105,h+75);
}
public void draw(){
init_b();
init_point();
str_next="";
read();
str=str_next;
}
public void init_point(){
x[0]=0; y[0]=0; z[0]=0; t[0]=0; p[0]=45;
xp0=w/2; yp0=0;
}
public void init_values(){
str="A(-5)";
stack=0; step=0;
}
public void init_b(){
buf_g.setColor(Color.white);
buf_g.fillRect(0,0,w,h);
}
public void read(){
int len,now=0,param,endp;
String str_buf;
char type;
//get length of string pn
len=str.length();
//decode string one by one
while(now
|