从Matrix67 blog里面看到了Tweetable Mathematical Art。
使用C++实现3个函数RD(i, j), GR(i, j), BL(i, j)分别返回像素(i, j)的R/G/B值,最终生成1幅1024*1024的图片。要求是每个函数代码不超过140字符,即Tweetable。
来个太极八卦图,娱乐一下。
unsigned char RD(int i,int j){ // YOUR CODE HERE #define LEFT (i < DIM/2) #define C1 C(DIM/2, DIM/2, DIM/2) #define C2 C(DIM/2, DIM/4, DIM/4) return BL(i, j); } unsigned char GR(int i,int j){ // YOUR CODE HERE #define C3 C(DIM/2, 3*DIM/4, DIM/4) #define C4 C(DIM/2, DIM/4, DIM/16) #define C5 C(DIM/2, 3*DIM/4, DIM/16) return BL(i, j); } unsigned char BL(int i,int j){ // YOUR CODE HERE #define C(x, y, r) (_sq(i - (x)) + _sq(j - (y)) < _sq((r))) return !C1 ? 127 : C2 ? C4 ? 255 : 0 : C3 ? C5 ? 0: 255 : LEFT ? 0 :255; } unsigned char RD(int i,int j){ #define r(n)(rand()%n) static char c[1024][1024];return!c[i][j]?c[i][j]=!r(999)?r(256):RD((i+r(2))%1024,(j+r(2))%1024):c[i][j]; }
生成图片
时间: 2024-11-12 07:50:52