在VC上可以运行的烟花代码~
2017-02-01 16:12
141 查看
# define PI 3.14
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
void star(int x,int y);
void drawstar();
void Putstar(void);
void starflower();
int main()
{
int gdriver=DETECT;
int gmode=0;
initgraph(&gdriver,&gmode,"c:\\tc20\\bgi");
drawstar();
starflower();
getch();
closegraph();
return 0;
}
void star(int x,int y)
{
int i,a;
int n=5;
int x1[5],y1[5],x2[5],y2[5];
setcolor(YELLOW);
for(i=0;i<5;i++)
{
x1[i]=x+n*cos(i*72*PI/180);
y1[i]=y+n*sin(i*72*PI/180);
x2[i]=x+n/2*cos(i*72*PI/180+PI/5);
y2[i]=y+n/2*sin(i*72*PI/180+PI/5);
}
for(i=0;i<5;i++)
{
a=i+1;
if(a>4) a=0;
line(x1[i],y1[i],x2[i],y2[i]);
line(x2[i],y2[i],x1[a],y1[a]);
}
}
void Putstar(void)
{
int seed=1858;
int i,dotx,doty,h,w,color,maxcolor;
w=getmaxx();
h=getmaxy();
srand(seed);
for(i=0;i<100;++i)
{dotx=i+rand()%(w-1);
doty=1+rand()%(h-1);
color=rand()%(h-1);
setcolor(color);
putpixel(dotx,doty,color);
circle(dotx+1,doty+1,1);
}
srand(seed);
}
void drawstar()
{
int a[]={70,280,230,440,140,110,180,90,500,360};
int b[]={50,27,88,99,100,37,67,98,60,78},i;
setfillstyle(1,14);
for(i=0;i<10;i++)
{
star(a[i],b[i]);
floodfill(a[i],b[i],YELLOW);
}
Putstar();
}
void starflower()
{
int i=0,j,n=60,n1=2;
int x=200,y=200,size=100;
int cover=0;
int delay1=20;
int wid,hei;
int px,py;
int color=9;
while(!kbhit())
{
if(i<size)
{
for(j=0;j<n;j++)
{
px=x+i*cos(j*360/n*PI/180);
py=y+i*sin(j*360/n*PI/180);
putpixel(px,py,rand()%16);
putpixel(px-1,py,color);
putpixel(px,py+1,color);
putpixel(px+1,py-1,YELLOW);
putpixel(px,py-1,YELLOW);
putpixel(px+1,py,RED);
putpixel(px+1,py+1,RED);
}
}
if(i>size&&cover<size)
{
setcolor(BLACK);
circle(x,y,cover++);
delay1=20;
}
if(cover==size)
{
i=0;
x=50+rand()%550;
y=rand()%400;
cover=0;
color=rand()%16;
size=50+rand()%250;
delay1=40;
drawstar();
}
i+=n1;
Sleep(delay1);
}
}
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
void star(int x,int y);
void drawstar();
void Putstar(void);
void starflower();
int main()
{
int gdriver=DETECT;
int gmode=0;
initgraph(&gdriver,&gmode,"c:\\tc20\\bgi");
drawstar();
starflower();
getch();
closegraph();
return 0;
}
void star(int x,int y)
{
int i,a;
int n=5;
int x1[5],y1[5],x2[5],y2[5];
setcolor(YELLOW);
for(i=0;i<5;i++)
{
x1[i]=x+n*cos(i*72*PI/180);
y1[i]=y+n*sin(i*72*PI/180);
x2[i]=x+n/2*cos(i*72*PI/180+PI/5);
y2[i]=y+n/2*sin(i*72*PI/180+PI/5);
}
for(i=0;i<5;i++)
{
a=i+1;
if(a>4) a=0;
line(x1[i],y1[i],x2[i],y2[i]);
line(x2[i],y2[i],x1[a],y1[a]);
}
}
void Putstar(void)
{
int seed=1858;
int i,dotx,doty,h,w,color,maxcolor;
w=getmaxx();
h=getmaxy();
srand(seed);
for(i=0;i<100;++i)
{dotx=i+rand()%(w-1);
doty=1+rand()%(h-1);
color=rand()%(h-1);
setcolor(color);
putpixel(dotx,doty,color);
circle(dotx+1,doty+1,1);
}
srand(seed);
}
void drawstar()
{
int a[]={70,280,230,440,140,110,180,90,500,360};
int b[]={50,27,88,99,100,37,67,98,60,78},i;
setfillstyle(1,14);
for(i=0;i<10;i++)
{
star(a[i],b[i]);
floodfill(a[i],b[i],YELLOW);
}
Putstar();
}
void starflower()
{
int i=0,j,n=60,n1=2;
int x=200,y=200,size=100;
int cover=0;
int delay1=20;
int wid,hei;
int px,py;
int color=9;
while(!kbhit())
{
if(i<size)
{
for(j=0;j<n;j++)
{
px=x+i*cos(j*360/n*PI/180);
py=y+i*sin(j*360/n*PI/180);
putpixel(px,py,rand()%16);
putpixel(px-1,py,color);
putpixel(px,py+1,color);
putpixel(px+1,py-1,YELLOW);
putpixel(px,py-1,YELLOW);
putpixel(px+1,py,RED);
putpixel(px+1,py+1,RED);
}
}
if(i>size&&cover<size)
{
setcolor(BLACK);
circle(x,y,cover++);
delay1=20;
}
if(cover==size)
{
i=0;
x=50+rand()%550;
y=rand()%400;
cover=0;
color=rand()%16;
size=50+rand()%250;
delay1=40;
drawstar();
}
i+=n1;
Sleep(delay1);
}
}
相关文章推荐
- extjs中的JS代码在firefox可以正常运行,在IE中无法运行的方法。
- 用vc2010以上版本编译可以在低版本xp和2003的运行程序的方法
- 经过测试的 可以使用的远程注入代码!!!!!我的VC里面缺少一个stdafx.h需要拷贝一个到程序
- 在VC++项目中使用.Net库,经过简单转换,可以直接使用C#代码
- VS如何完美运行VC++程序代码
- 猛犸代码助手V3.0 最新版代码生成器 可以生成C#Winform \VC++MFC代码
- 我们可以在同一个虚拟机中运行 Python 2 和 3 代码而不需要更改代码吗?
- extjs中的JS代码在firefox可以正常运行,在IE中无法运行的方法。
- HTML代码中,加这段声明 就可以 用IE7的方式 解析了,让IE8始终以IE7兼容模式运行网页
- C++ windows多线程 线程描述了进程内代码的执行路径。进程中同时可以有多个线程在执行,为了使他们能够同时运行,操作系统为每个线程轮流分配CPU时间片,为了充分地利用CPU提高软件产品的性能,一
- 如何打包VC程序,在一个没有安装VC的电脑上也可以运行
- 如何把代码中的SQL语句改成可以直接在数据库中运行的SQL语句
- iphone 代码在真机上可以运行但在模拟其上不可运行
- 网页注册机运行成功了!!!那个激动啊!!(VC下纯C代码) 记下我编写注册机的全过程
- 可以测试javascript运行效果的代码
- autocad.net将代码保存到图纸中,打开图纸后可以直接运行?
- JDK安装成功了,环境变量也配置好了,测试代码也可以运行,但是打不开eclipse
- 本地代码可以正常运行,其他人的不能正常运行???
- 启动VC++2010时显示“您可以在命令行上使用/log参数运行应用程序”的解决办法
- 使用vc2010的c++0x特性,我们可以写出简洁有趣的代码