欢迎来到天天文库
浏览记录
ID:36013954
大小:59.00 KB
页数:6页
时间:2019-04-29
《计算机图形学 分形图的生成93692》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验六分形图的生成班级08信计二学号52姓名刘丽杰分数一、实验目的和要求:1、掌握分形基本原理,熟悉分形的计算机模拟算法。2、学习调试程序及分析运行结果。3、上机操作迭代函数系统算法。二、实验内容:1、编程实现分形的贝塞尔算法,并输出图形。2、编程实现一棵树,先按某一方向画一条直线段,然后在此线段上找到一系列节点,在每一节点处向左右偏转60度各画一条分支。节点位置和节点处所画分支的长度的比值各按0.618分割。三、程序执行和运行结果:1、贝塞尔程序:#include#include#
2、defineWIDTH640#defineHEIGHT480#defineNUMPTS6HDChdc;floatanimpts[NUMPTS*2];floatdeltas[NUMPTS*2];voidInit(){for(inti=0;i3、]=(float)rand()/RAND_MAX*4+2;if(animpts[i]>WIDTH/6.0f)deltas[i]=-deltas[i];if(animpts[i+1]>HEIGHT/6.0f)deltas[i+1]=-deltas[i+1];6}}voidAnimate(floatpts[],floatdeltas[],intindex,intlimit){floatnewpt=pts[index]+deltas[index];if(newpt<=0){newpt=-newpt;deltas[index]=(f4、loat)rand()/RAND_MAX*3+2;}elseif(newpt>=(float)limit){newpt=2.0f*limit-newpt;deltas[index]=-((float)rand()/RAND_MAX*3+2);}pts[index]=newpt;}voidRun(){inti;for(i=0;i5、mpts;intlen=NUMPTS*2;floatprevx=ctrlpts[len-2];floatprevy=ctrlpts[len-1];floatcurx=ctrlpts[0];6floatcury=ctrlpts[1];floatmidx=(curx+prevx)/2.0f;floatmidy=(cury+prevy)/2.0f;MoveToEx(hdc,(int)midx,(int)midy,NULL);for(i=2;i<=len;i+=2){floatx1=(midx+curx)/2.0f;floaty1=6、(midy+cury)/2.0f;prevx=curx;prevy=cury;if(i7、,(int)midx,(int)midy};PolyBezierTo(hdc,param,3);}}voidmain(){6initgraph(WIDTH,HEIGHT);hdc=GetImageHDC();Init();BeginBatchDraw();while(!kbhit()){cleardevice();Run();FlushBatchDraw();Sleep(15);}EndBatchDraw();getch();closegraph();}运行结果:2、程序:6#defineg0.618#definePAI3.8、1416#include”graphics.h”#include”math.h”#include”stdio.h”#include”conio.h”floatthita=6.0;voidgrow(intx,inty,floatlenth,floatfai){intx1,y1;intnx,n
3、]=(float)rand()/RAND_MAX*4+2;if(animpts[i]>WIDTH/6.0f)deltas[i]=-deltas[i];if(animpts[i+1]>HEIGHT/6.0f)deltas[i+1]=-deltas[i+1];6}}voidAnimate(floatpts[],floatdeltas[],intindex,intlimit){floatnewpt=pts[index]+deltas[index];if(newpt<=0){newpt=-newpt;deltas[index]=(f
4、loat)rand()/RAND_MAX*3+2;}elseif(newpt>=(float)limit){newpt=2.0f*limit-newpt;deltas[index]=-((float)rand()/RAND_MAX*3+2);}pts[index]=newpt;}voidRun(){inti;for(i=0;i5、mpts;intlen=NUMPTS*2;floatprevx=ctrlpts[len-2];floatprevy=ctrlpts[len-1];floatcurx=ctrlpts[0];6floatcury=ctrlpts[1];floatmidx=(curx+prevx)/2.0f;floatmidy=(cury+prevy)/2.0f;MoveToEx(hdc,(int)midx,(int)midy,NULL);for(i=2;i<=len;i+=2){floatx1=(midx+curx)/2.0f;floaty1=6、(midy+cury)/2.0f;prevx=curx;prevy=cury;if(i7、,(int)midx,(int)midy};PolyBezierTo(hdc,param,3);}}voidmain(){6initgraph(WIDTH,HEIGHT);hdc=GetImageHDC();Init();BeginBatchDraw();while(!kbhit()){cleardevice();Run();FlushBatchDraw();Sleep(15);}EndBatchDraw();getch();closegraph();}运行结果:2、程序:6#defineg0.618#definePAI3.8、1416#include”graphics.h”#include”math.h”#include”stdio.h”#include”conio.h”floatthita=6.0;voidgrow(intx,inty,floatlenth,floatfai){intx1,y1;intnx,n
5、mpts;intlen=NUMPTS*2;floatprevx=ctrlpts[len-2];floatprevy=ctrlpts[len-1];floatcurx=ctrlpts[0];6floatcury=ctrlpts[1];floatmidx=(curx+prevx)/2.0f;floatmidy=(cury+prevy)/2.0f;MoveToEx(hdc,(int)midx,(int)midy,NULL);for(i=2;i<=len;i+=2){floatx1=(midx+curx)/2.0f;floaty1=
6、(midy+cury)/2.0f;prevx=curx;prevy=cury;if(i7、,(int)midx,(int)midy};PolyBezierTo(hdc,param,3);}}voidmain(){6initgraph(WIDTH,HEIGHT);hdc=GetImageHDC();Init();BeginBatchDraw();while(!kbhit()){cleardevice();Run();FlushBatchDraw();Sleep(15);}EndBatchDraw();getch();closegraph();}运行结果:2、程序:6#defineg0.618#definePAI3.8、1416#include”graphics.h”#include”math.h”#include”stdio.h”#include”conio.h”floatthita=6.0;voidgrow(intx,inty,floatlenth,floatfai){intx1,y1;intnx,n
7、,(int)midx,(int)midy};PolyBezierTo(hdc,param,3);}}voidmain(){6initgraph(WIDTH,HEIGHT);hdc=GetImageHDC();Init();BeginBatchDraw();while(!kbhit()){cleardevice();Run();FlushBatchDraw();Sleep(15);}EndBatchDraw();getch();closegraph();}运行结果:2、程序:6#defineg0.618#definePAI3.
8、1416#include”graphics.h”#include”math.h”#include”stdio.h”#include”conio.h”floatthita=6.0;voidgrow(intx,inty,floatlenth,floatfai){intx1,y1;intnx,n
此文档下载收益归作者所有