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

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

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

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);
}

[C++] 几行代码生成漂亮图片,数学家就是牛!的更多相关文章

  1. line-height行高与图片的隐匿文本间隙消除方法

    (标注 文章来源 http://www.zhangxinxu.com/wordpress/2015/08/css-deep-understand-vertical-align-and-line-hei ...

  2. Bootstrap 3之美03-独立行,文字环绕,图片自适应,隐藏元素

    本篇主要包括: ■  添加独立的一行■  文字环绕■  图片自适应■  隐藏元素 添加独立的一行 在id为body的section和id为main的section之间,添加2张图片. 我们发现,新加的 ...

  3. 利用iterm2,在命令行预览图片,服务器也是可以的

    1.首先你本地电脑上要安装iterm2软件,我们这里使用brew安装 这个是一定要装的,因为能在命令行渲染出图片文件全靠它,其实不是服务器渲染出来的,而是iterm2 官方网站:https://www ...

  4. C语言乱谈(一) 20行代码生成BMP

    在学习图形图像的过程中,最简单和常见的格式是BMP和PPM.下面将给出生成BMP的极度精简代码,然后讲解BMP格式. #include <stdio.h> #include <std ...

  5. 微信小程序rich-text 文本首行缩进和图片居中

    微信小程序开发使用rich-text组件渲染html格式的代码,常常因为不能自定义css导致文本不能缩进,以及图片不能居中等问题,这里可以考虑使用js的replace方法,替换字符串,然后在渲染的同时 ...

  6. 使用命令行生成 APNG 图片

    使用 apngasm 工具 下载地址 https://sourceforge.net/projects/apngasm/files/2.91/ 本地源码编译 make 或者 下载对应环境的可执行程序 ...

  7. python学习---50行代码实现图片转字符画1

    转自:https://blog.csdn.net/mm1030533738/article/details/78447714 项目链接: https://www.shiyanlou.com/cours ...

  8. Activiti开发案例之代码生成工作流图片

    图例 环境 软件 版本 SpringBoot 1.5.10 activiti-spring-boot-starter-basic 6.0 生成代码 以下是简化代码: /** * 查看实例流程图,根据流 ...

  9. [测试篇]MarkDown之代码块行号+折叠图片

    对比测试代码编号 $(function(){ $('pre code').each(function(){ texts = $(this).text().replace(/&(?!#?[a-z ...

随机推荐

  1. compile error

    stray \241     程序有非法字符,如空格,引号等,一般因为从别的地方粘贴导致这个错误.

  2. iOS真机调试问题-App installation failed,The maximum number of apps for free development profiles has been reached.

    The maximum number of apps for free development profiles has been reached. 源引:http://www.jianshu.com ...

  3. POJ 1637 Sightseeing tour (混合图欧拉回路)

    Sightseeing tour   Description The city executive board in Lund wants to construct a sightseeing tou ...

  4. [转] 在Linux平台使用mhVTL虚拟化磁带库

    原文来自:LIUBINGLIN ---- http://blog.itpub.net/23135684/viewspace-1307626/ <在Linux平台安装mhVTL虚拟化磁带库> ...

  5. Linux如何学习

    一:如何提问 1. 尝试自己解决 帮助文档 示例 2. 提问的要求 问题要详细(能被别人看懂, 一个知识点) 报错信息(截图) 二:1.Linux区分大小写 2.所有内容以文件形式保存,包括硬件(一切 ...

  6. mybatis 关联查询 association

    <resultMap id="DutyPersonAndFileAndScoreMap" type="com.cares.asis.duty.entity.Duty ...

  7. PRISM ‘VS100COMNTOOLS’ not set. Cannot set the build environment

    prism 注册dll,出现以上错误 在系统环境变量,增加 VS100COMNTOOLS 设置路径C:\Program Files (x86)\Microsoft Visual Studio 11.0 ...

  8. Oracle中的带参数的视图--我们致力于打造人力资源软件

    创建包和包体 create or replace package pkg_pv is procedure set_pv(pv varchar2); function get_pv return var ...

  9. java的面向对象

    Java是1995年诞生.前身oak,后来改名为java. 面向对象的编程思想:对象是万事万物. 对象是由两部分组成的:属性和方法 1:属性是对象的静态特性(名词) 2:方法是对象的动态特性(动词) ...

  10. 模板短信接口调用java,pythoy版(一) 网易云信

    说明 短信服务平台有很多,我只是个人需求,首次使用,算是测试用的,故选个网易(大公司). 稳定性:我只测试了15条短信... 不过前3条短信5分钟左右的延时,后面就比较快.... 我只是需要发短信,等 ...