-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·71 lines (53 loc) · 1.42 KB
/
main.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
#include <stdlib.h>
#include <cairo.h>
#include <cairo-svg.h>
#include <cairo-pdf.h>
#define SIZE_H 640
#define SIZE_V 360
void dragon_draw(int, int, int, int);
void dragon_r(cairo_t * cr, int depth, short *x,short *y);
void dragon_l(cairo_t * cr, int depth, short *x,short *y);
void dragon_l(cairo_t * cr, int depth, short *x,short *y)
{
if (depth != 0)
dragon_l(cr, depth-1, x, y);
short t = *x; *x = *y; *y = -t;
cairo_rel_line_to(cr, *x, *y);
if (depth != 0)
dragon_r(cr, depth - 1, x, y);
}
void dragon_r(cairo_t * cr, int depth, short *x,short *y)
{
if (depth != 0)
dragon_l(cr, depth-1, x, y);
short t = *x; *x = -*y; *y = t;
cairo_rel_line_to(cr, *x, *y);
if (depth != 0)
dragon_r(cr, depth -1, x, y);
}
int main(int argc, char **argv)
{
int h_size = SIZE_H;
int v_size = SIZE_V;
int line_len = 3;
int n = 2;
n = atoi(argv[1]);
dragon_draw(h_size, v_size, line_len, n);
return 0;
}
void dragon_draw(int h_size, int v_size, int line_len, int depth)
{
cairo_surface_t *surface;
surface = cairo_svg_surface_create("dragon.svg", h_size, v_size);
cairo_t * cr;
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_set_line_width(cr, 0.5);
cairo_move_to(cr, h_size/2, v_size/2);
short x = -line_len, y = 0;
cairo_rel_line_to(cr, x, y);
dragon_l(cr, depth, &x, &y);
cairo_stroke(cr);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}