瞎捣鼓出来的一张壁纸,Using C programming language.
Dependency: STB library
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "include/stb_image_write.h"
int main()
{
char *filename="test.png";
int width = 1220;
int height = 2656;
uint8_t *img_data = (uint8_t*)malloc(width*height*3); // RGB, 3 channels
// circle parameter
int cx = width/2;
int cy = height/2;
int r = 300;
int present_x;
int present_y;
int dis_square; // distance*distance
for(int i=0; i<width*height; i++)
{
present_x = i%width; // present x
present_y = (i-i%width)/width; // present y
dis_square = (present_x - cx)*(present_x - cx) + (present_y - cy)*(present_y - cy);
if(dis_square < r*r)
{
img_data[i*3 + 0] = ( (int) (abs(tan( (float)(i/4) ))) )%255; // R
img_data[i*3 + 1] = ( (int) (abs(tan( (float)(i/4) ))) )%255; // G
img_data[i*3 + 2] = ( (int) (abs(tan( (float)(i/4) ))) )%255; // B
}
else if( (dis_square < (r+1)*(r+1) ) && (dis_square >= r*r) )
{
img_data[i*3 + 0] = 200; // R
img_data[i*3 + 1] = 200; // G
img_data[i*3 + 2] = 200; // B
}
else if( (dis_square < (r+2)*(r+2) ) && (dis_square >= (r+1)*(r+1) ) )
{
img_data[i*3 + 0] = 100;
img_data[i*3 + 1] = 100;
img_data[i*3 + 2] = 100;
}
else
{
img_data[i*3 + 0] = 0;
img_data[i*3 + 1] = 0;
img_data[i*3 + 2] = 0;
}
}
stbi_write_png(filename, width, height, 3, img_data, width*3);
free(img_data);
return 0;
}