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

HIBERT

This C program draws a Hilbert curve using recursive calls to the hilbert function. It takes user input for the value of n, which determines the level of recursion and complexity of the curve. The hilbert function recursively draws line segments and calls itself, changing the directions r, d, l, u at each level according to the Hilbert curve algorithm. It uses global x and y variables to keep track of the current position on the graph.

Uploaded by

Tanmay Bhosale
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)
33 views3 pages

HIBERT

This C program draws a Hilbert curve using recursive calls to the hilbert function. It takes user input for the value of n, which determines the level of recursion and complexity of the curve. The hilbert function recursively draws line segments and calls itself, changing the directions r, d, l, u at each level according to the Hilbert curve algorithm. It uses global x and y variables to keep track of the current position on the graph.

Uploaded by

Tanmay Bhosale
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

Practical No.

15

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
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);
delay(30);
}
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);
}
}
void main()
{
int n, x1,y1;
int x0=50, y0=150, x, y, h=10, r=2, d=3,l=4, u=1;
int gd=DETECT, gm; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");printf("Give the
value of n: "); scanf("%d",&n);
x=x0;y=y0;

moveto(x,y); hilbert(r,d,l,u,n,h,x,y);getch();
closegraph();

}
Output:-

You might also like