我公开以下图片的源代码,,是ppm格式的,,自己找到能打开的工具..

(非原创,我加工的代码,可直接执行运行输出,缩略图能看到效果)
 这是原博客 http://news.cnblogs.com/n/501488/
 
本人测试可在Visual Studio 2012 中运行

请教高手一个问题,,
就是如何 调用动态方面名,,方面名均为后缀+数字,
希望可以根据动态方面名来调用不同的方法...
我觉得就是太多重复的代码了..我想用C++类泛型,,应该可以调用相应的方法.

 

以下是 C++ 的代码,,,

#include "stdafx.h"

#include <iostream>
#include <cmath>
#include <cstdlib>
#include<Windows.h> #pragma warning(disable:4996) //全部关掉
#pragma warning(disable:4244) #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 unsigned char GR (int ,int);
unsigned char BL (int ,int); unsigned char RD1 (int i,int j){
float x=0,y=0;
int k;
for(k=0;k++<256;)
{
float a=x*x-y*y+ (i-768.0)/512;
y=2*x*y+ (j-512.0)/512;
x=a;
if(x*x+y*y>4)
break;
}
return log (k)*47;
} unsigned char GR1 (int i,int j){
float x=0,y=0;
int k;
for(k=0;k++<256;)
{
float a=x*x-y*y+ (i-768.0)/512;y=2*x*y+ (j-512.0)/512;
x=a;
if(x*x+y*y>4)
break;
}
return log (k)*47;
} unsigned char BL1 (int i,int j){
float x=0,y=0;
int k;
for(k=0;k++<256;)
{
float a=x*x-y*y+ (i-768.0)/512;
y=2*x*y+ (j-512.0)/512;
x=a;
if(x*x+y*y>4)
break;
}
return 128-log (k)*23;
} 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];
} unsigned char GR (int i,int j)
{
static char c[1024][1024];
return!c[i][j]?c[i][j]=!r(999)?r(256):GR ((i+r(2))%1024,(j+r(2))%1024):c[i][j];
} unsigned char BL (int i,int j)
{
static char c[1024][1024];
return!c[i][j]?c[i][j]=!r(999)?r(256):BL ((i+r(2))%1024,(j+r(2))%1024):c[i][j];
} unsigned char RD2 (int i,int j){
double a=0,b=0,c,d,n=0;
while((c=a*a)+(d=b*b)<4&&n++<880)
{b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
return 255*pow ((n-80)/800,3.);
} unsigned char GR2 (int i,int j){
double a=0,b=0,c,d,n=0;
while((c=a*a)+(d=b*b)<4&&n++<880)
{b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
return 255*pow ((n-80)/800,.7);
} unsigned char BL2 (int i,int j){
double a=0,b=0,c,d,n=0;
while((c=a*a)+(d=b*b)<4&&n++<880)
{b=2*a*b+j*8e-9-.645411;a=c-d+i*8e-9+.356888;}
return 255*pow ((n-80)/800,.5);
} unsigned char RD3 (int i,int j){
static double k;k+=rand ()/1./RAND_MAX;int l=k;l%=512;return l>255?511-l:l;
} unsigned char GR3 (int i,int j){
static double k;k+=rand ()/1./RAND_MAX;int l=k;l%=512;return l>255?511-l:l;
} unsigned char BL3 (int i,int j){
static double k;k+=rand ()/1./RAND_MAX;int l=k;l%=512;return l>255?511-l:l;
} unsigned char RD4 (int i,int j){
float s=3./(j+99);
float y=(j+sin ((i*i+_sq (j-700)*5)/100./DIM)*35)*s;
return (int((i+DIM)*s+y)%2+int((DIM*2-i)*s+y)%2)*127;
} unsigned char GR4 (int i,int j){
float s=3./(j+99);
float y=(j+sin ((i*i+_sq (j-700)*5)/100./DIM)*35)*s;
return (int(5*((i+DIM)*s+y))%2+int(5*((DIM*2-i)*s+y))%2)*127;
} unsigned char BL4 (int i,int j){
float s=3./(j+99);
float y=(j+sin ((i*i+_sq (j-700)*5)/100./DIM)*35)*s;
return (int(29*((i+DIM)*s+y))%2+int(29*((DIM*2-i)*s+y))%2)*127;
} void pixel_write (int,int);
FILE *fp; void pixel_write1(int i, int j)
{
static unsigned char color[3];
color[0] = RD1 (i,j)&255;
color[1] = GR1 (i,j)&255;
color[2] = BL1 (i,j)&255;
fwrite (color, 1, 3, fp);
} void pixel_write2 (int i, int j)
{
static unsigned char color[3];
color[0] = RD2 (i,j)&255;
color[1] = GR2 (i,j)&255;
color[2] = BL2 (i,j)&255;
fwrite (color, 1, 3, fp);
} void pixel_write3(int i, int j)
{
static unsigned char color[3];
color[0] = RD3 (i,j)&255;
color[1] = GR3 (i,j)&255;
color[2] = BL3 (i,j)&255;
fwrite (color, 1, 3, fp);
} void pixel_write4(int i, int j)
{
static unsigned char color[3];
color[0] = RD4 (i,j)&255;
color[1] = GR4 (i,j)&255;
color[2] = BL4 (i,j)&255;
fwrite (color, 1, 3, fp);
} int main ()
{
char t[256];
char printfHistory[2048]="正写入文件请稍等";
printf_s("printfHistory");
int num=0;
for(int a=1;a<6;a++)
{
sprintf_s(t,"MathPic%d.ppm",a);
fp = fopen (t,"wb");
fprintf (fp, "P6\n%d %d\n255\n", DIM, DIM);
for(int j=0;j<DIM;j++)
{
for(int i=0;i<DIM;i++)
{
switch (a)
{
case 1:
pixel_write(i,j);
case 2:
pixel_write1(i,j);
case 3:
pixel_write2(i,j);
case 4:
pixel_write3(i,j);
case 5:
pixel_write4(i,j);
default:
break;
}
}
}
printf_s("第 %d 张图片 写入成功!\n",a);
}
printf_s("所有图片已全部输出,请打开程序目录查看!");
fclose (fp);
return 0;
} void pixel_write (int i, int j)
{
static unsigned char color[3];
color[0] = RD (i,j)&255;
color[1] = GR (i,j)&255;
color[2] = BL (i,j)&255;
fwrite (color, 1, 3, fp);
}

  

最新文章

  1. hdu1402 FFT入门
  2. Codeforces Beta Round #3
  3. Apache Shiro权限框架在SpringMVC+Hibernate中的应用
  4. ~~圣诞节到啦, canvas雪花效果, 漂亮到简直没天理啊~~
  5. [Locked] Longest Substring with At Most Two Distinct Characters
  6. [Q]AdobePDF虚拟打印机自动保存PDF
  7. python 函数 装饰器 内置函数
  8. Machine Learning 思维导图
  9. [转]PHP开发者必须了解的工具—Composer
  10. go 调用windows dll 的三种方法
  11. 利用shell简单监控网络设备的接口状态发出告警
  12. Linux 设备树的解释 - DTB文件格式【转】
  13. 用nodejs做一下发送邮件例子
  14. JavaBean 和 pojo 的区别
  15. 【Go】Mac上安装Go
  16. [Oracle] Insert All的妙用
  17. 19、Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition
  18. 明确出需求 然后开会评审 要什么接口 接口参数、返回json内容、格式 协定好 在做
  19. AngryFuzz3r-web扫描工具
  20. 初识Quartz(一)

热门文章

  1. 《Linux就该这么学》课程完结,强烈推荐
  2. 树莓派初入门(1):SSH远程登录与VNC远程桌面
  3. postman常用功能汇总(基础必备)
  4. 09-cmake语法-add_dependencies()
  5. LCD12864
  6. ESP8266 LUA脚本语言开发: 准备工作-动手编译LUA固件
  7. 【BZOJ3569】DZY Loves Chinese II
  8. Vue中的v-bind指令
  9. OpenStack总体架构概览&amp;OpenStack核心组件介绍
  10. postgresql小计