-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphics.pde
63 lines (47 loc) · 2.04 KB
/
Graphics.pde
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
void drawNetwork(Network net, int x, int y, int objWidth, int objHeight) {
fill(255, 255, 255);
stroke(2);
for(int i = 0; i < net.links.length; i++) {
if(net.links[i].in != 0) {
int startX = (int)(net.neurons[net.links[i].in].xPos * objWidth);
int startY = (int)(net.neurons[net.links[i].in].yPos * objHeight);
int endX = (int)(net.neurons[net.links[i].out].xPos * objWidth);
int endY = (int)(net.neurons[net.links[i].out].yPos * objHeight);
line(x + startX, y + startY, x + endX, y + endY);
}
}
noStroke();
for(int i = 0; i < net.neurons.length; i++) {
if(net.neurons[i] != null) {
int neuronX = (int)(net.neurons[i].xPos * objWidth);
int neuronY = (int)(net.neurons[i].yPos * objHeight);
fill(net.neurons[i].value * 255.0f, 0, 0);
ellipse(x + neuronX, y + neuronY, objWidth / 25, objWidth / 25);
}
}
}
void drawNetwork(Network net, int x, int y, int objWidth, int objHeight, color background) {
fill(background);
noStroke();
rect(x, y, objWidth, objHeight);
fill(255, 255, 255);
stroke(2);
for(int i = 0; i < net.links.length; i++) {
if(net.links[i].in != 0) {
int startX = (int)(net.neurons[net.links[i].in].xPos * objWidth);
int startY = (int)(net.neurons[net.links[i].in].yPos * objHeight);
int endX = (int)(net.neurons[net.links[i].out].xPos * objWidth);
int endY = (int)(net.neurons[net.links[i].out].yPos * objHeight);
line(x + startX, y + startY, x + endX, y + endY);
}
}
noStroke();
for(int i = 0; i < net.neurons.length; i++) {
if(net.neurons[i] != null) {
int neuronX = (int)(net.neurons[i].xPos * objWidth);
int neuronY = (int)(net.neurons[i].yPos * objHeight);
fill((int)constrain((net.neurons[i].value * -255.0f), 0, 255), (int)constrain((net.neurons[i].value * 255.0f), 0, 255), 0);
ellipse(x + neuronX, y + neuronY, objWidth / 25, objWidth / 25);
}
}
}