小球学习之路

#include<graphics.h>
#include<conio.h>
Console Input/Output(控制台输入输出)的简写
conio.h是库文件定义了通过控制台进行数据输入和数据输出的函数,主要是一些用户通过
按键盘产生的对应操作,比如getch函数
#include<stdio.h>
int main()
{
	initgraph(800, 600);//初始一个图
	//宽为800,高为600
	//easyx图形库的坐标原点在左上角
	//x往右增加
	//y往下正向增大
	fillcircle(400, 300, 100);
	//填充圆,有三个参数,400,300为圆心坐标
	//100为圆心半径
	_getch();
	return 0;
}
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
int main()
{
	int width = 800;
	int height = 600;
	int x = 400;
	int y = 300;
	int radius = 50;
	initgraph(width, height);
for循环适用于循环次数,边界固定的情况,反之可用while循环 
	for (y = 300; y < height; y = y + 10) {
		cleardevice();
		fillcircle(x, y, radius);
		Sleep(100);
	}

	return 0;
}
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
int main()
{
	int width = 800;
//画面宽度
	int height = 600;
//画面高度
	int x = 400;
//小球x坐标
	int y = 300;
	int vx = 2;
//小球x方向速度
	int vy = 3;
	int radius = 20;
//小球半径
	initgraph(width, height);
//新开一个画面
	while (1) {
//根据速度,更新小球的位置
		x += vx;
		y += vy;
//小球碰到边界,对应速度反向
		if (x <= radius || x >= width - radius)
			vx = -vx;
		if (y < radius|| y>height-radius)
			vy = -vy;
//清屏		 
		cleardevice();
		fillcircle(x, y, radius);//画小球
		Sleep(5);//暂停毫秒
	}
}
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
int main()
{
	int width = 800;
	int height = 600;
	int x = 400;
	int y = 300;
	int vx = 3;
	int vy = 3;
	int radius = 20;
	initgraph(width, height);
	while (1) {
//根据速度,更新小球的位置
		x = x + vx;
		y = y + vy;
//小球碰到左右边界,x速度反向
		if (x <= radius)
			vx = -vx; 
		if (x >= width - radius)
			vx = -vx;
//小球碰到上下边界,y速度反向
		if (y <= radius)
			vy = -vy;
		if (y >= height - radius)
			vy = -vy;
//左右弹跳
		cleardevice();//清屏
		fillcircle(x, y, radius);
//画小球
		Sleep(10);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值