0% found this document useful (0 votes)
6 views3 pages

Program-: Title: - Roll No

Uploaded by

xcallibersam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Program-: Title: - Roll No

Uploaded by

xcallibersam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

/*

Title: - Write C++ program to generate Hilbert curve using concept of fractals.
Roll No:-

Class:-SE Computer

Sub:-OOPL & CGL

Date:-
****************************************************************************/
Program-
#include<iostream>
#include<graphics.h>
#include<math.h>
#include<cstdlib>
using namespace std;
void move(int j, int h, int &x,int &y)
{
if(j==1)
y-=h;
else
if(j==2)
x+=h;
else if(j==3)
y+=h;
else if(j==4)
x-=h;
lineto(x,y);
}
void hilbert(int r,int d,int l ,int u,int i,int h,int &x,int &y)
{
if(i>0)
{
i--;
hilbert(d,r,u,l,i,h,x,y);
move(r,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(d,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(l,h,x,y);
hilbert(u,l,d,r,i,h,x,y);
}
}
int main()
{
int n,x1,y1;
int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
cout<<"Give the value of n=";
cin>>n;
x=x0;
y=y0;
int driver=DETECT,mode=0;
initgraph(&driver,&mode,NULL);
moveto(x,y);
hilbert(r,d,l,u,n,h,x,y);
delay(10000);
closegraph();
return 0;
}

/*Output:-

You might also like