![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
package com.accp.servletdemo;
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
import java.applet.Applet;
4
import java.applet.AudioClip;
5
import java.awt.*;
6
import java.awt.image.MemoryImageSource;
7
import java.util.Random;
8![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
public class jhanabi extends Applet implements Runnable
{
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
private int m_nAppX;
12![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
private int m_nAppY;
14![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
private int m_centerX;
16![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
private int m_centerY;
18![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
private int m_mouseX;
20![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
private int m_mouseY;
22![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
private int m_sleepTime;
24![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
private boolean isError;
26![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
private boolean m_isPaintFinished;
28![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
boolean isRunning;
30![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
boolean isInitialized;
32![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
Thread runner;
34![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
int pix0[];
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
MemoryImageSource offImage;
38![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
Image dbImg;
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
int pixls;
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
int pixls2;
44![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
Random rand;
46![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
int bits;
48![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
double bit_px[];
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
double bit_py[];
52![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
double bit_vx[];
54![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
double bit_vy[];
56![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
int bit_sx[];
58![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
int bit_sy[];
60![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
int bit_l[];
62![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
int bit_f[];
64![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
int bit_p[];
66![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
int bit_c[];
68![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
int bit_max;
70![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
int bit_sound;
72![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
int ru;
74![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
int rv;
76![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
AudioClip sound1;
78![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
AudioClip sound2;
80![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public jhanabi()
{
82
m_mouseX = 0;
83
m_mouseY = 0;
84
m_sleepTime = 5;
85
isError = false;
86
isInitialized = false;
87
rand = new Random();
88
bits = 10000;
89
bit_px = new double[bits];
90
bit_py = new double[bits];
91
bit_vx = new double[bits];
92
bit_vy = new double[bits];
93
bit_sx = new int[bits];
94
bit_sy = new int[bits];
95
bit_l = new int[bits];
96
bit_f = new int[bits];
97
bit_p = new int[bits];
98
bit_c = new int[bits];
99
ru = 50;
100
rv = 50;
101
}
102![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
103![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void init()
{
104
String s = getParameter("para_bits");
105![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s != null)
{
106
bits = Integer.parseInt(s);
107
}
108
s = getParameter("para_max");
109![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s != null)
{
110
bit_max = Integer.parseInt(s);
111
}
112
s = getParameter("para_blendx");
113![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s != null)
{
114
ru = Integer.parseInt(s);
115
}
116
s = getParameter("para_blendy");
117![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s != null)
{
118
rv = Integer.parseInt(s);
119
}
120
s = getParameter("para_sound");
121![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s != null)
{
122
bit_sound = Integer.parseInt(s);
123
}
124
m_nAppX = size().width;
125
m_nAppY = size().height;
126
m_centerX = m_nAppX / 2;
127
m_centerY = m_nAppY / 2;
128
m_mouseX = m_centerX;
129
m_mouseY = m_centerY;
130
resize(m_nAppX, m_nAppY);
131
pixls = m_nAppX * m_nAppY;
132
pixls2 = pixls - m_nAppX * 2;
133
pix0 = new int[pixls];
134
offImage = new MemoryImageSource(m_nAppX, m_nAppY, pix0, 0, m_nAppX);
135
offImage.setAnimated(true);
136
dbImg = createImage(offImage);
137![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int i = 0; i < pixls; i++)
{
138
pix0[i] = 0xff000000;
139
}
140![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
141
sound1 = getAudioClip(getDocumentBase(), "firework.au");
142
sound2 = getAudioClip(getDocumentBase(), "syu.au");
143![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int j = 0; j < bits; j++)
{
144
bit_f[j] = 0;
145
}
146![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
147
isInitialized = true;
148
start();
149
}
150![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
151![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void run()
{
152![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while (!isInitialized)
{
153![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
154
Thread.sleep(200L);
155![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (InterruptedException interruptedexception)
{
156
}
157
}
158![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
do
{
159![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int i = 0; i < pixls2; i++)
{
160
int j = pix0[i];
161
int k = pix0[i + 1];
162
int l = pix0[i + m_nAppX];
163
int i1 = pix0[i + m_nAppX + 1];
164
int j1 = (j & 0xff0000) >> 16;
165
int k1 = ((((k & 0xff0000) >> 16) - j1) * ru >> 8) + j1;
166
j1 = (j & 0xff00) >> 8;
167
int l1 = ((((k & 0xff00) >> 8) - j1) * ru >> 8) + j1;
168
j1 = j & 0xff;
169
int i2 = (((k & 0xff) - j1) * ru >> 8) + j1;
170
j1 = (l & 0xff0000) >> 16;
171
int j2 = ((((i1 & 0xff0000) >> 16) - j1) * ru >> 8) + j1;
172
j1 = (l & 0xff00) >> 8;
173
int k2 = ((((i1 & 0xff00) >> 8) - j1) * ru >> 8) + j1;
174
j1 = l & 0xff;
175
int l2 = (((i1 & 0xff) - j1) * ru >> 8) + j1;
176
int i3 = ((j2 - k1) * rv >> 8) + k1;
177
int j3 = ((k2 - l1) * rv >> 8) + l1;
178
int k3 = ((l2 - i2) * rv >> 8) + i2;
179
pix0[i] = i3 << 16 | j3 << 8 | k3 | 0xff000000;
180
}
181![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
182
rend();
183
offImage.newPixels(0, 0, m_nAppX, m_nAppY);
184![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
185
Thread.sleep(m_sleepTime);
186![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (InterruptedException interruptedexception1)
{
187
}
188
} while (true);
189
}
190![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
191![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void update(Graphics g)
{
192
paint(g);
193
}
194![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
195![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void paint(Graphics g)
{
196
g.drawImage(dbImg, 0, 0, this);
197
}
198![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
199![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void start()
{
200![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (isError)
{
201
return;
202
}
203
isRunning = true;
204![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (runner == null)
{
205
runner = new Thread(this);
206
runner.start();
207
}
208
}
209![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
210![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void stop()
{
211![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (runner != null)
{
212
runner.stop();
213
runner = null;
214
}
215
}
216![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
217![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public boolean mouseMove(Event event, int i, int j)
{
218
m_mouseX = i;
219
m_mouseY = j;
220
return true;
221
}
222![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
223![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public boolean mouseDown(Event event, int i, int j)
{
224
m_mouseX = i;
225
m_mouseY = j;
226
int k = (int) (rand.nextDouble() * 256D);
227
int l = (int) (rand.nextDouble() * 256D);
228
int i1 = (int) (rand.nextDouble() * 256D);
229
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
230
int k1 = 0;
231![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int l1 = 0; l1 < bits; l1++)
{
232![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (bit_f[l1] != 0)
{
233
continue;
234
}
235
bit_px[l1] = m_mouseX;
236
bit_py[l1] = m_mouseY;
237
double d = rand.nextDouble() * 6.2800000000000002D;
238
double d1 = rand.nextDouble();
239
bit_vx[l1] = Math.sin(d) * d1;
240
bit_vy[l1] = Math.cos(d) * d1;
241
bit_l[l1] = (int) (rand.nextDouble() * 100D) + 100;
242
bit_p[l1] = (int) (rand.nextDouble() * 3D);
243
bit_c[l1] = j1;
244
bit_sx[l1] = m_mouseX;
245
bit_sy[l1] = m_nAppY - 5;
246
bit_f[l1] = 2;
247![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (++k1 == bit_max)
{
248
break;
249
}
250
}
251![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
252![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (bit_sound > 1)
{
253
sound2.play();
254
}
255
return true;
256
}
257![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
258![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public boolean mouseExit(Event event, int i, int j)
{
259
m_mouseX = i;
260
m_mouseY = j;
261
return true;
262
}
263![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
264![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void rend()
{
265
boolean flag = false;
266
boolean flag1 = false;
267
boolean flag2 = false;
268![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int i = 0; i < bits; i++)
{
269![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
switch (bit_f[i])
{
270
default:
271
break;
272![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
273
case 1: // '\001'
274
bit_vy[i] += rand.nextDouble() / 50D;
275
bit_px[i] += bit_vx[i];
276
bit_py[i] += bit_vy[i];
277
bit_l[i]--;
278
if (bit_l[i] == 0 || bit_px[i] < 0.0D || bit_py[i] < 0.0D
279
|| bit_px[i] > (double) m_nAppX
280![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
|| bit_py[i] > (double) (m_nAppY - 3))
{
281
bit_c[i] = 0xff000000;
282
bit_f[i] = 0;
283![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} else if (bit_p[i] == 0)
{
284![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if ((int) (rand.nextDouble() * 2D) == 0)
{
285
bit_set((int) bit_px[i], (int) bit_py[i], -1);
286
}
287![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} else
{
288
bit_set((int) bit_px[i], (int) bit_py[i], bit_c[i]);
289
}
290
break;
291![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
292
case 2: // '\002'
293
bit_sy[i] -= 5;
294![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if ((double) bit_sy[i] <= bit_py[i])
{
295
bit_f[i] = 1;
296
flag2 = true;
297
}
298![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if ((int) (rand.nextDouble() * 20D) == 0)
{
299
int j = (int) (rand.nextDouble() * 2D);
300
int k = (int) (rand.nextDouble() * 5D);
301
bit_set(bit_sx[i] + j, bit_sy[i] + k, -1);
302
}
303
break;
304
}
305
}
306![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
307![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (flag2 && bit_sound > 0)
{
308
sound1.play();
309
}
310
}
311![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
312![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void bit_set(int i, int j, int k)
{
313
int l = i + j * m_nAppX;
314
pix0[l] = k;
315
}
316
}
posted @
2009-10-28 16:30
lovedeeply
阅读(
400)
评论()
编辑
收藏
举报