日期:2014-05-17 浏览次数:20812 次
import java.applet.Applet; import java.applet.AudioClip; import java.awt.*; import java.awt.image.MemoryImageSource; import java.util.Random; public class Flower extends Applet implements Runnable { /** * */ private static final long serialVersionUID = 1080187378875595772L; public Flower() { m_mouseX = 0; m_mouseY = 0; m_sleepTime = 5; isError = false; isInitialized = false; rand = new Random(); bits = 10000; bit_px = new double[bits]; bit_py = new double[bits]; bit_vx = new double[bits]; bit_vy = new double[bits]; bit_sx = new int[bits]; bit_sy = new int[bits]; bit_l = new int[bits]; bit_f = new int[bits]; bit_p = new int[bits]; bit_c = new int[bits]; ru = 50; rv = 50; } public void init() { String s = getParameter("para_bits"); if(s != null) bits = Integer.parseInt(s); s = getParameter("para_max"); if(s != null) bit_max = Integer.parseInt(s); s = getParameter("para_blendx"); if(s != null) ru = Integer.parseInt(s); s = getParameter("para_blendy"); if(s != null) rv = Integer.parseInt(s); s = getParameter("para_sound"); if(s != null) bit_sound = Integer.parseInt(s); m_nAppX = size().width; m_nAppY = size().height; m_centerX = m_nAppX / 2; m_centerY = m_nAppY / 2; m_mouseX = m_centerX; m_mouseY = m_centerY; resize(m_nAppX, m_nAppY); pixls = m_nAppX * m_nAppY; pixls2 = pixls - m_nAppX * 2; pix0 = new int[pixls]; offImage = new MemoryImageSource(m_nAppX, m_nAppY, pix0, 0, m_nAppX); offImage.setAnimated(true); dbImg = createImage(offImage); for(int i = 0; i < pixls; i++) pix0[i] = 0xff000000; sound1 = getAudioClip(getDocumentBase(), "firework.au"); sound2 = getAudioClip(getDocumentBase(), "syu.au"); for(int j = 0; j < bits; j++) bit_f[j] = 0; isInitialized = true; start(); } public void run() { while(!isInitialized) try { Thread.sleep(200L); } catch(InterruptedException interruptedexception) { } do { for(int j = 0; j < pixls2; j++) { int k = pix0[j]; int l = pix0[j + 1]; int i1 = pix0[j + m_nAppX]; int j1 = pix0[j + m_nAppX + 1]; int i = (k & 0xff0000) >> 16; int k1 = ((((l & 0xff0000) >> 16) - i) * ru >> 8) + i; i = (k & 0xff00) >> 8; int l1 = ((((l & 0xff00) >> 8) - i) * ru >> 8) + i; i = k & 0xff; int i2 = (((l & 0xff) - i) * ru >> 8) + i; i = (i1 & 0xff0000) >> 16; int j2 = ((((j1 & 0xff0000) >> 16) - i) * ru >> 8) + i; i = (i1 & 0xff00) >> 8; int k2 = ((((j1 & 0xff00) >> 8) - i) * ru >> 8) + i; i = i1 & 0xff; int l2 = (((j1 & 0xff) - i) * ru >> 8) + i; int i3 = ((j2 - k1) * rv >> 8) + k1; int j3 = ((k2 - l1) * rv >> 8) + l1; int k3 = ((l2 - i2) * rv >> 8) + i2; pix0[j] = i3 << 16 | j3 << 8 | k3 | 0xff000000; } rend(); offImage.newPixels(0, 0, m_nAppX, m_nAp