c语言编程烟花代码简单如下:
#include "stdlib.h"
#include "graphics.h"
#include "stdio.h"
#include "math.h"
#include "conio.h "
#define PI 3.1425926
main()
{
int gdriver=DETECT,gmode,errorcode
int a[10],b[10],x,y,c,r,i,j,t
double rad = 0.0
/* initialize graphics and local variables */
initgraph(&gdriver , &gmode ,"竖迹弊"州纯)
/* read result of initialization */
errorcode = graphresult()
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error : %s/n",grapherrormsg(errorcode))
printf("Please any key to halt:")
getch()
exit(1) /* terminate with an error code */
}
randomize()
for(!kbhit())
{
x=rand()%500+100/*随机中心坐标*/
y=rand()%300+100
for(r = 0 r <= 8 r++ ) /*烟花的大小设定*/
{
for(i = 0,rad = 0.0 rad <2*PIrad += 0.78 ) /*设余族定坐标*/
{
a[i++] = x + (int)r *10* cos(rad)
b[ i ] = y + (int)r *10* sin(rad)
}
t = i
for(i=1i<ti++)
{
c=rand()%13+1/*各点的颜色随机*/
setcolor(c) /*功能:将当前图形屏幕的当前笔画颜色置为color.*/
circle(a[i],b[i],1)/* a[i],b[i] 为圆心 1 为半径 画圆 */
}
delay(10000)
delay(10000)
cleardevice()
函数名: cleardevice
功 能: 清除图形屏幕
用 法: void far cleardevice(void)
}
}
getch()
closegraph()
函数名: closegraph
功 能: 关闭图形系统
用 法: void far closegraph(void)
}
初始化烟花参数
void Init( int i )
{
// 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量
int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 }
int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 }
int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 }
/**** 初始化烟花 *****/
Fire[i].x = 0// 烟花中心坐标
Fire[i].y = 0
Fire[i].width = 240// 图片宽
Fire[i].height = 240// 图片高
Fire[i].max_r = r[i]// 最大半径
Fire[i].cen_x = x[i]// 中心距左上角距离
Fire[i].cen_y = y[i]
Fire[i].show = false// 是否绽放
Fire[i].dt = 5// 绽放时间间隔
Fire[i].t1 = timeGetTime()
Fire[i].r = 0// 从 0 开始绽放
/**** 初始化烟花d *****/
Jet[i].x = -240// 烟花d左上角坐标
Jet[i].y = -240
Jet[i].hx = -240// 烟花d发射最高点坐标
Jet[i].hy = -240
Jet[i].height = 0// 发射高度
Jet[i].t1 = timeGetTime()
Jet[i].dt = rand() % 10// 发射速度时间间隔
Jet[i].n = 0// 烟花d闪烁图片下标
Jet[i].shoot = false// 是否发射
}
先物埋森建立一个图液配片框,一个时钟控件罩亩,Interval属性设为100,代码如下:Private Sub Form_Click()
Picture1.ScaleMode = 3
Picture1.Scale (-3, 3)-(3, -3)
Picture1.Line (-0.3, -2)-(0.3, -3), , BF
End Sub
Private Sub Timer1_Timer()
Dim i As Single
Picture1.DrawWidth = 2
For i = 0.15 To 3 Step 0.001
Picture1.PSet (i, Log(i)), RGB(255, 0, 1)
Next
For i = 0.15 To 3 Step 0.001
Picture1.PSet (i, Log(i)), Form1.BackColor
Next
For i = -0.15 To -3 Step -0.001
Picture1.PSet (i, Log(-i)), RGB(255, 0, 1)
Next
For i = -0.15 To -3 Step -0.001
Picture1.PSet (i, Log(-i)), Form1.BackColor
Next
For i = -2 To 3 Step 0.001
Picture1.PSet (0, i), RGB(255, 0, 0)
Next i
For i = -2 To 3 Step 0.001
Picture1.PSet (0, i), Form1.BackColor
Next i
End Sub
/**屏保程序--源代码及关键源代码注解如下:*/#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <math.h>
#include <bios.h>
#include<stdlib.h>
void Clock_f()/*时钟*/
{
int gd=DETECT,gm,no,rad=210
struct time t
float theta,x,y,x1,y1,theta1,theta2
char des[40],ch
initgraph(&gd,&gm,"")
setcolor(14)
circle(320,240,180)
circle(320,240,15)
setcolor(BLACK)
circle(320,240,170)
circle(320,240,165)
circle(320,240,158)
circle(320,240,16)
setcolor(11)
for(theta=0.0,no=0no<60no++,theta+=.1047)
{
if(no%5==0)
{
x=320+158*cos(theta)
y=240+158*sin(theta)
}
else
{
x=320+165*cos(theta)
y=240+165*sin(theta)
}
x1=320+170*cos(theta)
y1=240+170*sin(theta)
line(x,y,x1,y1)
}
settextjustify(CENTER_TEXT,CENTER_TEXT)
setcolor(YELLOW)
for(no=1,theta=5.236no<=12no++,theta+=.524)
{
x=320+rad*cos(theta)
y=240+rad*sin(theta)
settextstyle(GOTHIC_FONT,HORIZ_DIR,5)
sprintf(des,"%d",no)
outtextxy(x,y,des)
}
gettime(&t)
theta1=(.0175*6*t.ti_min)-1.5708
theta2=(.0175*30*(t.ti_hour%12+t.ti_min/60.0))-1.5708
while(bioskey(1)==0)
{
gettime(&t)
theta=(.0175*6*t.ti_sec)-1.5708
x=320+15*cos(theta)
y=240+15*sin(theta)
x1=320+150*cos(theta)
y1=240+150*sin(theta)
setcolor(11)
setlinestyle(SOLID_LINE,1,1)
line(x,y,x1,y1)
sound(7000)
delay(100)
nosound()
delay(900)
setcolor(BLACK)
line(x,y,x1,y1)
setlinestyle(SOLID_LINE,1,3)
x=320+15*cos(theta1)
y=240+15*sin(theta1)
x1=320+150*cos(theta1)
y1=240+150*sin(theta1)
line(x,y,x1,y1)
x=320+15*cos(theta2)
y=240+15*sin(theta2)
x1=320+100*cos(theta2)
y1=240+100*sin(theta2)
line(x,y,x1,y1)
theta1=(.0175*6*(t.ti_min+t.ti_sec/60.0))-1.5708
x=320+15*cos(theta1)
y=240+15*sin(theta1)
x1=320+150*cos(theta1)
y1=240+150*sin(theta1)
setcolor(14)
line(x,y,x1,y1)
circle(320,240,15)
theta2=(.0175*30*(t.ti_hour%12+t.ti_min/60.0))-1.5708
x=320+15*cos(theta2)
y=240+15*sin(theta2)
x1=320+100*cos(theta2)
y1=240+100*sin(theta2)
line(x,y,x1,y1)
}
getch()
closegraph()
}
void Boom_f(void)/*礼花*/
{
int gd=DETECT, gm
int maxx=0, maxy=0, midx=0, midy=0, a=0, b=0, x=0, y=0, k=0
initgraph(&gd, &gm, "")
maxx=getmaxx(), maxy=getmaxy(), midx=maxx/2, midy=maxy/2
randomize()
while(bioskey(1)==0)
{
x=60
y=50
for(b=-100b<=100b+=10)
{
k=random(15)
if(k==0)k=1
for(a=0a<=50a++)
{
{
putpixel((midx+a)+b, (midy+a)+b, k)
putpixel((midx+a)+b, (midy-a)+b, k)
putpixel((midx-a)+b, (midy+a)+b, k)
putpixel((midx-a)+b, (midy-a)+b, k)}
putpixel((midx)+b, (midy+a)+b, k+8)
putpixel((midx)+b, (midy-a)+b, k+8)
putpixel((midx+a)+b, (midy)+b, k+8)
putpixel((midx-a)+b, (midy)+b, k+8)
putpixel((midx+a)+b+x, (midy+a)+b+y, k)
putpixel((midx+a)+b+x, (midy-a)+b+y, k)
putpixel((midx-a)+b+x, (midy+a)+b+y, k)
putpixel((midx-a)+b+x, (midy-a)+b+y, k)
putpixel((midx)+b+x, (midy+a)+b+y, k+8)
putpixel((midx)+b+x, (midy-a)+b+y, k+8)
putpixel((midx+a)+b+x, (midy)+b+y, k+8)
putpixel((midx-a)+b+x, (midy)+b+y, k+8)
putpixel((midx+a)+b-x, (midy+a)+b-y, k)
putpixel((midx+a)+b-x, (midy-a)+b-y, k)
putpixel((midx-a)+b-x, (midy+a)+b-y, k)
putpixel((midx-a)+b-x, (midy-a)+b-y, k)
putpixel((midx)+b-x, (midy+a)+b-y, k+8)
putpixel((midx)+b-x, (midy-a)+b-y, k+8)
putpixel((midx+a)+b-x, (midy)+b-y, k+8)
putpixel((midx-a)+b-x, (midy)+b-y, k+8)
putpixel((midx+a)+b+x, (midy+a)+b-y, k)
putpixel((midx+a)+b+x, (midy-a)+b-y, k)
putpixel((midx-a)+b+x, (midy+a)+b-y, k)
putpixel((midx-a)+b+x, (midy-a)+b-y, k)
putpixel((midx)+b+x, (midy+a)+b-y, k+8)
putpixel((midx)+b+x, (midy-a)+b-y, k+8)
putpixel((midx+a)+b+x, (midy)+b-y, k+8)
putpixel((midx-a)+b+x, (midy)+b-y, k+8)
putpixel((midx+a)+b-x, (midy+a)+b+y, k)
putpixel((midx+a)+b-x, (midy-a)+b+y, k)
putpixel((midx-a)+b-x, (midy+a)+b+y, k)
putpixel((midx-a)+b-x, (midy-a)+b+y, k)
putpixel((midx)+b-x, (midy+a)+b+y, k+8)
putpixel((midx)+b-x, (midy-a)+b+y, k+8)
putpixel((midx+a)+b-x, (midy)+b+y, k+8)
putpixel((midx-a)+b-x, (midy)+b+y, k+8)
/*beginning if(a<36)*/
circle((midx+a)+b, (midy+a)+b, k)
circle((midx+a)+b, (midy-a)+b, k)
circle((midx-a)+b, (midy+a)+b, k)
circle((midx-a)+b, (midy-a)+b, k)
circle((midx)+b, (midy+a)+b, k+8)
circle((midx)+b, (midy-a)+b, k+8)
circle((midx+a)+b, (midy)+b, k+8)
circle((midx-a)+b, (midy)+b, k+8)
circle((midx+a)+b+x, (midy+a)+b+y, k)
circle((midx+a)+b+x, (midy-a)+b+y, k)
circle((midx-a)+b+x, (midy+a)+b+y, k)
circle((midx-a)+b+x, (midy-a)+b+y, k)
circle((midx)+b+x, (midy+a)+b+y, k+8)
circle((midx)+b+x, (midy-a)+b+y, k+8)
circle((midx+a)+b+x, (midy)+b+y, k+8)
circle((midx-a)+b+x, (midy)+b+y, k+8)
circle((midx+a)+b-x, (midy+a)+b-y, k)
circle((midx+a)+b-x, (midy-a)+b-y, k)
circle((midx-a)+b-x, (midy+a)+b-y, k)
circle((midx-a)+b-x, (midy-a)+b-y, k)
circle((midx)+b-x, (midy+a)+b-y, k+8)
circle((midx)+b-x, (midy-a)+b-y, k+8)
circle((midx+a)+b-x, (midy)+b-y, k+8)
circle((midx-a)+b-x, (midy)+b-y, k+8)
circle((midx+a)+b+x, (midy+a)+b-y, k)
circle((midx+a)+b+x, (midy-a)+b-y, k)
circle((midx-a)+b+x, (midy+a)+b-y, k)
circle((midx-a)+b+x, (midy-a)+b-y, k)
circle((midx)+b+x, (midy+a)+b-y, k+8)
circle((midx)+b+x, (midy-a)+b-y, k+8)
circle((midx+a)+b+x, (midy)+b-y, k+8)
circle((midx-a)+b+x, (midy)+b-y, k+8)
circle((midx+a)+b-x, (midy+a)+b+y, k)
circle((midx+a)+b-x, (midy-a)+b+y, k)
circle((midx-a)+b-x, (midy+a)+b+y, k)
circle((midx-a)+b-x, (midy-a)+b+y, k)
circle((midx)+b-x, (midy+a)+b+y, k+8)
circle((midx)+b-x, (midy-a)+b+y, k+8)
circle((midx+a)+b-x, (midy)+b+y, k+8)
circle((midx-a)+b-x, (midy)+b+y, k+8)
delay(25)
cleardevice()
}
}
}
closegraph()
}
void main(void)
{
int nChoice
do
{
printf("\n\t1. CLOCK\n")
printf("\t2. BOOM\n")
printf("\t3. EXIT\n")
scanf("%d",&nChoice)
switch(nChoice)
{
case 1:
Clock_f()
break
case 2:
Boom_f()
break
case 3:
break
default:
printf("input again\n")
}
}while(nChoice!=3)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)