Vouala c dans le cadre de mon tpe,j dois faire un prog pour generer un arbre en fractale ; alors la j'ai trouvé un code source en java mais bon je n'y connais absolument rien en java ( un peu en c ) et j'aimerais k'on m'explik un peu le code svp
paske en fait c po exactement ce ke je ve et ej voudrais ameliorer kelkes ptites choses .
Thanx
( si kelk'un a le temps de faireune explikation ligne par ligne ca s'rait tres sympa ; le prog est po tres long)
import java.awt.*;
import java.applet.Applet;
class Fractale extends Panel {
Arbre arbre;
boolean Affiche = false;
double Rap, Pos, Ang;
Color Coul[];
int X1, Y1, X2, Y2, Iter, Tr, Tv, Tb, Fr, Fv, Fb;
Image OffScr;
Dimension Dim;
Graphics OffGra;
Fractale(Arbre arbre) {
this.arbre = arbre;
}
void Fractal(Graphics g, int Ax, int Ay, int Bx, int By, double Angle, int I) {
g.setColor(Coul[I]);
OffGra.setColor(Coul[I]);
g.drawLine(Ax, Ay, Bx, By);
OffGra.drawLine(Ax, Ay, Bx, By);
if(I != Iter){
double Ag = Angle - Math.random() * Ang;
double Ad = Angle + Math.random() * Ang;
double Dist = Math.sqrt((Bx - Ax) * (Bx - Ax) + (By - Ay) * (By - Ay));
int Cx = (int) (Pos * Bx + (1 - Pos) * Ax);
int Cy = (int) (Pos * By + (1 - Pos) * Ay);
int Dx = (int) (Cx + Rap * Dist * Math.sin(Ag));
int Dy = (int) (Cy - Rap * Dist * Math.cos(Ag));
int Ex = (int) (Cx + Rap * Dist * Math.sin(Ad));
int Ey = (int) (Cy - Rap * Dist * Math.cos(Ad));
Fractal(g, Cx, Cy, Dx, Dy, Ag, I+1);
Fractal(g, Cx, Cy, Ex, Ey, Ad, I+1);
}
}
public void paint(Graphics g){
Dimension d = size();
if ((Affiche) || (OffScr == null) || (d.width != Dim.width) || (d.height != Dim.height)){
Dim = d;
OffScr = createImage(d.width, d.height);
OffGra = OffScr.getGraphics();
Coul = new Color[Iter+1];
for (int i = 0; i <= Iter; i++)
Coul[i] = new Color((int)(Tr+i*(Fr-Tr)/Iter),
(int)(Tv+i*(Fv-Tv)/Iter), (int)(Tb+i*(Fb-Tb)/Iter));
g.setColor(getBackground());
g.fillRect(0,0,d.width,d.height);
OffGra.setColor(getBackground());
OffGra.fillRect(0,0,d.width,d.height);
X1 = X2 = d.width >> 1;
Y1 = size().height-1;
Y2 = (int)(0.6*size().height);
Fractal(g, X1, Y1, X2, Y2, 0, 0);
Affiche = false;
} else
g.drawImage(OffScr, 0, 0, null);
}
}
public class Arbre extends Applet {
TextField tIter, tRap, tPos, tAng;
Fractale Tree;
public void init(){
setLayout(new BorderLayout());
Tree = new Fractale(this);
add("Center", Tree);
Panel p = new Panel();
add("South", p);
String s;
Tree.Iter=((s=getParameter("Iter" ))==null)?
12:Integer.parseInt(s);
Tree.Pos=((s=getParameter("Pos" ))==null)?
.5:Double.valueOf(s).doubleValue();
Tree.Rap=((s=getParameter("Rap" ))==null)?
.8:Double.valueOf(s).doubleValue();
Tree.Ang=((s=getParameter("Ang" ))==null)?
.6:Double.valueOf(s).doubleValue();
p.add(tIter=new TextField(Integer.toString(Tree.Iter),4));
p.add(tPos=new TextField(Double.toString(Tree.Pos),4));
p.add(tRap=new TextField(Double.toString(Tree.Rap),4));
p.add(tAng=new TextField(Double.toString(Tree.Ang),4));
p.add(new Button("Affiche" ));
Tree.Tr=((s=getParameter("Tr" ))==null)?
128:Integer.parseInt(s);
Tree.Tv=((s=getParameter("Tv" ))==null)?
64:Integer.parseInt(s);
Tree.Tb=((s=getParameter("Tb" ))==null)?
0:Integer.parseInt(s);
Tree.Fr=((s=getParameter("Fr" ))==null)?
64:Integer.parseInt(s);
Tree.Fv=((s=getParameter("Fv" ))==null)?
192:Integer.parseInt(s);
Tree.Fb=((s=getParameter("Fb" ))==null)?
0:Integer.parseInt(s);
Tree.repaint();
}
public boolean action(Event ev, Object arg){
if(ev.target instanceof Button){
String label=(String) arg;
Tree.Iter=Integer.parseInt(tIter.getText().trim
());
Tree.Pos=Double.valueOf(tPos.getText().trim()).
doubleValue();
Tree.Rap=Double.valueOf(tRap.getText().trim()).
doubleValue();
Tree.Ang=Double.valueOf(tAng.getText().trim()).
doubleValue();
if(Tree.Affiche=label.equals("Affiche" )) Tree.repaint();
return true;
}
return false;
}
}