-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJavaBrot.java
152 lines (126 loc) · 3.58 KB
/
JavaBrot.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright (c) 2012 Joe Davisson.
This file is part of JavaBrot.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.net.*;
public class JavaBrot
{
public static Frame win = null;
public static JPanel panel = null;
public static Palette pal;
public static Input input;
public static int iter;
public static boolean restart = false;
public static boolean reset = false;
public static int mode = 0;
public static Bitmap backbuf;
public static BufferedImage bi;
public static void about()
{
JOptionPane.showMessageDialog(win, "JavaBrot",
"About", JOptionPane.INFORMATION_MESSAGE);
}
public static void quit()
{
System.exit(0);
}
public static void nextPal()
{
pal.randomize();
}
public static void main(String[] args)
{
final int w = 640;
final int h = 480;
Blend.setMode(Blend.NORMAL);
backbuf = new Bitmap(w, h);
backbuf.clear(Col.makeRGB(0, 0, 0));
DataBuffer data_buffer = new DataBufferInt(backbuf.data, w * h);
int band_masks[] = { 0xFF0000, 0xFF00, 0xFF, 0xFF000000 };
WritableRaster write_raster =
Raster.createPackedRaster(data_buffer, w, h, w, band_masks, null);
ColorModel color_model = ColorModel.getRGBdefault();
bi = new BufferedImage(color_model, write_raster, false, null);
// input class needs these set
Screen.w = w;
Screen.h = h;
JFrame frame = new JFrame("JavaBrot");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
MainMenu menu = new MainMenu();
frame.setJMenuBar(menu);
panel = new JPanel()
{
public void paintComponent(Graphics g)
{
g.drawImage(bi, 0, 0, w, h, null);
}
};
panel.setSize(w, h);
panel.setPreferredSize(new Dimension(w, h));
panel.setLayout(new BorderLayout());
frame.add(panel);
input = new Input();
panel.addKeyListener(input);
panel.addMouseListener(input);
panel.addMouseMotionListener(input);
panel.setFocusable(true);
frame.pack();
frame.setVisible(true);
win = (Frame)frame;
Mandel mandel = null;
Rnd.set(1234567);
iter = 1000;
restart = false;
reset = false;
mode = 0;
pal = new Palette();
while(true)
{
mandel = null;
switch(mode)
{
case 0:
mandel = new MandelFloat();
break;
case 1:
Big.setSize(4);
mandel = new MandelBig();
break;
case 2:
Big.setSize(8);
mandel = new MandelBig();
break;
case 3:
Big.setSize(16);
mandel = new MandelBig();
break;
case 4:
Big.setSize(32);
mandel = new MandelBig();
break;
default:
mandel = new MandelFloat();
break;
}
mandel.loop();
}
}
}