用c语言编写动态烟花,C语言编写程序输出以下图案必须利用循环语句控制
用c语言编写动态烟花,C语言编写程序输出以下图案必须利用循环语句控制详细介绍
本文目录一览: 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*PI; rad += 0.78 ) /*设定坐标*/
{
a[i++] = x + (int)r *10* cos(rad);
b[ i ] = y + (int)r *10* sin(rad);
}
t = i;
for(i=1;i
<t;i++)
{
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);
}
扩展资料
C语言:表白显示(多彩小心心)
#include
#include
#include
#define I 20
#define R 340
#include
int main()
{
char answer[10];
printf("遇到你\n我才发现\n曾经所有的条件\n似乎都成了我等你的借口\n\n");
printf("我对你的感情已经决堤\n所以\n请允许我,从今往后映入你\n明媚的眼\n");
printf("我\n想和你\n耳鬓厮磨,相濡以沫!");
printf("答应我吧!\n输入yes,你可以看到我的真心\n");
scanf("%s", answer);
float y, x, z, f;
for (y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (x = -1.5f; x < 1.5f; x += 0.05f)
{
z = x * x + y * y - 1;
f = z * z*z - x * x*y*y*y;
putchar(f <= 0.0f ? "*********"[(int)(f*-8.0f)] : ' ');
}
putchar('\n');
}
long time;
for (;;)
{
system("color a");
for (time = 0; time<99999999; time++);
system("color b");
for (time = 0; time<99999999; time++);
system("color c");
for (time = 0; time<99999999; time++);
system("color d");
for (time = 0; time<99999999; time++);
system("color e");
for (time = 0; time<99999999; time++);
system("color f");
for (time = 0; time<99999999; time++);
system("color 0");
for (time = 0; time<99999999; time++);
system("color 1");
for (time = 0; time<99999999; time++);
system("color 2");
for (time = 0; time<99999999; time++);
system("color 3");
for (time = 0; time<99999999; time++);
system("color 4");
for (time = 0; time<99999999; time++);
system("color 5");
for (time = 0; time<99999999; time++);
system("color 6");
for (time = 0; time<99999999; time++);
system("color 7");
for (time = 0; time<99999999; time++);
system("color 8");
for (time = 0; time<99999999; time++);
system("color 9");
}
getchar();
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#define PI 3.14159
void moon()
{
int x=50,y=50,n=30;
setcolor(YELLOW);
setfillstyle(1,YELLOW);
ellipse(x,y,0,360,n,n);
ellipse(x+n/2,y,90,270,n,n);
floodfill(x-n+3,y,YELLOW);
setcolor(BLACK);
circle(x,y,n);
circle(x+n/2,y,n);
}
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 drawstar()
{
int a[]={70,250,190,400,150};
int b[]={43,27,38,79,90},i;
setfillstyle(1,14);
for(i=0;i<5;i++)
{
star(a[i],b[i]);
floodfill(a[i],b[i],YELLOW);
}
}
void starflower()
{
int i=0,j,n=60,n1=2;
int x=200,y=200,size=100;
int cover=0;
int delay1=5000;
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=1000;
}
if(cover==size)
{
i=0;
x=50+rand()%550;
y=rand()%400;
cover=0;
color=rand()%16;
size=50+rand()%250;
delay1=10000;
clearviewport();
drawstar();
moon();
}
i+=n1;
delay(delay1);
}
}
main()
{
int i,j,k;
int gdriver = DETECT, gmode;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"");
drawstar();
moon();
starflower();
}
# define PI 3.14
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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+random(w-1);
doty=1+random(h-1);
color=random(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;
clearviewport();
drawstar();
}
i+=n1;
delay(delay1);
}
}
http://tieba.baidu.com/p/173217066?pn=1
# -*- coding: utf-8 -*-import math, random,timeimport threadingimport tkinter as tkimport re uuidFireworks=[]maxFireworks=8height,width=600,600class firework(object):def __init__(self,color,speed,width,height):=uuid.uuid1()self.radius=random.randint(2,4) ~4像素self.color=color self.speed=speed .5-3.5秒self.status=0 ,status=0;爆炸后,status>=1;当status>100时,烟花的生命期终止self.nParticle=random.randint(20,30) self.center=[random.randint(0,width-1),random.randint(0,height-1)] self.oneParticle=[] (100%状态时)self.rotTheta=random.uniform(0,2*math.pi) :x=a*cos(theta),y=b*sin(theta)=[a,b]
</size)
</n;j++)
</size)
</t;i++)
2022年跨年烟花代码可复制
烟花代码如下:
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; // 烟花绽放的速度
variability = 10;
Max_Number = 980; // 可发出烟花的最大数目
Max_Energy = width + 50;
Max_Patch = 90; // 最大的斑点数
Max_Length = 90; // 斑点的最大距离
G = 150; // 向地面弯曲的力度
bcd = new BeaClassDemo[Max_Number];
for (i = 0; i < Max_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 / 4 + 1;
int P = (int) (Math.random() * Max_Patch * 3 / 4) // 烟花的斑点数
+ Max_Patch / 4 + 1;
int L = (int) (Math.random() * Max_Length * 3 / 4) // 烟花可发射出的距离
+ Max_Length / 4 + 1;
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; i < Max_Number; i++)
sleep = sleep && bcd[i].sleep;
if (sleep && Math.random() * 100 < variability) {
E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4
+ 1;
P = (int) (Math.random() * Max_Patch * 3 / 4) + Max_Patch / 4
+ 1;
L = (int) (Math.random() * Max_Length * 3 / 4) + Max_Length / 4
+ 1;
S = (long) (Math.random() * 10000);
for (i = 0; i < Max_Number; i++) {
if (bcd[i].sleep && Math.random() * Max_Number * L < 1)
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, width + 1, height + 1);
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; i < patch; i++) {
Ex[i] = (int) (Math.random() * energy) - energy / 2;
Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;
public void start
t = 0;
sleep = false;
public void show(Graphics g)
if (!sleep)
if (t < length)
int i, c;
double s;
Color color;
c = (int) (random.nextDouble() * 64) - 32 + Red;
if (c >= 0 && c < 256)
Red = c;
c = (int) (random.nextDouble() * 64) - 32 + Blue;
if (c >= 0 && c < 256)
Blue = c;
c = (int) (random.nextDouble() * 64) - 32 + Green;
if (c >= 0 && c < 256)
Green = c;
color = new Color(Red, Blue, Green);
for (i = 0; i < patch; i++)
s = (double) t / 100;
x = (int) (Ex[i] * s);
y = (int) (Ey[i] * s - G * s * s);
g.setColor(color);
g.drawLine(Xx + x, Xy - y, Xx + x, Xy - y);
if (t >= length / 2)
int j;
for (j = 0; j < 2; j++)
s = (double) ((t - length / 2) * 2 + j) / 100;
x = (int) (Ex[i] * s);
y = (int) (Ey[i] * s - G * s * s);
g.setColor(Color.black);
g.drawLine(Xx + x, Xy - y, Xx + x, Xy - y);
常用的编程语言。
编程语言一:C语言
C语言是世界上最流行、使用最广泛的高级程序设计语言之一。在操作系统和系统使用程序以及需要对硬件进行操作的场合,用C语言明显优于其它高级语言,许多大型应用软件都是用C语言编写的。
编程语言二:java
Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE, JavaEE, JavaME)的总称。
编程语言三:c++
C++这个词在中国大陆的程序员圈子中通常被读做“C加加”,而西方的程序员通常读做“C plus plus" , "CPP”。 它是一种使用非常广泛的计算机编程语言。C++是一种静态数据类型检查的、支持多重编程范式的通用程序设计语言。
大学用代码烟花表白也太帅了吧
C语言烟花氏慧蚂表白程序发给她\他
一、结构
首先当然是我们的老朋友结构体,其中艺术字结构体不用多说,留给大家发挥。
二、初始化
初始化烟花参数,把一切准备工作做好
三、烟花加载函数
加载图片,储存烟花的像素点颜色
四、烟花发射函数
扫描烟花弹并发射,控制开始与停止发射
五、烟花碧巧显示函数
显示花样,如何让烟花变得更好看
六、烟花绽放函数
绽放烟花,烟花个阶段绽放时间间隔,制作变速绽放效果等等
这里大家也可以自己去优化,去增加自己的东西。
七、主函数
通过C程序来模拟警笛、消防车、以及烟花然后的声音效果。
unsigned freq[]={200,100,200,100,200,100,200,100,200,100,200,100,
200,100,200,100,200,100,200,100,200,100,200,100,200,100,-1};
int main()
{
int i = 0;
for(;freq[i]!=-1;i++)
{
_beep(freq[i],500);
}
return 0;
}
如果要其他音效,自己可以动手改freq里面的数值
C语言编写闪烁的红心的程序
#include
#include
#include
void flash();
void main()
{
int DRIVER=DETECT,MODE=DETECT;
initgraph(&DRIVER,&MODE,"");
flash();
getch();
}
void flash()
{
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
while(bioskey(1)==0)
{
cleardevice();
delay(50000);
rectangle(100,100,200,200);
floodfill(150,150,WHITE);
delay(20000);
}
}
1、首先第一步要用在一个项目的spalsh界面,进入应用后弹出这个界面,闪烁完毕后跳入主界面,比纯粹的设置背景图片的splash好看炫酷很多。
2、然后就是要通过自定义view重写onDraw的方法和onSizeChanged方法实现效果。在把自定义view进行应用到布局文件即可。
3、最后就是 TODO: 在此放置代码。
MSG msg;
HACCEL hAccelTable;
// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);LoadString(hInstance, IDC_WIN32WA, szWindowClass, MAX_LOADSTRING);MyRegisterClass(hInstance); // 执行应用程序初始化:if (!InitInstance (hInstance, nCmdShow))
{return FALSE
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32WA))。
模拟烟花的程序,运行总出错,请c语言大师指点!!!
选项->目录->输出目录->不要设置和initgraph(&dr,&mode,"d:\\turboc2");
一样就可以正常执行.
Options->Directories->Output
Directory->不要设置和initgraph(&dr,&mode,"d:\\turboc2");
一样就可以正常执行.
C语言设计一个简单的图形动画,用turboc2运行,怎样编写使图形动起来的代码???
1、首先,打开vc6.0,建立程序编写页面,建立C语言环境,声明两个整数型变量。
2、随后,打出新的前三行,由于规律不明显,就用printf语句手动输入,要仔细观察模版。
3、观察可得,中间三行相同,就可以使用for循环,循环三行,每行的个数要仔细计算,模版很重要。
4、随后的七列逐渐减少,同样使用for循环进行循环七列递减的运算,这样还剩下最后一列。
5、最后一列,只有一个符号,相同于前三行,就是用printf语句直接编写最后一行。
6、这样就完成了程序的编写,这样就可以进行编译了,可以看到编译结果0错误,0警告,就可以运行程序了。
7、运行成功,看到程序运行框中出现了清晰的心图形,成功编程。
如何用C语言制作一个3D的动态火焰效果?
先建立3D动态火焰效果的数学模型;然后设计程序几个主要模块。
再看看别人怎么说的。
用c言制作3d火焰字~~?
咋不用ps呢~~
那这个就有点麻烦~~你要找到相关的图形函数啊~看看有没你需要的图形函数~
嗯,我来说两句。
C语言是可以实现火焰粒子特效的
你的创作思路是:在网上搜集关于火焰粒子特效的文章,比如百度文库,新浪文库、
然后着手编程
编程要注意,既然是C,你可以包含DirectX的库,然后调用别人写好的库函数实现一些基本功能,比如画点,上色,定时,Z缓存,你可以搜directx的使用说明,多得很
动态火焰效果是游戏编程的一部分,额。。涉及挺多的东西,代码无法给你,抱歉
C语言编写程序输出以下图案必须利用循环语句控制
如楼上所说d为7个
#include
int main()
{
int i, j;
for(i = 0; i < 4; i++){
for(j = 1; j <= (i*2 +1); j++){
printf("%c", 'a' + i);
}
printf(" ");
}
for(i = 2; i >= 0; i--){
for(j = 1; j <= (i*2 + 1); j++){
printf("%c", 'a' + i);
}
printf(" ");
}
printf("\n");
return 0;
}
当然,我很乐意帮您解决这个问题。以下是一个使用循环语句控制的C程序,可以输出一个三角形图案:
```
#include
int main() {
int i, j, rows;
printf("请输入行数:");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=1; j<=i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}
```
这个程序首先要求用户输入要输出的行数,然后使用两个嵌套的for循环来打印出图案。外层循环控制行数,内层循环控制每行输出的星号数量。在内层循环中,我们使用printf函数打印一个星号和一个空格,然后在每行的结尾打印一个换行符。
如果您想输出其他形状的图案,只需要对内层循环进行一些修改即可。希望这个程序对您有所帮助!