鱼C论坛

 找回密码
 立即注册
查看: 5489|回复: 16

分形模拟--树叶 有错误高手指正

 关闭 [复制链接]
发表于 2011-5-27 22:00:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 moshushi 于 2011-5-31 19:06 编辑

一个一个敲上来的代码,累死人了,却不能运行:@ ,高手来看看:

#include <graphics.h>
#include <stdio.h>
#include <stdarg.h>
#include <conio.h>
#define PI 3.14159


int X_maxd,Y_maxd,foregrcolor,backgrcolor,colorsum;
float x_maxs=10.0,y_maxs=7.0,borfact,vertfact;
float fx,fy,xc,yc,xmin0=100,xmax0=-100,ymin0=100,ymax=-100,xc0,yc0,
a,b,c,d,x0,x,y;


int count=0,recdepth,level_5;


void initgr()
{

int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"f:\\tc");
foregrcolor=getcolor();
backgrcolor=getbkcolor();
colorsum=foregrcolor+(backgrcolor<<4);
X_maxd=getmaxx();
Y_maxd=getmaxy();
horfact=X_maxd/x_maxs;
wertfact=Y_maxd/y_masx;

}

   int 1x(float x)
   {return((int)(x*horfact+0.5));
   }
   int 1y(float y)
   {return((int)(Y_maxd)-(int)(y*vertfact+0.5));}
   float xreal(float x)
   {return(xc+f*(x-xc0));}
   float yreal(float y)
   {return(yc+f*(y-yc0));}


   void transf(float x,float y,int n,int prescan)
   {/*用递归生成树叶上的点*/
   float x1,y1;
   if(n>0)
   {
   if(preascan)
   {
   if(x<xmin0)
   xmin0=0;
   if(x>xmax0)
   xmax0=0;
   if(y<ymin0)
   ymin0=y;
   if(y>ymax0)
   ymax0=y;

   }
   else
   {
   if(n==level_5)
   putpixel(count+=8,0,foregrcolor);
   putpixel(1x(xreal(x)),1y(yreal(y)),foregrcolor);


   }
   x1=a*x+b*y;
   y1=b*x-a*y;
   transf(x1,y1,n-1,prescan);

   }

   }

   main()
   {
   int i;
   recdepth=14;
   level_5=recdepth-5;
   a=0.7;b=0.3;c=0.5;  d=0.2;x0=2;
   transf(1.0,0.0,recdepth,1);
   initgr();
   setviewport(15,15,625,465,1);
   foregrcolor=2;
   setfillstyle(SOLID_FILL,DARKGRAY);
   floodfill(16,16,DARKGRAY);
   fx=x_maxs/(xmax0-xmin0);
   fy=y_maxs/(ymax0-ymin0);
   f=(fx<fy?fx:fy)*0.8;
   xc0=(xmin0+xmax0)/2;
   yc0=(ymin0+ymax0);
   xc=x_maxs/2;
   yc=y_maxs/2;
   count=0;
   transf(1.0,0.0,recdepth,0);
   for(i=1;i<=32;i++)
   putpixel(8*i,0,backgrcolor);
   getch();

   closegraph();


   }
希望能顺利运行

点评

哥们下次记得用代码模式~  发表于 2011-5-28 05:22

评分

参与人数 1鱼币 -1 收起 理由
soldier -1 请适应代码格式,

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-28 04:17:22 | 显示全部楼层
这个是TC 的程序吧~

#include <graphics.h>这个头文件是 TC 编译器的产物。

VC++ 没有这玩意哦~
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-28 20:11:54 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-28 23:11:20 | 显示全部楼层
moshushi 发表于 2011-5-28 20:11
用win-tc编译也不行的

报了什么错误呢?麻烦朋友把错误提示提供一下
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 17:24:24 | 显示全部楼层
小甲鱼 发表于 2011-5-28 23:11
报了什么错误呢?麻烦朋友把错误提示提供一下

错误 shuye.c 27: 未定义的符号'horfact'在 initgr 函数中

错误 shuye.c 28: 未定义的符号'wertfact'在 initgr 函数中

错误 shuye.c 28: 未定义的符号'y_masx'在 initgr 函数中

错误 shuye.c 32: 说明语法错误

