From 2b1a2a1ddf3cd85964fcbd74a615c8a39a137730 Mon Sep 17 00:00:00 2001 From: TanmaySpamzzz Date: Thu, 2 Nov 2023 11:47:33 +0530 Subject: [PATCH] Hilbert Curve added --- HilbertCurve.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 HilbertCurve.cpp diff --git a/HilbertCurve.cpp b/HilbertCurve.cpp new file mode 100644 index 0000000..af948e5 --- /dev/null +++ b/HilbertCurve.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +using namespace std; + +void move(int j, int h, int &x, int &y) +{ + if(j == 1) + { + y = y - h; + } + else if(j == 2) + { + x = x + h; + } + else if(j == 3) + { + y = y + h; + } + else if(j == 4) + { + x = x - h; + } + setcolor(BROWN); + lineto(x,y); +} + +void hilbert(int d, int r, int u, int l, int i, int h, int &x, int &y) +{ + if(i > 0) + { + i--; + hilbert(r,d,l,u,i,h,x,y); + move(d,h,x,y); + hilbert(d,r,u,l,i,h,x,y); + move(r,h,x,y); + hilbert(d,r,u,l,i,h,x,y); + move(u,h,x,y); + hilbert(l,u,r,d,i,h,x,y); + } +} + +int main() +{ + int gd = DETECT,gm; + initgraph(&gd,&gm,NULL); + int x,y,h,n,u = 1,r = 2,d = 3,l = 4; + cout<<"Enter x-co-ordinate of initial point: "; + cin>>x; + + cout<<"Enter y-co-ordinate of initial point: "; + cin>>y; + + cout<<"Enter length of line segment: "; + cin>>h; + + cout<<"Enter order of curve: "; + cin>>n; + + moveto(x,y); + //1. d,r,u; + //hilbert(d,r,u,l,n,h,x,y); + + //2. r,d,l; + hilbert(r,d,l,u,n,h,x,y); + getch(); + closegraph(); + return 0; +}