blob: 9c43b68f9301654990ee4c8b2ce9d1dde7b4f67c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mandelbrot;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JPanel;
/**
*
* @author Sjaak
*/
public class GridView extends JPanel implements Grid
{
private BufferedImage gridImage;
private WritableRaster gridRaster;
public static final int GRID_WIDTH = 600, GRID_HEIGHT = 600;
public static final int PIXELS_PER_REPAINT = (GRID_WIDTH * GRID_WIDTH) / 20;
public GridView() {
gridImage = new BufferedImage(GRID_WIDTH, GRID_WIDTH, BufferedImage.TYPE_INT_RGB);
gridRaster = gridImage.getRaster();
setPreferredSize(new Dimension(GRID_WIDTH, GRID_WIDTH));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(gridImage, 0, 0, null);
}
private int nrOfPixelsSet = 0;
@Override
public void setPixel(int x, int y, int[] rgb) {
gridRaster.setPixel (x, y, rgb);
nrOfPixelsSet++;
if (nrOfPixelsSet == PIXELS_PER_REPAINT) {
repaint();
nrOfPixelsSet = 0;
}
}
@Override
public int getWidth() {
return GRID_WIDTH;
}
@Override
public int getHeight() {
return GRID_HEIGHT;
}
}
|