***  编译出现 4 个错误  ***
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-29 17:58:22 | 显示全部楼层
  1. #include <graphics.h>
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <conio.h>
  5. #define PI 3.14159


  6. int X_maxd,Y_maxd,foregrcolor,backgrcolor,colorsum;
  7. float x_maxs=10.0,y_maxs=7.0,borfact,vertfact;
  8. float fx,fy,xc,yc,xmin0=100,xmax0=-100,ymin0=100,ymax=-100,xc0,yc0,
  9. a,b,c,d,x0,x,y;


  10. int count=0,recdepth,level_5;


  11. void initgr()
  12. {
  13.       
  14.       int gdriver=DETECT,gmode;
  15.       initgraph(&gdriver,&gmode,"f:\\tc");
  16.       foregrcolor=getcolor();
  17.       backgrcolor=getbkcolor();
  18.       colorsum=foregrcolor+(backgrcolor<<4);
  19.       X_maxd=getmaxx();
  20.       Y_maxd=getmaxy();
  21.       borfact=X_maxd/x_maxs;
  22.       vertfact=Y_maxd/y_maxs;
  23.       
  24. }

  25. int 1x(float x)
  26. {return((int)(x*horfact+0.5));
  27. }
  28. int 1y(float y)
  29. {return((int)(Y_maxd)-(int)(y*vertfact+0.5));}
  30. float xreal(float x)
  31. {return(xc+f*(x-xc0));}
  32. float yreal(float y)
  33. {return(yc+f*(y-yc0));}


  34. void transf(float x,float y,int n,int prescan)
  35. {/*用递归生成树叶上的点*/
  36.       float x1,y1;
  37.       if(n>0)
  38.       {
  39.             if(preascan)
  40.             {
  41.                   if(x<xmin0)
  42.                         xmin0=0;
  43.                   if(x>xmax0)
  44.                         xmax0=0;
  45.                   if(y<ymin0)
  46.                         ymin0=y;
  47.                   if(y>ymax0)
  48.                         ymax0=y;
  49.                   
  50.             }
  51.             else
  52.             {
  53.                   if(n==level_5)
  54.                         putpixel(count+=8,0,foregrcolor);
  55.                   putpixel(1x(xreal(x)),1y(yreal(y)),foregrcolor);
  56.                   
  57.                   
  58.             }
  59.             x1=a*x+b*y;
  60.             y1=b*x-a*y;
  61.             transf(x1,y1,n-1,prescan);
  62.             
  63.       }
  64.       
  65. }

  66. main()
  67. {
  68.       int i;
  69.       recdepth=14;
  70.       level_5=recdepth-5;
  71.       a=0.7;b=0.3;c=0.5;  d=0.2;x0=2;
  72.       transf(1.0,0.0,recdepth,1);
  73.       initgr();
  74.       setviewport(15,15,625,465,1);
  75.       foregrcolor=2;
  76.       setfillstyle(SOLID_FILL,DARKGRAY);
  77.       floodfill(16,16,DARKGRAY);
  78.       fx=x_maxs/(xmax0-xmin0);
  79.       fy=y_maxs/(ymax0-ymin0);
  80.       f=(fx<fy?fx:fy)*0.8;
  81.       xc0=(xmin0+xmax0)/2;
  82.       yc0=(ymin0+ymax0);
  83.       xc=x_maxs/2;
  84.       yc=y_maxs/2;
  85.       count=0;
  86.       transf(1.0,0.0,recdepth,0);
  87.       for(i=1;i<=32;i++)
  88.             putpixel(8*i,0,backgrcolor);
  89.       getch();
  90.       
  91.       closegraph();
  92.       
  93.       
  94. }
复制代码
请朋友以后提问务必注意下代码的格式,这样看实在很头疼……
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 18:01:08 | 显示全部楼层
:$:lol好的
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 18:02:43 | 显示全部楼层
小甲鱼 发表于 2011-5-29 17:58
请朋友以后提问务必注意下代码的格式,这样看实在很头疼……

错误 shuye2.c 32: 说明语法错误

还是报错了 哈
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-29 18:13:50 | 显示全部楼层
  1. int 1x(float x)
  2. {
  3.         return((int)(x*horfact+0.5));
  4. }
  5. 改为
  6. int 1x(float x)
  7. {
  8.         return((int)(x*borfact+0.5));
  9. }
  10. 试试
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 19:45:10 | 显示全部楼层
不行啊,还是那个错误
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 19:45:50 | 显示全部楼层

