-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhilb.c
111 lines (91 loc) · 2.09 KB
/
hilb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* hilb --- plot Hilbert curve 1996-12-16 */
/* Copyright (c) 1996 John Honniball, Froods Software Development */
#include <stdio.h>
#include "turtle.h"
#define A3
void hilb(const int level, const double len);
void bert(const int level, const double len);
int main(int argc, const char *argv[])
{
int level;
#ifdef A1
const double overall = 540.0; /* Overall size 540mm */
const int maxlevel = 6;
#else
const double overall = 270.0; /* Overall size 270mm */
const int maxlevel = 5;
#endif
double size;
double height;
double width;
#ifdef A1
turtle(DEV_HPGL, SIZ_A1, ORI_LAND, FLG_BORD);
#else
turtle(DEV_HPGL, SIZ_A3, ORI_LAND, FLG_BORD|FLG_RELS);
#endif
title("HILBERT", 3.75, BOT|LEFT, ITALIC);
// title("2013-03-23", 3.75, BOT|RIGHT, ITALIC);
height = page_height();
width = page_width();
size = overall / 2.0;
for (level = 1; level <= maxlevel; level++) {
bottom_left();
set_heading(0.0);
pen(UP);
forward((size / 2.0) + ((width - overall) / 2.0));
turn(90.0);
forward((size / 2.0) + ((height - overall) / 2.0));
turn(-90.0);
pen(DOWN);
switch (level % 4) {
case 0:
colour(BLACK);
break;
case 1:
colour(RED);
break;
case 2:
colour(GREEN);
break;
case 3:
colour(BLUE);
break;
}
hilb(level, size);
size /= 2.0;
}
show();
return (0);
}
void hilb(const int level, const double len)
{
if (level == 0)
return;
turn(90.0);
bert(level - 1, len);
forward(len);
turn(-90.0);
hilb(level - 1, len);
forward(len);
hilb(level - 1, len);
turn(-90.0);
forward(len);
bert(level - 1, len);
turn(90.0);
}
void bert(const int level, const double len)
{
if (level == 0)
return;
turn(-90.0);
hilb(level - 1, len);
forward(len);
turn(90.0);
bert(level - 1, len);
forward(len);
bert(level - 1, len);
turn(90.0);
forward(len);
hilb(level - 1, len);
turn(-90.0);
}