逼真下雪代码(电脑下雪代码)[20240429更新]
admin 发布:2024-04-29 20:15 115
今天给各位分享逼真下雪代码的知识,其中也会对电脑下雪代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
flash下雪代码怎么加啊,我是新手,在网上复制一些代码放到我的动画里,老是说错误!急求高手指点!!!!
网上下载的flash下雪代码一般情况下不会错 关键是你使用的是几点零的脚本 如果下载的as是2.0的 那么你在as3里应用就会出现错误的提示 另外就是使用代码 一般也需要一个雪花元件的 这个元件也要给其予实例名 或者直接从库里链接
HTML下雪代码
html
head
/head
BODY bgcolor="#000000"
SCRIPT language=JavaScript1.2
var snowsrc="images/xuehua1.gif"
var no = 10;
var ns4up = (document.layers) ? 1 : 0; // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var dx, xp, yp; // coordinate and position variables
var am, stx, sty; // amplitude and step variables
var i, doc_width = 800, doc_height =600;
if (ns4up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
} else if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
for (i = 0; i no; ++ i) {
dx[i] = 0; // set coordinate variables
xp[i] = Math.random()*(doc_width-50); // set position variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*20; // set amplitude variables
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random(); // set step variables
if (ns4up) { // set layers
if (i == 0) {
document.write("layer name=\"dot"+ i +"\" left=\"50\" top=\"50\" visibility=\"show\"img src='"+snowsrc+"' border=\"0\"/a/layer");
} else {
document.write("layer name=\"dot"+ i +"\" left=\"50\" top=\"50\" visibility=\"show\"img src='"+snowsrc+"' border=\"0\"/layer");
}
} else if (ie4up) {
if (i == 0) {
document.write("div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"img src='"+snowsrc+"' border=\"0\"/a/div");
} else {
document.write("div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"img src='"+snowsrc+"' border=\"0\"/div");
}
}
}
function snowNS() { // Netscape main animation function
for (i = 0; i no; ++ i) { // iterate for every dot
yp[i] += sty[i];
if (yp[i] doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
dx[i] += stx[i];
document.layers["dot"+i].top = yp[i];
document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowNS()", 10);
}
function snowIE() { // IE main animation function
for (i = 0; i no; ++ i) { // iterate for every dot
yp[i] += sty[i];
if (yp[i] doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx[i] += stx[i];
document.all["dot"+i].style.pixelTop = yp[i];
document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowIE()", 10);
}
if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}
/SCRIPT
/body
/html
记得给我加分啊
var snowsrc="images/xuehua1.gif"这句是你雪花图片的地址
冬天第一场雪的代码
weather rain。下雪代码是/weather rain,只能在雪地上使用才能下雪。我们来到雪地,打开聊天框输入这条指令,就可以下雪了。冬天来到了,很多地方都下起了第一场雪,让我们用博客的雪花来迎接冬天的到来吧!雪花飘落速度、雪片大小和雪片的密度都可以根据自己的喜好调整。
怎么用C语言写下雪的动画效果
#include stdio.h
#include stdlib.h
#include string.h
#include time.h
/*
* 清除屏幕的shell 命令/控制台命令,还有一些依赖平台的实现
* 如果定义了 __GNUC__ 就假定是 使用gcc 编译器,为Linux平台
* 否则 认为是 Window 平台
*/
#if defined(__GNUC__)
//下面是依赖 Linux 实现
#include unistd.h
#define sleep_ms(m) \
usleep(m * 1000)
//向上移动光标函数 Linux
static void __curup(int height)
{
int i = -1;
while (++iheight)
printf("\033[1A"); //先回到上一行
}
#else
// 创建等待函数 1s 60 帧 相当于 16.7ms = 1帧, 我们取16ms
// 咱么的这屏幕 推荐 1s 25帧吧 40ms
// 这里创建等待函数 以毫秒为单位 , 需要依赖操作系统实现
#include Windows.h
#define sleep_ms(m) \
Sleep(m)
//向上移动光标
static void __curup(int height)
{
COORD cr = {0,0};
// GetStdHandle(STD_OUTPUT_HANDLE) 获取屏幕对象, 设置光标
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cr);
}
#endif /*__GNUC__ 跨平台的代码都很丑陋 */
// 定义初始屏幕的宽高像素宏
#define _INT_WIDTH (100)
#define _INT_HEIGHT (50)
// 屏幕刷新帧的速率
#define _INT_FRATE (40)
// 雪花飘落的速率,相对于 屏幕刷新帧 的倍数
#define _INT_VSNOW (10)
/*
* 错误处理宏,msg必须是""括起来的字符串常量
* __FILE__ : 文件全路径
* __func__ : 函数名
* __LINE__ : 行数行
* __VA_ARGS__ : 可变参数宏,
* ##表示直接连接, 例如 a##b = ab
*/
#define cerr(msg,...) \
fprintf(stderr, "[%s:%s:%d]" msg "\n",__FILE__,__func__,__LINE__,##__VA_ARGS__);
/*
* 屏幕结构体, 具有 宽高
* frate : 绘制一帧的周期, 单位是 毫秒
* width : 屏幕的宽,基于窗口的左上角(0,0)
* height : 屏幕的高
* pix : 用一维模拟二维 主要结构如下
* 0 0 0 1 0 0 1 0 1 0
* 0 1 0 1 0 1 0 1 2 0
* . . .
* = 0表示没像素, 1表示1个像素,2表示2个像素....
*/
struct screen {
int frate; // 也可以用 unsigned 结构
int width;
int height;
char *pix;
};
/*
* 创建一个 屏幕结构指针 返回
*
* int frate : 绘制一帧的周期
* int width : 屏幕宽度
* int height : 屏幕高度
* return : 指向屏幕结构的指针
* */
struct screen* screen_create(int frate, int width, int height);
/*
* 销毁一个 屏幕结构指针, 并为其置空
* struct screen** : 指向 屏幕结构指针的指针, 二级销毁一级的
* */
void screen_destory(struct screen** pscr);
/**
* 屏幕绘制函数,主要生成一个雪花效果
*
* struct screen* : 屏幕数据
* return : 0表示可以绘制了,1表示图案不变
*/
int screen_draw_snow(struct screen* scr);
/**
* 屏幕绘制动画效果, 绘制雪花动画
*
* struct screen* : 屏幕结构指针
*/
void screen_flash_snow(struct screen* scr);
// 主函数,主业务在此运行
int main(int argc, char *argv[])
{
struct screen* scr = NULL;
//创建一个屏幕对象
scr = screen_create(_INT_FRATE, _INT_WIDTH, _INT_HEIGHT);
if (NULL == scr)
exit(EXIT_FAILURE);
//绘制雪花动画
screen_flash_snow(scr);
//销毁这个屏幕对象
screen_destory(scr);
return 0;
}
/*
* 创建一个 屏幕结构指针 返回
*
* int frate : 绘制一帧的周期
* int width : 屏幕宽度
* int height : 屏幕高度
* return : 指向屏幕结构的指针
* */
struct screen*
screen_create(int frate, int width, int height)
{
struct screen *scr = NULL;
if (frate0 || width = 0 || height = 0) {
cerr("[WARNING]check is frate0 || width=0 || height=0 err!");
return NULL;
}
//后面是 为 scr-pix 分配的内存 width*height
scr = malloc(sizeof(struct screen) + sizeof(char)*width*height);
if (NULL == scr) {
cerr("[FATALG]Out of memory!");
return NULL;
}
scr-frate = frate;
scr-width = width;
scr-height = height;
//减少malloc次数,malloc消耗很大,内存泄露呀,内存碎片呀
scr-pix = ((char *)scr) + sizeof(struct screen);
return scr;
}
/*
* 销毁一个 屏幕结构指针, 并为其置空
* struct screen** : 指向 屏幕结构指针的指针, 二级销毁一级的
* */
void
screen_destory(struct screen** pscr)
{
if (NULL == pscr || NULL == *pscr)
return;
free(*pscr);
// 避免野指针
*pscr = NULL;
}
//构建开头 的雪花,下面宏表示每 _INT_SHEAD 个步长,一个雪花,需要是2的幂
//static 可以理解为 private, 宏,位操作代码多了确实难读
#define _INT_SHEAD (12)
static void __snow_head(char* snow, int len)
{
int r = 0;
//数据需要清空
memset(snow, 0, len);
for (;;) {
//取余一个技巧 2^3 - 1 = 7 = 111 , 并就是取余数
int t = rand() (_INT_SHEAD - 1);
if (r + t = len)
break;
snow[r + t] = 1;
r += _INT_SHEAD;
}
}
#undef _INT_SHEAD
//通过 上一个 scr-pix[scr-width*(idx-1)] = scr-pix[scr-width*idx]
//下面的宏 规定 雪花左右摇摆 0 向左一个像素, 1 表示 不变, 2表示向右一个像素
#define _INT_SWING (3)
static void __snow_next(struct screen* scr, int idx)
{
int width = scr-width;
char* psnow = scr-pix + width*(idx - 1);
char* snow = psnow + width;
int i, j, t; // i索引, j保存下一个瞬间雪花的位置,t 临时补得,解决雪花重叠问题
//为当前行重置
memset(snow, 0, width);
//通过上一次雪花位置 计算下一次雪花位置
for (i = 0; iwidth; ++i) {
for (t = psnow[i]; t0; --t) { // 雪花可以重叠
// rand()%_INT_SWING - 1 表示 雪花 横轴的偏移量,相对上一次位置
j = i + rand() % _INT_SWING - 1;
j = j0 ? width - 1 : j = width ? 0 : j; // j如果越界了,左边越界让它到右边,右边越界到左边
++snow[j];
}
}
}
/**
* 屏幕绘制函数,主要生成一个雪花效果
*
* struct screen* : 屏幕数据
* return : 0表示可以绘制了,1表示图案不变
*/
int
screen_draw_snow(struct screen* scr)
{
// 静态变量,默认初始化为0,每次都共用
static int __speed = 0;
int idx;
if (++__speed != _INT_VSNOW)
return 1;
//下面 就是 到了雪花飘落的时刻了 既 __speed == _INT_VSNOW
__speed = 0;
//这里重新构建雪花界面,先构建头部,再从尾部开始构建
for (idx = scr-height - 1; idx 0; --idx)
__snow_next(scr, idx);
//构建头部
__snow_head(scr-pix, scr-width);
return 0;
}
//buf 保存scr 中pix 数据,构建后为 (width+1)*height, 后面宏是雪花图案
#define _CHAR_SNOW ‘*‘
static void __flash_snow_buffer(struct screen* scr, char* buf)
{
int i, j, rt;
int height = scr-height, width = scr-width;
int frate = scr-frate; //刷新的帧频率
//每次都等一下
for (;;sleep_ms(frate)) {
//开始绘制屏幕
rt = screen_draw_snow(scr);
if (rt)
continue;
for (i = 0;iheight; ++i) {
char* snow = scr-pix + i*width;
for (j = 0; jwidth; ++j)
buf[rt++] = snow[j] ? _CHAR_SNOW : ‘ ‘;
buf[rt++] = ‘\n‘;
}
buf[rt - 1] = ‘\0‘;
//正式绘制到屏幕上
puts(buf);
//清空老屏幕,屏幕光标回到最上面
__curup(height);
}
}
#undef _CHAR_SNOW
/**
* 屏幕绘制动画效果, 绘制雪花动画
*
* struct screen* : 屏幕结构指针
*/
void
screen_flash_snow(struct screen* scr)
{
char* buf = NULL;
// 初始化随机数种子,改变雪花轨迹
srand((unsigned)time(NULL));
buf = malloc(sizeof(char)*(scr-width + 1)*scr-height);
if (NULL == buf) {
cerr("[FATAL]Out of memory!");
exit(EXIT_FAILURE);
}
__flash_snow_buffer(scr, buf);
//1.这里理论上不会执行到这,没加控制器. 2.对于buf=NULL,这种代码 可以省掉,看编程习惯
free(buf);
buf = NULL;
}
逼真下雪代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于电脑下雪代码、逼真下雪代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-05安卓应用代码(安卓应用代码大全)[20240505更新]
- 05-05html5制作动漫网站源代码(html动漫网页设计作品及代码)[20240505更新]
- 05-04客服代码微信(微信客服是什么号)[20240504更新]
- 05-04融资源代码(融资代码是什么)[20240504更新]
- 05-04易语言整人代码大全(易语言符号易语言制作整人程序易语言 51自学网 215)[20240504更新]
- 05-04搜索引擎的代码样式(搜索框样式代码)[20240504更新]
- 05-04淘宝代码与网页代码不一样吗(淘宝网页源代码怎么看)[20240504更新]
- 05-04音乐播放器系统代码大全(音乐播放器c语言代码)[20240504更新]
- 05-04菜单滑动代码(开始菜单自动滚动)[20240504更新]
- 05-04好看登录界面代码(好看的登陆界面)[20240504更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接