farmerbuff(C语言实现小球)

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#define FB "/dev/fb0"
int main()
{
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
__u32 height;
__u32 width;
__u32 bpp;
__u32 length;
char *man, *tmp;
int fd;
int i, j;
int x = 50;
int y = 50;
int flag_x = 1;
int flag_y = 1;


fd = open(FB, O_RDWR);
if(fd < 0) {
perror("open");
return fd;
}
ioctl(fd, FBIOGET_VSCREENINFO, &var);
ioctl(fd, FBIOGET_FSCREENINFO, &fix);


width = var.xres_virtual;
height = var.yres_virtual;
bpp = (var.bits_per_pixel + 7) / 8;
length = fix.line_length / bpp;


printf("%d, %d, %d, %d", width, height, bpp, length);


man = (char *)mmap(NULL,length * height * bpp, PROT_WRITE, MAP_SHARED, fd, 0);


while (1) {
tmp = man;
for (i = 0; i < height; i++) {
for (j = 0; j < length; j++) {
if ((i - x) * (i - x) + (j - y) * (j - y) <= 2500)
*tmp++ = 255;
else
*tmp++ = 0;


*tmp++ = 0;
*tmp++ = 1;
*tmp++ = 0;


}
}


if (x + 50 >= height)
flag_x = 1;
if (x <= 50)
flag_x = -1;
if (y + 50 >= width)
flag_y = 1;
if (y <= 50)
flag_y = -1;


if (flag_x == 1)
x -= 50;
if (flag_x == -1)
x += 50;
if (flag_y == 1)
y -= 50;
if (flag_y == -1)
y += 50;
sleep(1);
}


close(fd);


return 0;


}#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>

#define FB "/dev/fb0"
int main()
{
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
__u32 height;
__u32 width;
__u32 bpp;
__u32 length;
char *man, *tmp;
int fd;
int i, j;
int x = 50;
int y = 50;
int flag_x = 1;
int flag_y = 1;


fd = open(FB, O_RDWR);
if(fd < 0) {
perror("open");
return fd;
}
ioctl(fd, FBIOGET_VSCREENINFO, &var);
ioctl(fd, FBIOGET_FSCREENINFO, &fix);


width = var.xres_virtual;
height = var.yres_virtual;
bpp = (var.bits_per_pixel + 7) / 8;
length = fix.line_length / bpp;
printf("%d, %d, %d, %d", width, height, bpp, length);
man = (char *)mmap(NULL,length * height * bpp, PROT_WRITE, MAP_SHARED, fd, 0);
while (1) {
tmp = man;
for (i = 0; i < height; i++) {
for (j = 0; j < length; j++) {
if ((i - x) * (i - x) + (j - y) * (j - y) <= 2500)
*tmp++ = 255;
else
*tmp++ = 0;

        *tmp++ = 0;
*tmp++ = 1;
*tmp++ = 0;


}
}

if (x + 50 >= height)
flag_x = 1;
if (x <= 50)
flag_x = -1;
if (y + 50 >= width)
flag_y = 1;
if (y <= 50)
flag_y = -1;


if (flag_x == 1)
x -= 50;
if (flag_x == -1)
x += 50;
if (flag_y == 1)
y -= 50;
if (flag_y == -1)
y += 50;
sleep(1);
}
close(fd);
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值