首页 技术 正文
技术 2022年11月21日
0 收藏 365 点赞 4,623 浏览 3517 个字

信息获得处:http://news.cnblogs.com/n/501488/

分形:http://baike.baidu.com/subview/83243/11213590.htm?fr=aladdin

[C++] 几行代码生成漂亮图片,数学家就是牛! [C++] 几行代码生成漂亮图片,数学家就是牛! [C++] 几行代码生成漂亮图片,数学家就是牛!

[C++] 几行代码生成漂亮图片,数学家就是牛! [C++] 几行代码生成漂亮图片,数学家就是牛! [C++] 几行代码生成漂亮图片,数学家就是牛!

代码:[采用宏定义的来选择绘制不同的图,所以把最后两个给注释掉了,因为宏冲突,想自己试试可以单独编译运行]

PS:生成的图片是ppm格式的要用格式工厂之类的软件进行转换,也可以自己在程序里直接把图片生成bmp或者其他格式的~

 // NOTE: compile with g++ filename.cpp -std=c++11
#include <iostream>
#include <cmath>
#include <cstdlib>
#define DIM 1024
#define DM1 (DIM-1)
#define _sq(x) ((x)*(x)) // square
#define _cb(x) abs((x)*(x)*(x)) // absolute value of cube
#define _cr(x) (unsigned char)(pow ((x),1.0/3.0)) // cube root
#define F unsigned char GR (int,int);
unsigned char BL (int,int); unsigned char RD (int i,int j){
#ifdef A
return (char)(_sq(cos(atan2(j-,i-)/))*);
#endif #ifdef B
#define r(n) (rand ()%n)
static char c[][];
return!c[i][j]?c[i][j]=!r()?r():RD ((i+r())%,(j+r())%):c[i][j];
#endif #ifdef C
float x=,y=;
int k;
for(k=;k++<;){
float a=x*x-y*y+ (i-768.0)/;
y=*x*y+ (j-512.0)/;
x=a;
if(x*x+y*y>)break;
}
return log (k)*;
#endif #ifdef D
double a=,b=,c,d,n=;
while((c=a*a)+(d=b*b)<&&n++<){
b=*a*b+j*8e--.;
a=c-d+i*8e-+.;
}
return *pow ((n-)/,.);
#endif #ifdef E
static double k;
k+=rand ()/./RAND_MAX;
int l=k;
l%=;
return l>?-l:l;
#endif #ifdef F
float s=./(j+);
float y=(j+sin ((i*i+_sq (j-)*)/./DIM)*)*s;
return (int((i+DIM)*s+y)%+int((DIM*-i)*s+y)%)*;
#endif
/*
#ifdef G
#define D DIM
#define M m[(x+D+ (d==0)-(d==2))%D][(y+D+ (d==1)-(d==3))%D]
#define R rand ()%D
#define B m[x][y]
return(i+j)?256-(BL (i,j))/2:0;
#endif
*/
/*
#ifdef H
#define A float a=0,b,k,r,x
#define B int e,o
#define C (x) x>255?255:x
#define R return #define D DIM
R BL (i,j)*(D-i)/D;
#endif
*/
return ;
}
unsigned char GR (int i,int j){
#ifdef A
return (char)(_sq (cos (atan2(j-,i-)/-*acos (-)/))*);
#endif #ifdef B
static char c[][];
return!c[i][j]?c[i][j]=!r()?r():GR ((i+r())%,(j+r())%):c[i][j];
#endif #ifdef C
float x=,y=;
int k;
for(k=;k++<;){
float a=x*x-y*y+ (i-768.0)/;
y=*x*y+ (j-512.0)/;
x=a;
if(x*x+y*y>)break;
}
return log (k)*;
#endif #ifdef D
double a=,b=,c,d,n=;
while((c=a*a)+(d=b*b)<&&n++<){
b=*a*b+j*8e--.;
a=c-d+i*8e-+.;
}
return *pow ((n-)/,.);
#endif #ifdef E
static double k;
k+=rand ()/./RAND_MAX;
int l=k;
l%=;
return l>?-l:l;
#endif #ifdef F
float s=./(j+);
float y=(j+sin ((i*i+_sq (j-)*)/./DIM)*)*s;
return (int(*((i+DIM)*s+y))%+int(*((DIM*-i)*s+y))%)*;
#endif
/*
#ifdef G
#define A
static int m[D][D],e,x,y,d,c[4],f,n;
if (i+j<1){
for (d=D*D;d;d--){
m[d%D][d/D]=d%6?0:rand ()%2000?1:255;
}
for (n=1 return RD (i,j);
#endif
*/
/*
#ifdef H
#define E DM1
#define F static float
#define G for (
#define H r=a*1.6/D+2.4;x=1.0001*b/D
R BL (i,j)*(D-j/2)/D;
#endif
*/
return ;
}
unsigned char BL (int i,int j){
#ifdef A
return (char)(_sq (cos (atan2(j-,i-)/+*acos (-)/))*);
#endif #ifdef B
static char c[][];
return!c[i][j]?c[i][j]=!r()?r():BL((i+r())%,(j+r())%):c[i][j];
#endif #ifdef C
float x=,y=;
int k;
for(k=;k++<;){
float a=x*x-y*y+ (i-768.0)/;
y=*x*y+ (j-512.0)/;
x=a;
if(x*x+y*y>)break;
}
return -log (k)*;
#endif #ifdef D
double a=,b=,c,d,n=;
while((c=a*a)+(d=b*b)<&&n++<){
b=*a*b+j*8e--.;
a=c-d+i*8e-+.;
}
return *pow ((n-)/,.);
#endif #ifdef E
static double k;
k+=rand ()/./RAND_MAX;
int l=k;
l%=;
return l>?-l:l;
#endif #ifdef F
float s=./(j+);
float y=(j+sin ((i*i+_sq (j-)*)/./DIM)*)*s;
return (int(*((i+DIM)*s+y))%+int(*((DIM*-i)*s+y))%)*;
#endif
/*
#ifdef G
A;n;n++){
x=R;y=R;
if(B==1){
f=1;
for(d=0;d<4;d++){
c[d]=M;
f=f<c[d]?c[d]:f;
}
if(f>2){B=f-1;}
else{
++e%=4;
d=e;
if(!c[e]){
B=0;M=1;
}}}}}
return m[i][j];
#endif
*/
/*
#ifdef H
F c[D][D];
if(i+j<1){A;B;G;a<D;a+=0.1){G b=0;b<D;b++){H;G k=0;k<D;k++){x=r*x*(1-x);
if(k>D/2){e=a;o=(E*x);c[e][o]+=0.01;}}}}}
R C (c[j][i])*i/D;
#endif
*/ return ;
} void pixel_write (int,int);
FILE *fp;
int main (){
fp = fopen ("MathPic.ppm","wb");
fprintf (fp, "P6\n%d %d\n255\n", DIM, DIM);
for(int j=;j<DIM;j++)
for(int i=;i<DIM;i++)
pixel_write (i,j);
fclose (fp);
return ;
}
void pixel_write (int i, int j){
static unsigned char color[];
color[] = RD (i,j)&;
color[] = GR (i,j)&;
color[] = BL (i,j)&;
fwrite (color, , , fp);
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849