/* Java Applet "Mandel" is a standard Mandelbrot set explorer. Copyright Danny Calegari; source code released under GPL license */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.lang.Math; import java.awt.Color; public class mandel extends Applet implements MouseListener, MouseMotionListener, ActionListener{ double xc,yc,xz,yz,x,y; double xleft,xright; double yleft,yright; int xileft,yileft,xiright,yiright; int col[][]; int bwcol[][]; double scale; double xcenter,ycenter; int iterate,detail,i,j,k; int a,b,m,n; int f,g; int dragbox, bw; Button moredetail, lessdetail, resetbut, BWbut; public void init() { setLayout(new FlowLayout(10)); moredetail = new Button("detailed"); lessdetail = new Button("coarse"); resetbut = new Button("reset"); BWbut = new Button("B/W"); add(moredetail); add(lessdetail); add(resetbut); add(BWbut); moredetail.addActionListener(this); lessdetail.addActionListener(this); resetbut.addActionListener(this); BWbut.addActionListener(this); col = new int[501][501]; bwcol = new int[501][501]; addMouseListener(this); addMouseMotionListener(this); xcenter=-1.0; ycenter=0.0; scale=0.01; detail=100; compute(); dragbox=0; bw=0; } public void paint( Graphics graphics ) { m=0; if(dragbox==0){ for (xc=xcenter-(200.0*scale);xc4.0){ if (yz>0){ bwcol[m][n]=0; } else { bwcol[m][n]=1; }; iterate=detail; }; iterate++; }; }; }; }; public void actionPerformed( ActionEvent e) { if (e.getSource() == moredetail){ detail = (int) (detail*1.2); compute(); repaint(); }; if (e.getSource() == lessdetail){ detail = (int) (detail*0.8); compute(); repaint(); }; if (e.getSource() == resetbut){ xcenter=-1.0; ycenter=0.0; scale=0.01; detail=100; bw=0; compute(); repaint(); }; if (e.getSource() == BWbut){ if(bw==0){ bw=1; } else { bw=0; }; repaint(); }; }; public void mouseMoved( MouseEvent e) { }; public void mousePressed( MouseEvent e ) { if ((e.getY()>38) || e.getX()>326){ xleft = xcenter+(e.getX()-200)*scale; yleft = ycenter+(e.getY()-200)*scale; xileft = e.getX(); yileft = e.getY(); dragbox=1; }; }; public void mouseDragged( MouseEvent e ){ xiright = e.getX(); yiright = e.getY(); repaint(); }; public void mouseReleased( MouseEvent e ) { if ((e.getY()>38) || e.getX()>326){ xright = xcenter+(e.getX()-200)*scale; yright = ycenter+(e.getY()-200)*scale; xcenter = (xleft+xright)/2.0; ycenter = (yleft+yright)/2.0; scale=(xright-xleft)/400.0; dragbox=0; compute(); repaint(); }; }; public void mouseClicked( MouseEvent e ) { }; public void mouseEntered( MouseEvent e ) { }; public void mouseExited( MouseEvent e ) { }; }