cs_tuctuc2
Messages postés6Date d'inscriptionmardi 28 février 2006StatutMembreDernière intervention23 avril 2006
-
17 mars 2006 à 23:08
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023
-
18 mars 2006 à 03:25
BONJOUR A TOUS
VOILA G TROUVE UN CODE SUR BEZIER MAIS C4EST UNE APPLET ET MOI JE CONNAIS PAS LE FONCTIONNEMENT.
SVP CELUI QUI PEUX M'AIDER M'INDIQUE COMMENT FAIRE POUR CREER LE MAIN POUR VISUALISER LE FONCTIONNEMENT DU CODE OU SI VOUS AVEZ UN CODE SUR BEZIER.
C DANS LE CADRE DE MON PFE JE DOIS FAIRE UN OUTIL PLUME COMME EN PHOTOSHOP.SI VOUS AVEZ UNE IDEE DITES MOI
MERCI
import java.applet.*;
import java.awt.*;
class bezierCanvas extends PlotCanvas {
RealPoint P[];
controlNode cn[];
// index controls stack of points if overlap
int index[];
int nodeWd, nodeHt;
public bezierCanvas(Applet a, int w, int h, RealPoint p[]) {
super(a, w, h);
P = p;
cn = new controlNode[4];
index = new int[4]; double W 5, H W*height/width;
setCorners(-1, -1, W-1, H-1);
for (int i=0;i<4;i++) {
cn[i] = new controlNode(this, P[i]);
index[i] = i;
}
nodeWd = cn[0].wd;
nodeHt = cn[0].ht;
}
public void initGfx() {
// take care of canvas offset from containing applet
// usually about 5 pixels
adjustGfx();
double W 5, H W*height/width;
setCorners(-1, -1, W-1, H-1);
for (int i=0;i<4;i++) {
cn[i] = new controlNode(this, P[i]);
index[i] = i;
}
nodeWd = cn[0].wd;
nodeHt = cn[0].ht;
repaint();
}
public void draw() {
PlotPath ell = new PlotPath(this);
ell.moveto(P[0]);
ell.lineto(P[1]);
ell.stroke(Color.red);
ell = new PlotPath(this);
ell.moveto(P[3]);
ell.lineto(P[2]);
ell.stroke(Color.red);
PlotPath p = new PlotPath(this);
p.moveto(P[0]);
p.curveto(P[1], P[2], P[3]);
p.stroke(Color.black);
for (int i=0;i<4;i++) {
cn[index[i]].draw();
}
}
int active = -1;
public boolean mouseDown(Event evt, int x, int y) {
// System.out.println(getBounds());
// the index is a kind of stack
// find the top node hit
for (int i=3;i>=0;i--) {
if (cn[index[i]].contains(x, y)) {
active = index[i];
// put the active one on top
int k = 0;
while (index[k] != active) {
k++;
}
while (k<3) {
index[k] = index[k+1];
k++;
}
index[3] = active;
break;
}
}
return true;
}
public boolean mouseDrag(Event evt, int x, int y) {
// System.out.println("x, y = " + x + ", " + y);
if (active >= 0) {
// project (x, y) onto the window if (x <nodeWd) x nodeWd; else if (x >width-nodeWd) x width-nodeWd; if (y <nodeHt) y nodeHt; else if (y >height-nodeHt) y height-nodeHt;
cn[active].locate(x, y);
P[active] = toRealPoint(x, y);
repaint();
}
return true;
}
public boolean mouseUp(Event evt, int x, int y) {
active = -1;
return true;
}
}
public class bezierApplet extends Applet {
RealPoint P[] = new RealPoint[4];
bezierCanvas baby;
public void init() {
// System.out.println(getBounds());
setLayout(new FlowLayout());
setBackground(Color.white);
P[0] = new RealPoint(0, 0);
P[1] = new RealPoint(1, 1);
P[2] = new RealPoint(2, 1);
P[3] = new RealPoint(3, 0);
baby = new bezierCanvas(this, bounds().width, bounds().height, P);
add(baby);
show();
}