看如何能实现如网页显示出的那种效果?(50分)

  • 主题发起人 主题发起人 真心
  • 开始时间 开始时间

真心

Unregistered / Unconfirmed
GUEST, unregistred user!
http://www.lili.cc/welcome/java/yanhua.htm
 
//以上是网页那种效果的JAVA源代码,谁能帮我用DELPHI实现吗?或讲一下实现
的步骤也行,先谢谢谢谢谢谢谢谢谢谢了!!!
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.util.Random;

public class jhanabi extends Applet
implements Runnable
{

private int m_nAppX = 0;
private int m_nAppY = 0;
private int m_centerX = 0;
private int m_centerY = 0;
private int m_mouseX = 0;
private int m_mouseY = 0;
private int m_sleepTime = 0;
private boolean isError = false;
private boolean m_isPaintFinished = false;
boolean isRunning = false;
boolean isInitialized = false;
Thread runner = null;
int pix0[] = null;
MemoryImageSource offImage = null;
Image dbImg = null;
int pixls = 0;
int pixls2 = 0;
Random rand = null;
int bits = 0;
double bit_px[] = null;
double bit_py[] = null;
double bit_vx[] = null;
double bit_vy[] = null;
int bit_sx[] = null;
int bit_sy[] = null;
int bit_l[] = null;
int bit_f[] = null;
int bit_p[] = null;
int bit_c[] = null;
int bit_max = 0;
int bit_sound = 0;
int ru = 0;
int rv = 0;
AudioClip sound1 = null;
AudioClip sound2 = null;

public jhanabi()
{
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 = 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 &amp; 0xff0000) >> 16;
int k1 = ((((l &amp; 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (k &amp; 0xff00) >> 8;
int l1 = ((((l &amp; 0xff00) >> 8) - i) * ru >> 8) + i;
i = k &amp; 0xff;
int i2 = (((l &amp; 0xff) - i) * ru >> 8) + i;
i = (i1 &amp; 0xff0000) >> 16;
int j2 = ((((j1 &amp; 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (i1 &amp; 0xff00) >> 8;
int k2 = ((((j1 &amp; 0xff00) >> 8) - i) * ru >> 8) + i;
i = i1 &amp; 0xff;
int l2 = (((j1 &amp; 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_nAppY);
try
{
Thread.sleep(m_sleepTime);
}
catch(InterruptedException interruptedexception1) { }
}
while(true);
}

public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
g.drawImage(dbImg, 0, 0, this);
}

public void start()
{
if(isError)
return;
isRunning = true;
if(runner == null)
{
runner = new Thread(this);
runner.start();
}
}

public void stop()
{
if(runner != null)
{
runner.stop();
runner = null;
}
}

public boolean mouseMove(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}

public boolean mouseDown(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
int k = (int)(rand.nextDouble() * 256D);
int l = (int)(rand.nextDouble() * 256D);
int i1 = (int)(rand.nextDouble() * 256D);
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
int k1 = 0;
for(int l1 = 0; l1 < bits; l1++)
{
if(bit_f[l1] != 0)
continue;
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
double d = rand.nextDouble() * 6.2800000000000002D;
double d1 = rand.nextDouble();
bit_vx[l1] = Math.sin(d) * d1;
bit_vy[l1] = Math.cos(d) * d1;
bit_l[l1] = (int)(rand.nextDouble() * 100D) + 100;
bit_p[l1] = (int)(rand.nextDouble() * 3D);
bit_c[l1] = j1;
bit_sx[l1] = m_mouseX;
bit_sy[l1] = m_nAppY - 5;
bit_f[l1] = 2;
if(++k1 == bit_max)
break;
}

if(bit_sound > 1)
sound2.play();
return true;
}

public boolean mouseExit(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}

void rend()
{
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
for(int k = 0; k < bits; k++)
switch(bit_f[k])
{
default:
break;

case 1: // '/001'
bit_vy[k] += rand.nextDouble() / 50D;
bit_px[k] += bit_vx[k];
bit_py[k] += bit_vy[k];
bit_l[k]--;
if(bit_l[k] == 0 || bit_px[k] < 0.0D || bit_py[k] < 0.0D || bit_px[k] > (double)m_nAppX || bit_py[k] > (double)(m_nAppY - 3))
{
bit_c[k] = 0xff000000;
bit_f[k] = 0;
}
else
if(bit_p[k] == 0)
{
if((int)(rand.nextDouble() * 2D) == 0)
bit_set((int)bit_px[k], (int)bit_py[k], -1);
}
else
{
bit_set((int)bit_px[k], (int)bit_py[k], bit_c[k]);
}
break;

case 2: // '/002'
bit_sy[k] -= 5;
if((double)bit_sy[k] <= bit_py[k])
{
bit_f[k] = 1;
flag2 = true;
}
if((int)(rand.nextDouble() * 20D) == 0)
{
int i = (int)(rand.nextDouble() * 2D);
int j = (int)(rand.nextDouble() * 5D);
bit_set(bit_sx[k] + i, bit_sy[k] + j, -1);
}
break;

}

if(flag2 &amp;&amp; bit_sound > 0)
sound1.play();
}

void bit_set(int i, int j, int k)
{
int l = i + j * m_nAppX;
pix0[l] = k;
}
}
 
那是用 flash 做的,
 
我晕,是java
 
我想知道里面那几个函数的工作过程及顺序,谁能帮我?
 
程序的工作顺序如下:

public jhanabi()
类的构造函数,最先执行。
public void init()
这个是Applat的初始化工作
然后是
public void start()
其中
runner = new Thread(this);--->this指向jhanabi
runner.start();--->调用run()函数。
相当于生成一个新jhanabi Applet,在一个新的进程中运行。
调用从接口runnable重写的函数run();
public void run()
线程接口runnable的执行入口
// applet function ---------------
public void update(Graphics g)
//update graphics
public void paint(Graphics g)
//paint graphics
public void stop()
// run after applet stop

//响应Mouse的事件函数
public boolean mouseMove(Event event, int i, int j)
public boolean mouseDown(Event event, int i, int j)
public boolean mouseExit(Event event, int i, int j)
//以下两个是作者自定义的函数
void rend()
void bit_set(int i, int j, int k)

 
给你了,虽然我也没分了,不过答案我还是比较满意的,谢了
 
我试着用DELPHI做了做,但速度很慢,效果也不是太好。

但是基本理解了他的过程
------------------------------------------------
先得到mouse 的位置。
m_mouseX = i;
m_mouseY = j;
------------------------------------------------
int k = (int)(rand.nextDouble() * 256D);
int l = (int)(rand.nextDouble() * 256D);
int i1 = (int)(rand.nextDouble() * 256D);
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
生成随机的色彩
---------------------------------------------
int k1 = 0;
for(int l1 = 0; l1 < bits; l1++)
{
if(bit_f[l1] != 0)
continue;
//记录下mouse位置
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
//生成半径为1的随机向量
double d = rand.nextDouble() * 6.2800000000000002D;
double d1 = rand.nextDouble();
bit_vx[l1] = Math.sin(d) * d1;
bit_vy[l1] = Math.cos(d) * d1;
//随机出一个100到200的数,表示每次爆炸的点数
bit_l[l1] = (int)(rand.nextDouble() * 100D) + 100;
//生成0,1,2中的一个数,用来表示用什么色,0时用白色
bit_p[l1] = (int)(rand.nextDouble() * 3D);
//记录下随机生的那个color
bit_c[l1] = j1;

bit_sx[l1] = m_mouseX;
bit_sy[l1] = m_nAppY - 5;
bit_f[l1] = 2;
// 2 表示是礼花上升的样子
if(++k1 == bit_max)
break;
//只产生bit_max个修改点
}


-----------------------------------------------------------------
void rend()
{
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
for(int k = 0; k < bits; k++)
switch(bit_f[k])
{
default:
break;
//001这个是画礼花爆炸
case 1: // '/001'
//随机的向量在y方向来一个小的随机变化
bit_vy[k] += rand.nextDouble() / 50D;
//与mouse位置相加,生成绝对的位置
//下一frame中bit_px,bit_py放的就不是mouse 的位置了,是已经移动到的新点
//所以下一个frame在前一个的base上生成随机的位移
bit_px[k] += bit_vx[k];
bit_py[k] += bit_vy[k];
//爆炸点数-1
bit_l[k]--;
//如果爆炸点数为0
//(x,y)点不在Screen内,就置变化的色为黑色0xff000000
if(bit_l[k] == 0 || bit_px[k] < 0.0D || bit_py[k] < 0.0D || bit_px[k] > (double)m_nAppX || bit_py[k] > (double)(m_nAppY - 3))
{
bit_c[k] = 0xff000000;
bit_f[k] = 0;
}
else
//根据bit_p[k]来画点
if(bit_p[k] == 0)
{
if((int)(rand.nextDouble() * 2D) == 0)
bit_set((int)bit_px[k], (int)bit_py[k], -1);
//-1显示是白色,表示随机的产生一些白点,看到炸开时会有这个效果
}
else
{
bit_set((int)bit_px[k], (int)bit_py[k], bit_c[k]);
//其它点都用随机生成的彩色点来画
}
break;
//002画上升的柱子
case 2: // '/002'
bit_sy[k] -= 5;//在y方向上减小,就是向上升空了
if((double)bit_sy[k] <= bit_py[k])
//是否已经到了mouesY点,到了换成001类型开始画爆炸
{
bit_f[k] = 1;
flag2 = true;
}
//随机一点,在那相直线柱边上2,5上产生一些随机的白点(-1-->0xFFFFFF)
//就是那个柱子的效果了!是直线,又有点模糊
if((int)(rand.nextDouble() * 20D) == 0)
{
int i = (int)(rand.nextDouble() * 2D);
int j = (int)(rand.nextDouble() * 5D);
bit_set(bit_sx[k] + i, bit_sy[k] + j, -1);
}
break;

}
//如果到了爆炸时,产生声音。
if(flag2 &amp;&amp; bit_sound > 0)
sound1.play();
}


--------------------------------------------------------------------------
以下这段是使整个画变黑,就是原来的点慢慢的没有了,看不出什么原理,但是效果是这样的
差不多是通过平移使color越来越淡,浙浙到黑色
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 &amp; 0xff0000) >> 16;
int k1 = ((((l &amp; 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (k &amp; 0xff00) >> 8;
int l1 = ((((l &amp; 0xff00) >> 8) - i) * ru >> 8) + i;
i = k &amp; 0xff;
int i2 = (((l &amp; 0xff) - i) * ru >> 8) + i;
i = (i1 &amp; 0xff0000) >> 16;
int j2 = ((((j1 &amp; 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (i1 &amp; 0xff00) >> 8;
int k2 = ((((j1 &amp; 0xff00) >> 8) - i) * ru >> 8) + i;
i = i1 &amp; 0xff;
int l2 = (((j1 &amp; 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;
}
--------------------------------------------------------------------------------

主要部分都分析的差不多了,你可以做一做的,我做的慢的原因是,一没有能过内存
改变图象,2没有用线程,只是试了试效果,不是很好,

而且作者的这个java也有问题,就是线程不会结束,如果一直点下去,就会发现这个
java程序在吃内存………
哈哈

这回满意了吧……呵…

不知道能不能看明白…

 
后退
顶部