-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrtree.c
75 lines (55 loc) · 1.71 KB
/
rtree.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
/* rtree --- plot randomised recursive tree 1996-12-16 */
/* Copyright (c) 1996 John Honniball, Froods Software Development */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "turtle.h"
/* Geometric parameters */
#define LEFT_ANGLE (27.0)
#define LEFT_SIZE (0.75)
#define RIGHT_ANGLE (22.0)
#define RIGHT_SIZE (0.70)
void tree(const int level, const double len);
double Left_angle;
double Right_angle;
double Left_size;
double Right_size;
int main(int argc, const char *argv[])
{
const int level = 8;
const double size = 65.0; /* 65mm trunk for A3 */
turtle(DEV_HPGL, SIZ_A3, ORI_LAND, FLG_BORD|FLG_RELS);
// title("http://www.dorkbot.org/dorkbotbristol/", 3.75, BOT|LEFT, FLG_NONE);
title("Bristol Hackspace", 3.75, BOT|LEFT, FLG_NONE);
title("2018-04-22", 3.75, BOT|RIGHT, FLG_NONE);
srand((unsigned int)time(NULL));
Left_angle = LEFT_ANGLE + (((double)rand() / (double)RAND_MAX) * 6.0);
Right_angle = RIGHT_ANGLE + (((double)rand() / (double)RAND_MAX) * 6.0);
Left_size = LEFT_SIZE + (((double)rand() / (double)RAND_MAX) * 0.05);
Right_size = RIGHT_SIZE + (((double)rand() / (double)RAND_MAX) * 0.05);
pen(UP);
turn(-90.0);
forward(1.9 * size);
turn(180.0);
pen(DOWN);
colour(BLACK);
tree(level, size);
show();
return (0);
}
/* tree --- recursive function to plot a tree */
void tree(const int level, const double len)
{
forward(len);
if (level == 0) {
turn(180.0);
}
else {
turn(Left_angle);
tree(level - 1, len * Left_size);
turn((180.0 - Left_angle) - Right_angle);
tree(level - 1, len * Right_size);
turn(Right_angle);
}
forward(len);
}