Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Parth1906
GitHub Repository: Parth1906/SPPU-2019-Pattern-SE-COMP-Computer-Graphics-Practicals
Path: blob/main/9. Hilbert Curve (Fractals).cpp
724 views
1
#include <iostream>
2
#include <stdlib.h>
3
#include <graphics.h>
4
#include <math.h>
5
6
using namespace std;
7
8
void move(int j,int h,int &x,int &y)
9
{
10
if(j==1)
11
y-=h;
12
else if(j==2)
13
x+=h;
14
else if(j==3)
15
y+=h;
16
else if(j==4)
17
x-=h;
18
lineto(x,y);
19
}
20
21
void hilbert(int r,int d,int l,int u,int i,int h,int &x,int &y)
22
{
23
if(i>0)
24
{
25
i--;
26
hilbert(d,r,u,l,i,h,x,y);
27
move(r,h,x,y);
28
hilbert(r,d,l,u,i,h,x,y);
29
move(d,h,x,y);
30
hilbert(r,d,l,u,i,h,x,y);
31
move(l,h,x,y);
32
hilbert(u,l,d,r,i,h,x,y);
33
}
34
}
35
36
int main()
37
{
38
int n,x1,y1;
39
int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
40
41
cout<<"\nGive the value of n: ";
42
cin>>n;
43
x=x0;y=y0;
44
int gm,gd=DETECT;
45
initgraph(&gd,&gm,NULL);
46
moveto(x,y);
47
hilbert(r,d,l,u,n,h,x,y);
48
delay(10000);
49
50
closegraph();
51
52
return 0;
53
}
54
55