| 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.*;
public class logisticMap extends Applet implements Runnable{
Thread th;
Image original_i,buf_i,info_i;
Graphics original_g,buf_g,info_g;
boolean goFlag=true,dragFlag=false;
int w,h,x_margin=35,y_margin=15;
Button db,hf,reset;
int mx,my,sx0,sy0,sx1,sy1;
double a_now,x_now;
int plot_max=30000;
int rep_max=1000;
int xp[]=new int[plot_max];
int ap[]=new int[plot_max];
double a_min,a_max,x_min,x_max;
Applet applet = this;
public void init(){
a_min=2.8;a_max=4.0;x_min=0.0;x_max=1.0;
//get screen size
w=getSize().width;
h=getSize().height;
//redefine w and h for buffer layer
w-=20; h-=50;
//create buffer layer
buf_i=createImage(w,h);
buf_g=buf_i.getGraphics();
//create original (temp.) layer
original_i=createImage(w,h);
original_g=original_i.getGraphics();
//create info layer
info_i=createImage(100,10);
info_g=info_i.getGraphics();
//GUI
setLayout(new FlowLayout(1,20,h+20));
add(db=new Button("X2"));
add(hf=new Button("/2"));
add(reset=new Button("reset"));
db.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
db_fig();
}
});
hf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
hf_fig();
}
});
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
reset_fig();
}
});
//mouse
addMouseMotionListener(
new MouseMotionAdapter(){
public void mouseMoved(MouseEvent e){
mx=e.getX(); my=e.getY();
//ajustment for out of range
if(mx<x_margin) mx=x_margin;
if(mx>w-x_margin) mx=w-x_margin;
if(my<y_margin) my=y_margin;
if(my>h-y_margin) my=h-y_margin;
//set max and min for a and x
a_now=(double)(mx-x_margin)/(double)(w-x_margin*2)*(a_max-a_min)+a_min;
x_now=x_max-(double)(my-y_margin)/(double)(h-y_margin*2)*(x_max-x_min);
info_g.setColor(Color.white);
info_g.fillRect(0,0,w,10);
info_g.setColor(Color.black);
info_g.drawString("a="+java.lang.Double.toString(a_now).substring(0,5)+", x="+java.lang.Double.toString(x_now).substring(0,5),0,10);
repaint();
}
public void mouseDragged(MouseEvent e){
int i;
dragFlag=true;
mx=e.getX(); my=e.getY();
int vert_of_range_x[]={sx0,mx,mx,sx0};
int vert_of_range_y[]={sy0,sy0,my,my};
//ajustment for out of range
for(i=0;i<4;i++){
if(vert_of_range_x[i]<x_margin)vert_of_range_x[i]=x_margin;
if(vert_of_range_x[i]>w-x_margin)vert_of_range_x[i]=w-x_margin;
if(vert_of_range_y[i]<y_margin)vert_of_range_y[i]=y_margin;
if(vert_of_range_y[i]>h-y_margin)vert_of_range_y[i]=h-y_margin;
}
//Image buf_iをImage original_iにしたい...
buf_g.drawImage(original_i,0,0,applet);
buf_g.setColor(Color.blue);
buf_g.drawPolygon(vert_of_range_x,vert_of_range_y,4);
a_now=(double)(mx-x_margin)/(double)(w-x_margin*2)*(a_max-a_min)+a_min;
x_now=x_max-(double)(my-y_margin)/(double)(h-y_margin*2)*(x_max-x_min);
info_g.setColor(Color.white);
info_g.fillRect(0,0,w,10);
info_g.setColor(Color.black);
info_g.drawString("a="+java.lang.Double.toString(a_now).substring(0,5)+", x="+java.lang.Double.toString(x_now).substring(0,5),0,10);
repaint();
}
}
);
addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e){
sx0=e.getX(); sy0=e.getY();
//現在のImage buf_iをImage original_iに格納したい...
original_g.drawImage(buf_i,0,0,applet);
//System.out.println(sx0);
}
public void mouseReleased(MouseEvent e){
if(dragFlag){
double a_min_n,a_max_n,x_min_n,x_max_n;
int s_buf;
sx1=e.getX(); sy1=e.getY();
if(sx0>sx1){
s_buf=sx0; sx0=sx1; sx1=s_buf;
}
if(sy0>sy1){
s_buf=sy0; sy0=sy1; sy1=s_buf;
}
//ajustment for out of range
if(sx0
|