Code
1package com.accp.servletdemo;
2
3import java.applet.Applet;
4import java.applet.AudioClip;
5import java.awt.*;
6import java.awt.image.MemoryImageSource;
7import java.util.Random;
8
9public class jhanabi extends Applet implements Runnable {
10
11 private int m_nAppX;
12
13 private int m_nAppY;
14
15 private int m_centerX;
16
17 private int m_centerY;
18
19 private int m_mouseX;
20
21 private int m_mouseY;
22
23 private int m_sleepTime;
24
25 private boolean isError;
26
27 private boolean m_isPaintFinished;
28
29 boolean isRunning;
30
31 boolean isInitialized;
32
33 Thread runner;
34
35 int pix0[];
36
37 MemoryImageSource offImage;
38
39 Image dbImg;
40
41 int pixls;
42
43 int pixls2;
44
45 Random rand;
46
47 int bits;
48
49 double bit_px[];
50
51 double bit_py[];
52
53 double bit_vx[];
54
55 double bit_vy[];
56
57 int bit_sx[];
58
59 int bit_sy[];
60
61 int bit_l[];
62
63 int bit_f[];
64
65 int bit_p[];
66
67 int bit_c[];
68
69 int bit_max;
70
71 int bit_sound;
72
73 int ru;
74
75 int rv;
76
77 AudioClip sound1;
78
79 AudioClip sound2;
80
81 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
103 public void init() {
104 String s = getParameter("para_bits");
105 if (s != null) {
106 bits = Integer.parseInt(s);
107 }
108 s = getParameter("para_max");
109 if (s != null) {
110 bit_max = Integer.parseInt(s);
111 }
112 s = getParameter("para_blendx");
113 if (s != null) {
114 ru = Integer.parseInt(s);
115 }
116 s = getParameter("para_blendy");
117 if (s != null) {
118 rv = Integer.parseInt(s);
119 }
120 s = getParameter("para_sound");
121 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 for (int i = 0; i < pixls; i++) {
138 pix0[i] = 0xff000000;
139 }
140
141 sound1 = getAudioClip(getDocumentBase(), "firework.au");
142 sound2 = getAudioClip(getDocumentBase(), "syu.au");
143 for (int j = 0; j < bits; j++) {
144 bit_f[j] = 0;
145 }
146
147 isInitialized = true;
148 start();
149 }
150
151 public void run() {
152 while (!isInitialized) {
153 try {
154 Thread.sleep(200L);
155 } catch (InterruptedException interruptedexception) {
156 }
157 }
158 do {
159 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
182 rend();
183 offImage.newPixels(0, 0, m_nAppX, m_nAppY);
184 try {
185 Thread.sleep(m_sleepTime);
186 } catch (InterruptedException interruptedexception1) {
187 }
188 } while (true);
189 }
190
191 public void update(Graphics g) {
192 paint(g);
193 }
194
195 public void paint(Graphics g) {
196 g.drawImage(dbImg, 0, 0, this);
197 }
198
199 public void start() {
200 if (isError) {
201 return;
202 }
203 isRunning = true;
204 if (runner == null) {
205 runner = new Thread(this);
206 runner.start();
207 }
208 }
209
210 public void stop() {
211 if (runner != null) {
212 runner.stop();
213 runner = null;
214 }
215 }
216
217 public boolean mouseMove(Event event, int i, int j) {
218 m_mouseX = i;
219 m_mouseY = j;
220 return true;
221 }
222
223 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 for (int l1 = 0; l1 < bits; l1++) {
232 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 if (++k1 == bit_max) {
248 break;
249 }
250 }
251
252 if (bit_sound > 1) {
253 sound2.play();
254 }
255 return true;
256 }
257
258 public boolean mouseExit(Event event, int i, int j) {
259 m_mouseX = i;
260 m_mouseY = j;
261 return true;
262 }
263
264 void rend() {
265 boolean flag = false;
266 boolean flag1 = false;
267 boolean flag2 = false;
268 for (int i = 0; i < bits; i++) {
269 switch (bit_f[i]) {
270 default:
271 break;
272
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 || bit_py[i] > (double) (m_nAppY - 3)) {
281 bit_c[i] = 0xff000000;
282 bit_f[i] = 0;
283 } else if (bit_p[i] == 0) {
284 if ((int) (rand.nextDouble() * 2D) == 0) {
285 bit_set((int) bit_px[i], (int) bit_py[i], -1);
286 }
287 } else {
288 bit_set((int) bit_px[i], (int) bit_py[i], bit_c[i]);
289 }
290 break;
291
292 case 2: // '\002'
293 bit_sy[i] -= 5;
294 if ((double) bit_sy[i] <= bit_py[i]) {
295 bit_f[i] = 1;
296 flag2 = true;
297 }
298 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
307 if (flag2 && bit_sound > 0) {
308 sound1.play();
309 }
310 }
311
312 void bit_set(int i, int j, int k) {
313 int l = i + j * m_nAppX;
314 pix0[l] = k;
315 }
316}
1package com.accp.servletdemo;
2
3import java.applet.Applet;
4import java.applet.AudioClip;
5import java.awt.*;
6import java.awt.image.MemoryImageSource;
7import java.util.Random;
8
9public class jhanabi extends Applet implements Runnable {
10
11 private int m_nAppX;
12
13 private int m_nAppY;
14
15 private int m_centerX;
16
17 private int m_centerY;
18
19 private int m_mouseX;
20
21 private int m_mouseY;
22
23 private int m_sleepTime;
24
25 private boolean isError;
26
27 private boolean m_isPaintFinished;
28
29 boolean isRunning;
30
31 boolean isInitialized;
32
33 Thread runner;
34
35 int pix0[];
36
37 MemoryImageSource offImage;
38
39 Image dbImg;
40
41 int pixls;
42
43 int pixls2;
44
45 Random rand;
46
47 int bits;
48
49 double bit_px[];
50
51 double bit_py[];
52
53 double bit_vx[];
54
55 double bit_vy[];
56
57 int bit_sx[];
58
59 int bit_sy[];
60
61 int bit_l[];
62
63 int bit_f[];
64
65 int bit_p[];
66
67 int bit_c[];
68
69 int bit_max;
70
71 int bit_sound;
72
73 int ru;
74
75 int rv;
76
77 AudioClip sound1;
78
79 AudioClip sound2;
80
81 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
103 public void init() {
104 String s = getParameter("para_bits");
105 if (s != null) {
106 bits = Integer.parseInt(s);
107 }
108 s = getParameter("para_max");
109 if (s != null) {
110 bit_max = Integer.parseInt(s);
111 }
112 s = getParameter("para_blendx");
113 if (s != null) {
114 ru = Integer.parseInt(s);
115 }
116 s = getParameter("para_blendy");
117 if (s != null) {
118 rv = Integer.parseInt(s);
119 }
120 s = getParameter("para_sound");
121 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 for (int i = 0; i < pixls; i++) {
138 pix0[i] = 0xff000000;
139 }
140
141 sound1 = getAudioClip(getDocumentBase(), "firework.au");
142 sound2 = getAudioClip(getDocumentBase(), "syu.au");
143 for (int j = 0; j < bits; j++) {
144 bit_f[j] = 0;
145 }
146
147 isInitialized = true;
148 start();
149 }
150
151 public void run() {
152 while (!isInitialized) {
153 try {
154 Thread.sleep(200L);
155 } catch (InterruptedException interruptedexception) {
156 }
157 }
158 do {
159 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
182 rend();
183 offImage.newPixels(0, 0, m_nAppX, m_nAppY);
184 try {
185 Thread.sleep(m_sleepTime);
186 } catch (InterruptedException interruptedexception1) {
187 }
188 } while (true);
189 }
190
191 public void update(Graphics g) {
192 paint(g);
193 }
194
195 public void paint(Graphics g) {
196 g.drawImage(dbImg, 0, 0, this);
197 }
198
199 public void start() {
200 if (isError) {
201 return;
202 }
203 isRunning = true;
204 if (runner == null) {
205 runner = new Thread(this);
206 runner.start();
207 }
208 }
209
210 public void stop() {
211 if (runner != null) {
212 runner.stop();
213 runner = null;
214 }
215 }
216
217 public boolean mouseMove(Event event, int i, int j) {
218 m_mouseX = i;
219 m_mouseY = j;
220 return true;
221 }
222
223 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 for (int l1 = 0; l1 < bits; l1++) {
232 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 if (++k1 == bit_max) {
248 break;
249 }
250 }
251
252 if (bit_sound > 1) {
253 sound2.play();
254 }
255 return true;
256 }
257
258 public boolean mouseExit(Event event, int i, int j) {
259 m_mouseX = i;
260 m_mouseY = j;
261 return true;
262 }
263
264 void rend() {
265 boolean flag = false;
266 boolean flag1 = false;
267 boolean flag2 = false;
268 for (int i = 0; i < bits; i++) {
269 switch (bit_f[i]) {
270 default:
271 break;
272
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 || bit_py[i] > (double) (m_nAppY - 3)) {
281 bit_c[i] = 0xff000000;
282 bit_f[i] = 0;
283 } else if (bit_p[i] == 0) {
284 if ((int) (rand.nextDouble() * 2D) == 0) {
285 bit_set((int) bit_px[i], (int) bit_py[i], -1);
286 }
287 } else {
288 bit_set((int) bit_px[i], (int) bit_py[i], bit_c[i]);
289 }
290 break;
291
292 case 2: // '\002'
293 bit_sy[i] -= 5;
294 if ((double) bit_sy[i] <= bit_py[i]) {
295 bit_f[i] = 1;
296 flag2 = true;
297 }
298 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
307 if (flag2 && bit_sound > 0) {
308 sound1.play();
309 }
310 }
311
312 void bit_set(int i, int j, int k) {
313 int l = i + j * m_nAppX;
314 pix0[l] = k;
315 }
316}