| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2185 人关注过本帖
标题:一个模拟自然云朵的C程序(转载) 实在是漂亮!!!
只看楼主 加入收藏
mkmny
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-8-17
收藏
 问题点数:0 回复次数:20 
一个模拟自然云朵的C程序(转载) 实在是漂亮!!!

只可惜没有注释…………

#include <stdio.h> #include <dos.h> #include <math.h> long Addr[768]; int Mode;

Set_Mode (int mode) { union REGS r; r.h.ah=0; r.h.al=mode; int86 (0x10,&r,&r); }

Set_Graphics_Mode (unsigned x,unsigned y) { long i; if ((x<321)&&(y<201)) { Set_Mode (0x13); Mode=0x13; for (i=0;i<200;i++) Addr[i]=320*i; } else if ((x<641)&&(y<401)) { Set_Mode (0x5c); Mode=0x5c; for (i=0;i<400;i++) Addr[i]=640*i; } else if ((x<641)&&(y<481)) { Set_Mode (0x5d); Mode=0x5d; for (i=0;i<480;i++) Addr[i]=640*i; } else if ((x<641)&&(y<481)) { Set_Mode (0x5d); Mode=0x5d; for (i=0;i<480;i++) Addr[i]=640*i; } else if ((x<801)&&(y<601)) { Set_Mode (0x5e); Mode=0x5e; for (i=0;i<600;i++) Addr[i]=800*i; } else if ((x<1025)&&(y<769)) { Set_Mode (0x62); Mode=0x62; for (i=0;i<768;i++) Addr[i]=1024*i; } else { Set_Mode (3); printf ("Not support this mode .\n"); getch (); } }

set_pattern () { int i; unsigned char pat[256][3]; struct SREGS inreg; union REGS reg;

pat[0][0]=0;pat[0][1]=0;pat[0][2]=0; for (i=1;i<=255;i++) { pat[i][0]=(unsigned char)((float)(abs(i-127)*63)/127.0+0.5); pat[i][1]=(unsigned char)((float)(abs(i-127)*63)/127.0+0.5); pat[i][2]=63; } reg.x.ax=0x1012; reg.x.bx=0; reg.x.cx=256; reg.x.dx=FP_OFF(pat); inreg.es=FP_SEG(pat); int86x (0x10,&reg,&reg,&inreg); }

plot (int x,int y,unsigned char color) { long offset; char Page; unsigned char far *address; switch (Mode) { case 0x13: offset=Addr[y]+x; address=(unsigned char far *)(0xa0000000L+offset); *address=color; break; case 0x5c: case 0x5d: case 0x5e: offset=Addr[y]+x; Page=(offset>>16); outportb (0x3c4,0xe); outportb (0x3c5,Page^0x02); offset=offset&65535; address=(unsigned char far *)(0xa0000000L+offset); *address=color; break; case 0x62: offset=Addr[y]+x; Page=y>>6; outportb (0x3c4,0xe); outportb (0x3c5,Page^0x02); offset=offset&65535; address=(unsigned char far *)(0xa0000000L+offset); *address=color; break; default: break; } }

get_pixel (int x,int y) { long offset; char Page; unsigned char far *address; unsigned char color; switch (Mode) { case 0x13: offset=Addr[y]+x; address=(unsigned char far *)(0xa0000000+offset); color=*address; break; case 0x5c: case 0x5d: case 0x5e: offset=Addr[y]+x; Page=(offset>>16); outportb (0x3c4,0xe); outportb (0x3c5,Page^0x02); offset=offset&65535; address=(unsigned char far *)(0xa0000000L+offset); color=*address; break; case 0x62: offset=Addr[y]+x; Page=y>>6; outportb (0x3c4,0xe); outportb (0x3c5,Page^0x02); offset=offset&65535; address=(unsigned char far *)(0xa0000000L+offset); color=*address; break; default: break; } return (color); }

randint (unsigned int range) { float sigma=423.1966; static double OldRand=0.4231967; double temp; temp=sigma*OldRand; OldRand=temp-(int)temp; return (int)(OldRand*(float)range); }

void New_Col (int xa,int ya,int x,int y,int xb,int yb) { unsigned int color; color=abs(xa-xb)+abs(ya-yb); color=randint(color<<1)-color; color=color+(get_pixel(xa,ya)+get_pixel(xb,yb)+1)>>1; if (color<1) color=1; else if (color>255) color=255; if ((get_pixel(x,y)==0)) plot (x,y,color); }

