Hilbert Curve added
This commit is contained in:
parent
27b1618b6a
commit
2b1a2a1ddf
71
HilbertCurve.cpp
Normal file
71
HilbertCurve.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include<iostream>
|
||||
#include<graphics.h>
|
||||
#include<math.h>
|
||||
#include<cstdlib>
|
||||
#include<stdlib.h>
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user