-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranch.pde
More file actions
42 lines (38 loc) · 1.09 KB
/
Branch.pde
File metadata and controls
42 lines (38 loc) · 1.09 KB
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
// Branche définie comme une position + direction + parent (une autre branche) : permet de tracer les lignes
class Branch
{
// Attributs
PVector position;
PVector direction;
Branch parent;
float length = 5;
int count = 0; // Pour compter le nombre d'attirance vers les feuilles
PVector initialDirection; // Pour reset la branche
// Constructeur
Branch(PVector pos, PVector dir, Branch par)
{
position = pos;
direction = dir;
parent = par;
initialDirection = direction.copy();
}
// Autre constructeur : construit une branche à partir d'une branche précédente
Branch(Branch previousBranch)
{
position = previousBranch.nextPosition();
direction = previousBranch.direction.copy(); // Garde la même direction
parent = previousBranch;
initialDirection = direction.copy();
}
public PVector nextPosition()
{
PVector movement = PVector.mult(direction, length);
PVector nextPosition = PVector.add(position, movement);
return nextPosition;
}
public void reset()
{
count = 0;
direction = initialDirection.copy();
}
}