java雨花特效代码 用java写新年快乐特效代码

java 能否实现桌面下雪花的效果?使用swing?/*
*实现在窗体上随机布满300个雪花("*"),滚动
*在上次的课基础上增加了for循环(一次要产生300个变量),随机数,数组 ;
*下面的序号为步骤
*/ import java.awt.* ; //(3)导入awt包
public class Star {
public static void main(String args[]) {
Frame w = new Frame() ; //(1)绘制窗体
w.setSize(1024,768) ; //(4)把窗体布满全屏
w.setBackground(Color.BLACK) ; //(5)背景为黑颜色
MyPanel mp = new MyPanel() ; //(7)把MyPanel对象mp,添加到窗体w上
w.add(mp) ;
Thread t = new Thread(mp) ;
t.start() ; //(12)启动线程
w.show(); //(2)显示窗体
}
}
//(6)继承Panel类
class MyPanel extends Panel implements Runnable { //(11)实现Runnable接口
int x[] = new int[300] ;
int y[] = new int[300] ; //(8)定义300个数组变量MyPanel(){
for(int i = 0;i300; i) {
x[i] = (int)(Math.random()*1024) ;
y[i] = (int)(Math.random()*768) ; //(9)当程序走到第6步的时候程序就会调用构成函数
} //由于随机数是从0-1之间的数任意产出所以x乘以1024,y乘以768再转换为int类型
}
public void paint(Graphics g) {
for(int i = 0;i300; i) {
g.setColor(Color.WHITE) ;
g.drawString("*",x[i],y[i]) ;
//g.drawString("*",30,30) ;(7)绘制一个星星在屏幕的x=30,y=30的位置上
} //(10)绘制300个雪花 , 把坐标30,30,改成x[i],y[i] ;
} //做到这步可以实现在黑色的天空布满300个星星
public void run() {
while(true) { //(13)实现产生300个雪花往下落死循环
for(int i = 0 ; i300; i) {
y[i]; //(14)y坐标不断的 1
if(y[i]768){ //(18)如果y轴坐标大于768时,则y = 0,回到窗体的顶部
y[i] = 0 ;
}
}
try{ //(16)用try,catch解决线程休眠的异常
Thread.sleep(20) ; //(15)在每次y轴坐标 1后线程休眠20毫秒
}catch(Exception e) {}
repaint() ; //(17)雪花在新的位置重画
}
}
}
java怎么画出 3D 效果的图像?可参考 孙博文 java雨花特效代码的一本书分形算法与程序设计: Java实现里面有3D的内容
貌似要下载JAVA3D 的msi安装包解压后得到jar包JAVA 3D已经被淘汰可能有点难找
用Java3D编程就行java雨花特效代码了java雨花特效代码你先把那书上关于3D的代码稍微看一下编程的思路也就是先建立一个场景(有光)然后空间描点画线着色之类的可以参考具体的Java 3D 的书貌似大多是英文的
编程也可以参考官方API文档
求一段javascritp网页特效代码!doctype html
html
head
meta charset="utf-8"
title无标题文档/title
style type="text/css"
#box{width:100px;height:100px;background:red;border-radius:100px;transition:1s;}
.boxLate{
-webkit-transform:translate(200px,300px);
-moz-transform:translate(200px,300px);
-o-transform:translate(200px,300px);
transform:translate(200px,300px);
}
/style
/head
body
input type="button" value="https://www.04ip.com/post/点击移动" id="Btn"
div id="box"/div
script type="text/javascript"
window.onload = function()
{
var oBtn = document.getElementById("Btn");
var oDiv = document.getElementById("box");
oBtn.onclick = function()
{
//alert("f");
oDiv.style.webkitTransform = 'translate(200px,300px)';
oDiv.style.mozTransform = 'translate(200px,300px)';
oDiv.style.oTransform = 'translate(200px,300px)';
oDiv.style.transform = 'translate(200px,300px)';
};
}
/script
/body
/html
跨年特效代码package love;import java.applet.Applet;import java.awt.Color;import java.awt.Graphics;import java.net.URL;import java.util.Random;/*** 烟花* @author enjoy**/@SuppressWarnings("serial")public class Q extends Applet implements Runnable {public int speed, variability, Max_Number, Max_Energy, Max_Patch,Max_Length, G;public String sound;private int width, height;private Thread thread = null;private BeaClassDemo bcd[];public void init() {int i;this.setSize(1900, 900);width = getSize().width - 1;height = getSize().height - 1;speed = 1;// 烟花绽放java雨花特效代码的速度variability = 10;Max_Number = 980;// 可发出烟花java雨花特效代码的最大数目Max_Energy = width50;Max_Patch = 90;// 最大的斑点数Max_Length = 90;// 斑点的最大距离G = 150;// 向地面弯曲的力度bcd = new BeaClassDemo[Max_Number];for (i = 0; iMax_Number; i)bcd[i] = new BeaClassDemo(width, height, G);}public void start() {if (thread == null) {thread = new Thread(this);thread.start();}}@SuppressWarnings("deprecation")public void stop() {if (thread != null) {thread.stop();thread = null;}}@SuppressWarnings({ "unused", "static-access" })public void run() {int i;int E = (int) (Math.random() * Max_Energy * 3 / 4)Max_Energy / 41;int P = (int) (Math.random() * Max_Patch * 3 / 4)// 烟花的斑点数Max_Patch / 41;int L = (int) (Math.random() * Max_Length * 3 / 4)// 烟花可发射出的距离Max_Length / 41;long S = (long) (Math.random() * 10000);boolean sleep;Graphics g = getGraphics();URL u = null;while (true) {try {thread.sleep(1000 / speed);} catch (InterruptedException x) {}sleep = true;for (i = 0; iMax_Number; i)sleep = sleepbcd[i].sleep;if (sleepMath.random() * 100variability) {E = (int) (Math.random() * Max_Energy * 3 / 4)Max_Energy / 41;P = (int) (Math.random() * Max_Patch * 3 / 4)Max_Patch / 41;L = (int) (Math.random() * Max_Length * 3 / 4)Max_Length / 41;S = (long) (Math.random() * 10000);}for (i = 0; iMax_Number; i) {if (bcd[i].sleepMath.random() * Max_Number * L1) {bcd[i].init(E, P, L, S);bcd[i].start();}bcd[i].show(g);}}}public void paint(Graphics g) {g.setColor(Color.black);g.fillRect(0, 0, width1, height1);}}class BeaClassDemo {public boolean sleep = true;private int energy, patch, length, width, height, G, Xx, Xy, Ex[], Ey[], x,y, Red, Blue, Green, t;private Random random;public BeaClassDemo(int a, int b, int g) {width = a;height = b;G = g;}public void init(int e, int p, int l, long seed) {int i;energy = e;patch = p;length = l;// 创建一个带种子的随机数生成器random = new Random(seed);Ex = new int[patch];Ey = new int[patch];Red = (int) (random.nextDouble() * 128)128;Blue = (int) (random.nextDouble() * 128)128;Green = (int) (random.nextDouble() * 128)128;Xx = (int) (Math.random() * width / 2)width / 4;Xy = (int) (Math.random() * height / 2)height / 4;for (i = 0; ipatch; i) {Ex[i] = (int) (Math.random() * energy) - energy / 2;Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;
回答于 2023-02-22
向TA提问
官方服务
官方网站
官方网站
【java雨花特效代码 用java写新年快乐特效代码】关于java雨花特效代码和用java写新年快乐特效代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读