还是那个错误
小甲鱼最新课程 -> https://ilovefishc.com
头像被屏蔽
发表于 2011-5-29 20:46:29 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-29 21:19:29 | 显示全部楼层
代码了?在哪里
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-29 23:57:03 | 显示全部楼层
  1. #include <graphics.h>
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <conio.h>

  5. #define PI 3.14159265

  6. int X_maxd,Y_maxd,foregrcolor,backgrcolor,colorsum;
  7. float x_maxs=10.0,y_maxs=7.0,horfact,vertfact;
  8. float fx,fy,f,xc,yc,xmin0=100,xmax0=-100,ymin0=100,ymax0=-100,xc0,yc0,a,b,c,d,x0,x,y;
  9. int count=0,recdepth,level_5;

  10. void initgr()
  11. {
  12.       int gdriver=DETECT,gmode;

  13.       initgraph(&gdriver,&gmode,"d:\\turboc2");

  14.       foregrcolor=getcolor();
  15.       backgrcolor=getbkcolor();

  16.       colorsum=foregrcolor+(backgrcolor<<4);

  17.       X_maxd=getmaxx();
  18.       Y_maxd=getmaxy();

  19.       horfact=X_maxd/x_maxs;
  20.       vertfact=Y_maxd/y_maxs;
  21. }

  22. int lx(float x)
  23. {
  24.       return ((int)(x*horfact+0.5));
  25. }

  26. int ly(float y)
  27. {
  28.       return ((int)(Y_maxd)-(int)(y*vertfact+0.5));
  29. }

  30. float xreal(float x)
  31. {
  32.       return (xc+f*(x-xc0));
  33. }

  34. float yreal(float y)
  35. {
  36.       return (yc+f*(y-yc0));
  37. }

  38. void transf(float x,float y,int n,int prescan)
  39. {
  40.       float x1,y1;

  41.       if(n>0)
  42.       {
  43.             if(prescan)
  44.             {
  45.                   if(x<xmin0)
  46.                         xmin0=x;
  47.                   if(x>xmax0)
  48.                         xmax0=x;
  49.                   if(y<ymin0)
  50.                         ymin0=y;
  51.                   if(y>ymax0)
  52.                         ymax0=y;
  53.             }
  54.             else
  55.             {
  56.                   if(n==level_5)
  57.                         putpixel(count+=8,0,foregrcolor);

  58.                   putpixel(lx(xreal(x)),ly(yreal(y)),foregrcolor);
  59.             }
  60.             x1=a*x+b*y;
  61.             y1=b*x-a*y;

  62.             transf(x1,y1,n-1,prescan);

  63.             x1=c*(x-x0)-d*y+x0;
  64.             y1=d*(x-x0)+c*y;

  65.             transf(x1,y1,n-1,prescan);
  66.       }
  67. }

  68. main()
  69. {
  70.       int i;

  71.       recdepth=14;
  72.       level_5=recdepth-5;
  73.       a=0.7;
  74.       b=0.3;
  75.       c=0.5;
  76.       d=0.2;
  77.       x0=2;

  78.       transf(1.0,0.0,recdepth,1);
  79.       initgr();
  80.       setviewport(15,15,625,465,1);

  81.       foregrcolor=2;

  82.       setfillstyle(SOLID_FILL,DARKGRAY);
  83.       floodfill(16,16,DARKGRAY);

  84.       fx=x_maxs/(xmax0-xmin0);
  85.       fy=y_maxs/(ymax0-ymin0);

  86.       f=(fx<fy?fx:fy)*0.8;
  87.       xc0=(xmin0+xmax0)/2;
  88.       yc0=(ymin0+ymax0)/2;
  89.       xc=x_maxs/2;
  90.       yc=y_maxs/2;

  91.       count=0;
  92.       transf(1.0,0.0,recdepth,0);

  93.       for(i=1;i<32;i++)
  94.             putpixel(8*i,0,backgrcolor);

  95.       getch();

  96.       closegraph();
  97. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-30 19:31:33 | 显示全部楼层

终于成功编译。高手啊 ,佩服,真是我的崇拜偶像:victory:
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-5-30 22:40:27 | 显示全部楼层
moshushi 发表于 2011-5-30 19:31
终于成功编译。高手啊 ,佩服,真是我的崇拜偶像

问题解决后麻烦把分类改为【已解决】哦~
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-5-31 19:05:25 | 显示全部楼层
本帖最后由 moshushi 于 2011-5-31 19:06 编辑

哈 嗯 嗯 我知道了
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-6 10:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表