前言
话说没有艺术细胞的程序员不是好码农!
上一次我们进行了LCD的刷屏测试,我们觉得太单调了,程序员就应该玩点有艺术性的。这次我们使用LCD点阵画出各类具有艺术性的图像。
参见https://codegolf.stackexchange.com/
代码
有用到浮点算数运算,需要包含算术库
#include <math.h>
代码如下
#define DIM 130
#define DM1 (DIM-1)
#define _sq(x) ((x)*(x))
#define _cb(x) abs((x)*(x)*(x))
#define _cr(x) (unsigned short)(pow((x),1.0/3.0))
unsigned char RD(int i,int j){
return (char)(_sq(cos(atan2(j-65,i-65)/2))*255);
}
unsigned char GR(int i,int j){
return (char)(_sq(cos(atan2(j-65,i-65)/2-2*acos(-1)/3))*255);
}
unsigned char BL(int i,int j){
return (char)(_sq(cos(atan2(j-65,i-65)/2+2*acos(-1)/3))*255);
}
unsigned char RD0(int i,int j)
{
float s=3./(j+99);
float y=(j+sin((i*i+_sq(j-700)*5)/100./DIM)*35)*s;
return ((int)((i+DIM)*s+y)%2+(int)((DIM*2-i)*s+y)%2)*127;
}
unsigned char GR0(int i,int j){
float s=3./(j+99);
float y=(j+sin((i*i+_sq(j-700)*5)/100./DIM)*35)*s;
return ((int)(5*((i+DIM)*s+y))%2+(int)(5*((DIM*2-i)*s+y))%2)*127;
}
unsigned char BL0(int i,int j){
float s=3./(j+99);
float y=(j+sin((i*i+_sq(j-700)*5)/100./DIM)*35)*s;
return ((int)(29*((i+DIM)*s+y))%2+(int)(29*((DIM*2-i)*s+y))%2)*127;
}
unsigned char RD1(int i, int j) {
#define r(n)(rand()%n)
static char c[DIM][DIM]; return!c[i][j] ? c[i][j] = !r(999) ? r(256) : RD((i + r(2)) % 1024, (j + r(2)) % 1024) : c[i][j];
}
unsigned char GR1(int i, int j) {
static char c[DIM][DIM]; return!c[i][j] ? c[i][j] = !r(999) ? r(256) : GR((i + r(2)) % 1024, (j + r(2)) % 1024) : c[i][j];
}
unsigned char BL1(int i, int j) {
static char c[DIM][DIM]; return!c[i][j] ? c[i][j] = !r(999) ? r(256) : BL((i + r(2)) % 1024, (j + r(2)) % 1024) : c[i][j];
}
unsigned char RD2(int i, int j) {
static double k; k += rand() / 1. / 0x7FFF; int l = k; l %= 512; return l > 255 ? 511 - l : l;
}
unsigned char GR2(int i, int j) {
static double k; k += rand() / 1. / 0x7FFF; int l = k; l %= 512; return l > 255 ? 511 - l : l;
}
unsigned char BL2(int i, int j) {
static double k; k += rand() / 1. / 0x7FFF; int l = k; l %= 512; return l > 255 ? 511 - l : l;
}
unsigned char RD3(int i, int j) {
return (unsigned char)sqrt((double)(_sq(i - DIM / 2) * _sq(j - DIM / 2)) * 2.0);
}
unsigned char GR3(int i, int j) {
return (unsigned char)sqrt((double)(
(_sq(i - DIM / 2) | _sq(j - DIM / 2)) *
(_sq(i - DIM / 2) & _sq(j - DIM / 2))
));
}
unsigned char BL3(int i, int j) {
return (unsigned char)sqrt((double)(_sq(i - DIM / 2) & _sq(j - DIM / 2)) * 2.0);
}
unsigned char RD4(int i, int j) {
static int r[DIM]; int p = rand() % 9 - 4; r[i] = i & r[i] ? (r[i] + r[i - 1]) / 2 : i ? r[i - 1] : 512; r[i] += r[i] + p > 0 ? p : 0; return r[i] ? r[i] < DIM ? r[i] : DM1 : 0;
}
unsigned char GR4(int i, int j) {
static int r[DIM]; int p = rand() % 7 - 3; r[i] = i & r[i] ? (r[i] + r[i - 1]) / 2 : i ? r[i - 1] : 512; r[i] += r[i] + p > 0 ? p : 0; return r[i] ? r[i] < DIM ? r[i] : DM1 : 0;
}
unsigned char BL4(int i, int j) {
static int r[DIM]; int p = rand() % 15 - 7; r[i] = i & r[i] ? (r[i] + r[i - 1]) / 2 : i ? r[i - 1] : 512; r[i] += r[i] + p > 0 ? p : 0; return r[i] ? r[i] < DIM ? r[i] : DM1 : 0;
}
void StartHdfSPITest(void)
{
static uint16_t gcolor = 0xFFFF;
LcdInit();
while (1) {
for(int i=0;i<ROW_PIXEL;i++)
{
for(int j=0;j<COL_PIXEL;j++)
{
static unsigned short color[3];
color[0] = RD(i,j)&255;
color[1] = GR(i,j)&255;
color[2] = BL(i,j)&255;
uint16_t c = (color[0]>>3) << 11;
c |= (color[1]>>2) << 5;
c |= (color[2]>>3) << 0;
lcd_draw_point(i,j,c);
}
}
LcdPush();
LOS_Msleep(2000);
for(int i=0;i<ROW_PIXEL;i++)
{
for(int j=0;j<COL_PIXEL;j++)
{
static unsigned short color[3];
color[0] = RD1(i,j)&255;
color[1] = GR1(i,j)&255;
color[2] = BL1(i,j)&255;
uint16_t c = (color[0]>>3) << 11;
c |= (color[1]>>2) << 5;
c |= (color[2]>>3) << 0;
lcd_draw_point(i,j,c);
}
}
LcdPush();
LOS_Msleep(2000);
for(int i=0;i<ROW_PIXEL;i++)
{
for(int j=0;j<COL_PIXEL;j++)
{
static unsigned short color[3];
color[0] = RD2(i,j)&255;
color[1] = GR2(i,j)&255;
color[2] = BL2(i,j)&255;
uint16_t c = (color[0]>>3) << 11;
c |= (color[1]>>2) << 5;
c |= (color[2]>>3) << 0;
lcd_draw_point(i,j,c);
}
}
LcdPush();
LOS_Msleep(2000);
for(int i=0;i<ROW_PIXEL;i++)
{
for(int j=0;j<COL_PIXEL;j++)
{
static unsigned short color[3];
color[0] = RD3(i,j)&255;
color[1] = GR3(i,j)&255;
color[2] = BL3(i,j)&255;
uint16_t c = (color[0]>>3) << 11;
c |= (color[1]>>2) << 5;
c |= (color[2]>>3) << 0;
lcd_draw_point(i,j,c);
}
}
LcdPush();
LOS_Msleep(2000);
for(int i=0;i<ROW_PIXEL;i++)
{
for(int j=0;j<COL_PIXEL;j++)
{
static unsigned short color[3];
color[0] = RD4(i,j)&255;
color[1] = GR4(i,j)&255;
color[2] = BL4(i,j)&255;
uint16_t c = (color[0]>>3) << 11;
c |= (color[1]>>2) << 5;
c |= (color[2]>>3) << 0;
lcd_draw_point(i,j,c);
}
}
LcdPush();
LOS_Msleep(2000);
}
}
效果
总结
代码中有大量的浮点运算,本身也可以作为CPU性能的一个对比测试,同时也可以测试刷屏的速率。从效果来看CPU的性能是不错的,刷频效果也可以,后面就正式开始LVGL的移植了。