-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsystem.h
109 lines (96 loc) · 2.45 KB
/
lsystem.h
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
#ifndef LSYSTEM_H
#define LSYSTEM_H
#include <string>
#include <map>
#include <vector>
#include <stack>
#include "colour.h"
#include "window.h"
using namespace std;
enum phenotype {NOTHING, MOVE_FORWARD, DRAW_FORWARD, DRAW_CIRCLE, SAVE, RETURN, ROTATE};
/**
* Class for the phenotype of a symbol
*/
class Phenotype{
public:
/**
* Type of the phenotype
*/
phenotype ptype;
/**
* Additional option. Meaning varies according to the phenotype
*/
double option;
/**
* Colour option. Set to black when colour has no meaning for a phenotype
*/
Colour colour;
/**
* Default constructor
*/
Phenotype();
/**
* Parameteried constructor
* @param ptype Phenotype
* @param option [Optional] Length for MOVE_FORWARD and DRAW_FORWARD, radius for DRAW_CIRCLE and angle for ROTATE. Set to 0 for other phenotypes
* @param colour [Optional] Colour of the constituent pixels for DRAW_FORWARD and DRAW_CIRCLE. Set to black for other phenotypes
*/
Phenotype (phenotype ptype, double option = 0.0, Colour colour = Colour(0.0, 0.0, 0.0));
};
/**
* Class for a deterministic context-free Graphical L system
*/
class GraphicalLSystem{
public:
/**
* Axiom
*/
string axiom;
/**
* Production rules
*/
map <char, string> rules;
/**
* Generation number
*/
int n_generation;
/**
* Current genotype
*/
string current_genotype;
/**
* Phenotypes for symbols
*/
map < char, Phenotype > phenotypes;
/**
* Parameterized constructor
* @param axiom Axiom
* @param rules Production rules
*/
GraphicalLSystem (string axiom, map <char, string> rules);
/**
* Produces the genotype of the next generation
* @return Genotype of the next generation
*/
string GenerateNext();
/**
* Returns current genotype
* @return Current genotype
*/
string GetCurrentGenotype();
/**
* Adds phenotypes to symbols
* @param symbol The symbol
* @param ptype Phenotype
*/
void AddPhenotype(char symbol, Phenotype ptype);
/**
* Outputs the phenotype of the current genotype
* @param window_ptr Graphical window pointer
* @param x Initial X coordinate
* @param y Initial y coordinate
* @param angle Initial angle
*/
void Draw(Window* window_ptr, int x, int y, double angle);
};
#endif /* LSYSTEM_H */