void Sub_Divide (int x1,int y1,int x2,int y2) { int x,y; unsigned char color; if (!((x2-x1<2)&&(y2-y1<2))) { x=(x1+x2)>>1; y=(y1+y2)>>1; New_Col (x1,y1,x,y1,x2,y1); New_Col (x2,y1,x2,y,x2,y2); New_Col (x1,y2,x,y2,x2,y2); New_Col (x1,y1,x1,y,x1,y2); color=(get_pixel(x1,y1)+get_pixel(x2,y1)+get_pixel(x2,y2)+get_pixel (x1,y2)+2)>>2; plot (x,y,color); Sub_Divide (x1,y1,x,y); Sub_Divide (x,y1,x2,y); Sub_Divide (x,y,x2,y2); Sub_Divide (x1,y,x,y2); } }

main () { int x,y; x=320;y=200; Set_Graphics_Mode (x,y); set_pattern (); plot (0,0,randint(254)+1); plot (x-1,0,randint(254)+1); plot (x-1,y-1,randint(254)+1); plot (0,y-1,randint(254)+1); Sub_Divide (0,0,x-1,y-1); getch(); Set_Mode (0x03); }

搜索更多相关主题的帖子: 云朵 漂亮 自然 模拟 
2004-08-17 13:51
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
挺漂亮的呀~可惜不能动~~~~顶一下

淘宝杜琨
2004-08-17 16:08
乌鸦丘比特
Rank: 1
等 级:新手上路
威 望:2
帖 子:625
专家分:0
注 册:2004-7-19
收藏
得分:0 
强,UP

我喜欢创造,一只扑腾着翅膀向天空飞翔的乌鸦
2004-08-17 17:55
天地一沙鸥
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2004-8-14
收藏
得分:0 

这个程序采用的分辨率是不是有点低?还是我显卡不行? 这个程序在我这里采用的分辨率为320X200


鸟凄声以孤归, 兽索偶而不还。 悼当年之晚暮, 恨兹岁之欲殚。 思宵梦以从之, XXX而不安; 若凭舟之失棹, 譬缘崖而无攀。 /img/assets/200401/200401061015134010607.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://joke./img/assets/200401/200401061015134010607.jpg');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-17 23:46
流星雨
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1854
专家分:1868
注 册:2004-5-30
收藏
得分:0 
很漂亮,不知楼主可否将原理与思路书写出来,小女想研究研究!

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2004-08-17 23:52
忆楠
Rank: 1
等 级:新手上路
帖 子:721
专家分:0
注 册:2004-7-5
收藏
得分:0 

呵呵 很漂亮啊 楼上的大哥说不能动 我用win-tc 云彩是有变化的 仔细看看


点 鼠 标 , 救 饥 民 http://www./
2004-08-18 11:06
mkmny
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-8-17
收藏
得分:0 

楼上的MM你可看清了,我已经注明是转载了!我只知道此程序借用一对名为int86()和int86x()的函数,使你不仅可以调用DOS函数,还可以调用其它低级函数。用这些函数可以跳过标准的C函数而直接调用DOS函数。因而没有调用graphics.h

呵呵,我也不知道我说的对不对。也希望大家有一说一!!!


2004-08-18 11:19
mkmny
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2004-8-17
收藏
得分:0 
以下是引用忆楠在2004-08-18 11:06:34的发言:

呵呵 很漂亮啊 楼上的大哥说不能动 我用win-tc 云彩是有变化的 仔细看看

哪里有变化,我也用Win-tc试了试。还是静态的呀!!!忆楠大哥不会是把眼睛看花了吧?呵呵,不要生气…… 云彩真的在运动吗?


2004-08-18 11:33
忆楠
Rank: 1
等 级:新手上路
帖 子:721
专家分:0
注 册:2004-7-5
收藏
得分:0 
呵呵     我真地看到有变化   也不知道是不是我的眼睛花了````

点 鼠 标 , 救 饥 民 http://www./
2004-08-18 22:15
silvermoon
Rank: 1
等 级:新手上路
帖 子:188
专家分:0
注 册:2004-8-20
收藏
得分:0 
没变化

我是一棵菠菜~~菜菜菜菜菜~~~
2004-08-20 14:54
快速回复:一个模拟自然云朵的C程序(转载) 实在是漂亮!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016762 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved