Aide pour faire un Zoom Fractale - Java - Programmation
MarshPosté le 27-03-2006 à 13:54:54
Bonjour, Je voudrais savoir si il y aurait quelqu'un pour m'aider à faire un zoom pour mon programme de fractale en java. Sais pas trop comment m'y prendre. Je mets la structure de ma source ci-dessous. Je voudrais faire une selection rectangulaire de la zone à zoomer. Merci.
public class FrmFractal extends JFrame { public FrmFractal() { setTitle( "Fractale Mandelbrot" ); setSize( 600, 600 ); Container pnl = getContentPane(); pnl.setLayout( new BorderLayout() ); pnl.add( new PnlFractal(), BorderLayout.CENTER ); pnl.addComponentListener( new ComponentAdapter(){
public void componentResized( ComponentEvent e ) { FrmFractal.this.repaint(); }
}); }
// globals:
public static void main( String[] args ) { new FrmFractal().setVisible( true ); }
Marsh Posté le 27-03-2006 à 13:54:54
Bonjour,
Je voudrais savoir si il y aurait quelqu'un pour m'aider à faire un zoom pour mon programme de fractale en java. Sais pas trop comment m'y prendre. Je mets la structure de ma source ci-dessous. Je voudrais faire une selection rectangulaire de la zone à zoomer.
Merci.
public class FrmFractal extends JFrame
{
public FrmFractal()
{
setTitle( "Fractale Mandelbrot" );
setSize( 600, 600 );
Container pnl = getContentPane();
pnl.setLayout( new BorderLayout() );
pnl.add( new PnlFractal(), BorderLayout.CENTER );
pnl.addComponentListener( new ComponentAdapter(){
public void componentResized( ComponentEvent e )
{
FrmFractal.this.repaint();
}
});
}
// globals:
public static void main( String[] args )
{
new FrmFractal().setVisible( true );
}
class PnlFractal extends JPanel
{
double xbegin = -1.8;
double xend = 1.1;
double ybegin = -1.2;
double yend = 1.2;
public PnlFractal()
{
}
public void paint( Graphics g )
{
super.paint( g );
Dimension d = getSize();
double winx = d.getWidth();
double winy = d.getHeight();
for ( float i = 0; i < winx; i += 0.999 )
{
for ( float j = 0; j < winy; j += 0.999 )
{
// define z_0
double zIm = j * (yend - ybegin) / (winy * 1.0) + ybegin;
double zRe = i * (xend - xbegin) / (winx * 1.0) + xbegin;
double cIm = zIm;
double cRe = zRe;
// res est le compteur d'iterations
double temp;
int res = 0;
// on prend 255 iterations comme max
while ( res < 300 && (zIm * zIm + zRe * zRe) <= 4.0 )
{
temp = zRe * zRe - zIm * zIm + cRe;
zIm = 2 * zRe * zIm + cIm;
zRe = temp;
res++;
}
g.setColor( new Color( 0, 0, (float)((res * 1.0) / 300.0) ) );
g.drawLine( (int)(i), (int)(j), (int)(i), (int)(j) );
}
}
}
}
}