java

位置:IT落伍者 >> java >> 浏览文章

一个用java演示的产生图像烟花的算法


发布日期:2021年02月25日
 
一个用java演示的产生图像烟花的算法

以下是一个用java演示的产生图像烟花的算法可以用来研究以下相关的东西希望对有兴趣的朋友有用

import javaappletAudioClip;

import javaawt*;

import javaawtimageMemoryImageSource;

import javautilRandom;

public class jhanabi extends Applet

implements Runnable

{

// 类成员变量定义域开始

private int m_nAppX;

private int m_nAppY;

private int m_centerX;

private int m_centerY;

private int m_mouseX;

private int m_mouseY;

private int m_sleepTime;

private boolean isError;

private boolean m_isPaintFinished;

boolean isRunning;

boolean isInitialized;

Thread runner;

int pix[];

MemoryImageSource offImage;

Image dbImg;

int pixls;

int pixls;

Random rand;

int bits;

double bit_px[];

double bit_py[];

double bit_vx[];

double bit_vy[];

int bit_sx[];

int bit_sy[];

int bit_l[];

int bit_f[];

int bit_p[];

int bit_c[];

int bit_max;

int bit_sound;

int ru;

int rv;

AudioClip sound;

AudioClip sound;

// 类成员变量定义域结束 < 初始化过程祥见构造方法 >

public jhanabi// 构造方法 (如有必要请手工调整该方法)

{

m_mouseX = ;

m_mouseY = ;

m_sleepTime = ;

isError = false;

isInitialized = false;

rand = new Random;

bits = ;

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 = ;

rv = ;

}// jhanabi 结束

//构造方法结束

public void init

{

String s = getParameter( para_bits );

if(s != null)

bits = IntegerparseInt(s);

s = getParameter( para_max );

if(s != null)

bit_max = IntegerparseInt(s);

s = getParameter( para_blendx );

if(s != null)

ru = IntegerparseInt(s);

s = getParameter( para_blendy );

if(s != null)

rv = IntegerparseInt(s);

s = getParameter( para_sound );

if(s != null)

bit_sound = IntegerparseInt(s);

m_nAppX = sizewidth;

m_nAppY = sizeheight;

m_centerX = m_nAppX / ;

m_centerY = m_nAppY / ;

m_mouseX = m_centerX;

m_mouseY = m_centerY;

resize(m_nAppX m_nAppY);

pixls = m_nAppX * m_nAppY;

pixls = pixls m_nAppX * ;

pix = new int[pixls];

offImage = new MemoryImageSource(m_nAppX m_nAppY pix m_nAppX);

offImagesetAnimated(true);

dbImg = createImage(offImage);

for(int i = ; i < pixls; i++)

pix[i] = xff;

sound = getAudioClip(getDocumentBase fireworkau );

sound = getAudioClip(getDocumentBase syuau );

for(int j = ; j < bits; j++)

bit_f[j] = ;

isInitialized = true;

start;

}//init 结束

public void run

{

while(!isInitialized)

try

{

Threadsleep(L);

}

catch(InterruptedException interruptedexception) { }

do

{

for(int j = ; j < pixls; j++)

{

int k = pix[j];

int l = pix[j + ];

int i = pix[j + m_nAppX];

int j = pix[j + m_nAppX + ];

int i = (k & xff) > > ;

int k = ((((l & xff) > > ) i) * ru > > ) + i;

i = (k & xff) > > ;

int l = ((((l & xff) > > ) i) * ru > > ) + i;

i = k & xff;

int i = (((l & xff) i) * ru > > ) + i;

i = (i & xff) > > ;

int j = ((((j & xff) > > ) i) * ru > > ) + i;

i = (i & xff) > > ;

int k = ((((j & xff) > > ) i) * ru > > ) + i;

i = i & xff;

int l = (((j & xff) i) * ru > > ) + i;

int i = ((j k) * rv > > ) + k;

int j = ((k l) * rv > > ) + l;

int k = ((l i) * rv > > ) + i;

pix[j] = i < < | j < < | k | xff;

}//for 结束

rend;

offImagenewPixels( m_nAppX m_nAppY);

try

{

Threadsleep(m_sleepTime);

}

catch(InterruptedException interruptedexception) { }

}// do 结束

while(true);

}//run 结束

public void update(Graphics g)

{

paint(g);

}

public void paint(Graphics g)

{

gdrawImage(dbImg this);

}

public void start

{

if(isError)

return;

isRunning = true;

if(runner == null)

{

runner = new Thread(this);

runnerstart;

}

}

public void stop

{

if(runner != null)

{

runnerstop;

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)(randnextDouble * D);

int l = (int)(randnextDouble * D);

int i = (int)(randnextDouble * D);

int j = k < < | l < < | i | xff;

int k = ;

for(int l = ; l < bits; l++)

{

if(bit_f[l] != )

continue;

bit_px[l] = m_mouseX;

bit_py[l] = m_mouseY;

double d = randnextDouble * D;

double d = randnextDouble;

bit_vx[l] = Mathsin(d) * d;

bit_vy[l] = s(d) * d;

bit_l[l] = (int)(randnextDouble * D) + ;

bit_p[l] = (int)(randnextDouble * D);

bit_c[l] = j;

bit_sx[l] = m_mouseX;

bit_sy[l] = m_nAppY ;

bit_f[l] = ;

if(++k == bit_max)

break;

}

if(bit_sound > )

soundplay;

return true;

}//mouseDown 结束

public boolean mouseExit(Event event int i int j)

{

m_mouseX = i;

m_mouseY = j;

return true;

}

void rend

{

boolean flag = false;

boolean flag = false;

boolean flag = false;

for(int k = ; k < bits; k++)

switch(bit_f[k])

{

default:

break;

case : // \

bit_vy[k] += randnextDouble / D;

bit_px[k] += bit_vx[k];

bit_py[k] += bit_vy[k];

bit_l[k];

if(bit_l[k] == || bit_px[k] < D || bit_py[k] < D || bit_px[k] > (double)m_nAppX || bit_py[k] > (double)(m_nAppY ))

{

bit_c[k] = xff;

bit_f[k] = ;

}

else

if(bit_p[k] == )

{

if((int)(randnextDouble * D) == )

bit_set((int)bit_px[k] (int)bit_py[k] );

}

else

{

bit_set((int)bit_px[k] (int)bit_py[k] bit_c[k]);

}

break;

case : // \

bit_sy[k] = ;

if((double)bit_sy[k] <= bit_py[k])

{

bit_f[k] = ;

flag = true;

}

if((int)(randnextDouble * D) == )

{

int i = (int)(randnextDouble * D);

int j = (int)(randnextDouble * D);

bit_set(bit_sx[k] + i bit_sy[k] + j );

}

break;

}//switch 结束

if(flag && bit_sound > )

soundplay;

}// rend 结束

void bit_set(int i int j int k)

{

int l = i + j * m_nAppX;

pix[l] = k;

}

               

上一篇:Java编程技巧:列表排序代码分析

下一篇:JAVA虚拟机实例学习笔记二