本文來(lái)源電子發(fā)燒友社區(qū),作者:李先生, 帖子地址:https://bbs.elecfans.com/jishu_2307400_1_1.html
前言
話(huà)說(shuō)沒(méi)有藝術(shù)細(xì)胞的程序員不是好碼農(nóng)!
上一次我們進(jìn)行了LCD的刷屏測(cè)試,我們覺(jué)得太單調(diào)了,程序員就應(yīng)該玩點(diǎn)有藝術(shù)性的。這次我們使用LCD點(diǎn)陣畫(huà)出各類(lèi)具有藝術(shù)性的圖像。
參見(jiàn)https://codegolf.stackexchange.com/
代碼
有用到浮點(diǎn)算數(shù)運(yùn)算,需要包含算術(shù)庫(kù)
#include
代碼如下
//圖片尺寸:
#define DIM 130
//圖片尺寸-1
#define DM1 (DIM-1)
#define _sq(x) ((x)*(x)) // 平方
#define _cb(x) abs((x)*(x)*(x)) // 立方的絕對(duì)值
#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;ifor(int j=0;jstatic 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;ifor(int j=0;jstatic 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;ifor(int j=0;jstatic 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;ifor(int j=0;jstatic 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;ifor(int j=0;jstatic 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);
}
}
;j++)>;i++)>;j++)>;i++)>;j++)>;i++)>;j++)>;i++)>;j++)>;i++)>
效果
總結(jié)
代碼中有大量的浮點(diǎn)運(yùn)算,本身也可以作為CPU性能的一個(gè)對(duì)比測(cè)試,同時(shí)也可以測(cè)試刷屏的速率。從效果來(lái)看CPU的性能是不錯(cuò)的,刷頻效果也可以,后面就正式開(kāi)始LVGL的移植了。
-
開(kāi)鴻智谷
+關(guān)注
關(guān)注
2文章
125瀏覽量
1154 -
NiobeU4
+關(guān)注
關(guān)注
3文章
31瀏覽量
508
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論