圆形
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int color;
int lcd_fd = open("/dev/fb0", O_RDWR);//打开LCD屏的驱动文件
if (-1 == lcd_fd)
{
printf("open lcd error\n");
exit(-1);
}
int colorbuf[480][800] = {0};//定义一个二维数组,大小为开发板的分辨率
int x, y;
for (x = 0; x < 480; x++)
{
for (y = 0; y < 800; y++)
{
//如果满足圆的定义条件x*x+y*y=0;
if ((x - 240) * (x - 240) + (y - 400) * (y - 400) <= 100 * 100)
{
colorbuf[x][y] = 0x00000000;//黑色
continue;
}
else
{
colorbuf[x][y] = 0x00ff0000;//红色
}
}
}
write(lcd_fd, colorbuf, 800 * 480 * 4);
close(lcd_fd);
return 0;
}
彩虹
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
int main()
{
// 打开LCD屏幕文件
int fd = open("/dev/fb0", O_RDWR | O_CREAT);
if(fd == -1)
{
printf("open txt failed\n");
return -1;
}
/*
红色 #FF0000
橙色 #FF7F00
黄色 #FFFF00
绿色 #00FF00
青色 #00FFFF
蓝色 #0000FF
紫色 #8B00FF
0xffffff 白色
*/
// LCD 800*480 v 百度rgb颜色代码 0x ff 80 40
int lcd_buf[480][800];
int color[8] = {0x8b00ff, 0x0000ff, 0x00ffff, 0x00ff00, 0xffff00, 0xff7f00, 0xff0000, 0xffffff};
int i, j, count = 0; // 记录色块落在哪个区间
for(i = 0; i < 480; i++)
{
for(j=-400; j< 400 ;j++)
{
if((480-i)*(480-i)+j*j > 400*400 || (480-i)*(480-i)+j*j < 225){
lcd_buf[i][j+400] = color[7];
}else{
count = sqrt((480-i)*(480-i) + j*j )/55;
lcd_buf[i][j+400] = color[count];
}
}
}
write(fd, lcd_buf, 800*480*4);
// fd文件描述符 指向我们将要写入数据的文件
// buf 数据 我们将要写入数据
// count 计数 我们最多写入多少个字节
close(fd);
return 0;
}