Source Link
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 #define X 2560 //尽量为8的倍数,若不是X/8需向上取整 6 #define Y 1600 //推荐X、Y比例为(4.0-2.4):1,这样网格为正方形 7 8 9 #define b_start 2.4 10 #define b_end 4.0 11 #define b_len (b_end-b_start) 12 13 #define PI 3.14159265358979323846 14 #define function(_b, _x) (_b*sin(_x*PI)/4) 15 //迭代方程 16 //x = b*x*(1-x) (_b*_x*(1-_x)) 17 //x = b/4*sin(x/pi) (_b*sin(_x*PI)/4) 18 int main(int argc, char **argv) 19 { 20 double x; 21 if(argc==2) 22 x = atof(argv[1]); 23 else 24 x = 0.6; 25 26 unsigned char * data = (unsigned char *)calloc(X*Y/8, 1); 27 28 double b = b_start; 29 for(int i=0;i<X;i++){ //保证x轴取点密度 30 double temp = x; 31 for(int k=0;k<4000;k++){ //先迭代至基本稳定 32 temp = function(b, temp); 33 } 34 for(int k=0;k<1000;k++){ //真正画的部分 35 temp = function(b, temp); 36 int vx = (b-b_start)/b_len*X; //visual(virtual) x 37 int vy = temp*Y; //visual(virtual) y 38 data[(Y-1-vy)*(X/8)+vx/8] |= 1<<(7-vx%8); 39 } 40 b += b_len/X; 41 } 42 //画竖线 43 for(double i=b_start;i<b_end;i+=0.1){ 44 int vx = (i-b_start)/b_len*X; //visual(virtual) x 45 for(int vy=0;vy<Y;vy++){ 46 data[(Y-1-vy)*(X/8)+vx/8] |= 1<<(7-vx%8); 47 } 48 } 49 //画横线 50 for(double i=0;i<1;i+=0.1){ 51 int vy = i*Y; //virsual(virtual) y 52 for(int vx=0;vx<X;vx++){ 53 data[(Y-1-vy)*(X/8)+vx/8] |= 1<<(7-vx%8); 54 } 55 } 56 //图片输出 57 FILE *fp; 58 fp = fopen("0.25 sin(PI x).pbm","wb"); 59 fprintf(fp, "P4 %d %d\n", X, Y); 60 for(int i=0; i<X*Y/8; i++) 61 fputc(data[i], fp); 62 fclose(fp); 63 64 free(data); 65 return 0; 66 }
Demo
x = b * x * (1 - x)
x = b / 4 * sin(PI * x)
标签:Map,int,char,start,Logistic,PI,sin,define From: https://www.cnblogs.com/YHFBlogs/p/16609824.html