1.三色旗
这个题比较简单,就是把屏幕分成三块, 屏幕总色素块为 800 *480= 384,000, 将屏幕分为三块,就是每
128,000个色块换一个颜色.
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
// 打开LCD屏幕文件
int fd = open("/dev/fb0", O_RDWR | O_CREAT);
if(fd == -1)
{
printf("open txt failed\n");
return -1;
}
// LCD 800*480 v 百度rgb颜色代码 0x ff 80 40
int lcd_buf[800*480];
//int yello = 0xffff00, black = 0x000, red=0xf44336; // 全部像素的赋值为 橘色
int color[3] = {0xffff00, 0x000000, 0xf44336};
int i, j = 0;
for(i = 0; i < 800*480; i++)
{
lcd_buf[i]=color[j];
if(i%128000==0){
j++;
}
}
write(fd, lcd_buf, 800*480*4);
// fd文件描述符 指向我们将要写入数据的文件
// buf 数据 我们将要写入数据
// count 计数 我们最多写入多少个字节
close(fd);
return 0;
}
// 能否显示三色旗 德国国旗 俄国国旗
// 能否显示七彩虹 弧状七彩虹
结果
2.彩虹图
初看有点难, 不过画一下图就不难了,简单化问题就是判断像素块到圆心的距离,是否在指定之内对应指定的颜色即可.
- 确定圆心 (400,480)
- 划定范围,最长半径为400,划分为7块,每块越占57, 假设中间有一个小圆不要大概半径占15
- 最后每个同心圆的半径差为55
- 最远的一个为400,然后依次是345,290…
-
七颜色代码
红色 #FF0000
橙色 #FF7F00
黄色 #FFFF00
绿色 #00FF00
青色 #00FFFF
蓝色 #0000FF
紫色 #8B00FF -
其他为白色
#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;
}
// 能否显示三色旗 德国国旗 俄国国旗
// 能否显示七彩虹 弧状七彩虹