Discuz! Board

 找回密码
 立即注册
查看: 278|回复: 0

10.28 小球

[复制链接]

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
发表于 2022-10-28 19:57:18 | 显示全部楼层 |阅读模式
[C++] 纯文本查看 复制代码
#include <graphics.h>                 //包含EGE的头文件
#include <time.h>
float rnx(int min,int max)
{
	float t;
	t=rand()%(max-min)+min;
	return t;
}
struct ballon
{
	int r;
	double g,y,x,vy,vx;
	unsigned int R_color,G_color,B_color;
}ball[10];
int height=600,width=800;
int main()
{
	srand(time(0));//随机种子函数  
	for(int i=0;i<10;i++){
        ball[i].x = rnx(ball[i].r,width-ball[i].r);
        ball[i].y = rnx(ball[i].r,height-ball[i].r);
        ball[i].vx = rnx(3,5);
        ball[i].vy = rnx(3,5);
        ball[i].r = 10+rand()%10;  
        ball[i].R_color = rnx(10,255);
        ball[i].G_color = rnx(10,255);
        ball[i].B_color = rnx(10,255);

	}
    initgraph(width, height);               //初始化图形界面
     
    setcolor(BLACK);  //设置画图线为黑色 
     
    setbkcolor(YELLOW);//设置背景颜色为黄色
     
    setfillcolor(RED);//设置填充颜色为红色 
    while(1)
    {
        cleardevice();
		
        for(int t=0;t<=9;t++)
		{
			
        	ball[t].vy+=ball[t].g;
	        //ball[t].vx+=ball[t].g;
	        ball[t].x+=ball[t].vx;
	        ball[t].y+=ball[t].vy;
		
        	
	        if(ball[t].y>=height-ball[t].r)
	        {
	            ball[t].vy=-ball[t].vy;
	            ball[t].y=height-ball[t].r;
	        }
	        if(ball[t].y<=ball[t].r)
	        {
	            ball[t].vy=-ball[t].vy;
	        }
	        if(ball[t].x>=width-ball[t].r)
	        {
	            ball[t].vx=-ball[t].vx;
	            ball[t].x=width-ball[t].r;
	        }
	        if(ball[t].x<=ball[t].r)
	        {
	            ball[t].vx=-ball[t].vx;
	        }
	        fillellipse(ball[t].x, ball[t].y,  ball[t].r,  ball[t].r);
	        setfillcolor(EGERGB(ball[t].R_color, ball[t].G_color, ball[t].B_color));
		}
        Sleep(10);
    }
     
 
     
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 10:57 , Processed in 0.050900 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表