【开鸿智谷NiobeU4开发板免费试用体验】LVGL移植前菜篇-程序员就要晚点有艺术的(生成艺术图片)

描述

本文来源电子发烧友社区,作者:李先生, 帖子地址:https://bbs.elecfans.com/jishu_2307400_1_1.html


前言

话说没有艺术细胞的程序员不是好码农!

上一次我们进行了LCD的刷屏测试,我们觉得太单调了,程序员就应该玩点有艺术性的。这次我们使用LCD点阵画出各类具有艺术性的图像。

参见https://codegolf.stackexchange.com/

代码

有用到浮点算数运算,需要包含算术库

#include

代码如下

//图片尺寸:

#define DIM 130

//图片尺寸-1

#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;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++)>

效果

开鸿智谷

开鸿智谷

开鸿智谷

开鸿智谷

总结

代码中有大量的浮点运算,本身也可以作为CPU性能的一个对比测试,同时也可以测试刷屏的速率。从效果来看CPU的性能是不错的,刷频效果也可以,后面就正式开始LVGL的移植了。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分