All pastes #254470 Raw Edit

ViewPanel.java

public java v1 · immutable
#254470 ·published 2006-11-21 22:10 UTC
rendered paste body
import java.awt.*;import javax.swing.*;public class ViewPanel extends JPanel {	private int _width;    private int _height;          private Mandelbrot _calculate;        public ViewPanel(int width, int height) {        // Create Mandelbrot set calculator.        _calculate = new Mandelbrot(width, height, -2, 2, -2, 2);                // Set the maximum number of iterations.        _calculate.setMaxIterations(3);        //_calculate.setMaxIterations(5);        //_calculate.setMaxIterations(10);        //_calculate.setMaxIterations(100);        //_calculate.setMaxIterations(1000);        //_calculate.setMaxIterations(10000);                // Start calculating.        _calculate.start();                // Store width and height.        _width = width;        _height = height;        setSize(width, height);    }        public void paintComponent(Graphics g) {		super.paintComponent(g);                // Colour scaling factor.        int scale = 0x7fffffff / _calculate.getMaxIterations();                // Draw Manelbrot set.        for (int x = 0; x < _width; x++) {            for (int y = 0; y < _height; y++) {                g.setColor(new Color(_calculate.value(x, y) * scale));                g.drawLine(x, y, x, y);            }        }  	}}