-
Notifications
You must be signed in to change notification settings - Fork 7
/
Cell.pde
151 lines (132 loc) · 3.64 KB
/
Cell.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
public abstract class Cell extends ControllableShape {
protected ArrayList<Path> fAxons;
protected ArrayList<Path> fDendrites;
protected int fTotalTime, fLastFired, fNumFired;
protected float fAvgFiringRate, fCurrentFiringRate;
public Cell(float x, float y, float size, color cc) {
super(x, y, size, cc);
fAxons = new ArrayList<Path>();
fDendrites = new ArrayList<Path>();
fLastFired = 0;
fNumFired = 0;
fAvgFiringRate = 0;
fCurrentFiringRate = 0;
}
protected void fire() {
if (fireSignals()) {
int current = millis();
fNumFired++;
if (fNumFired > 1) {
float interval = (current - fLastFired)/1000.0;
fCurrentFiringRate = 1.0/interval;
fTotalTime += interval;
fAvgFiringRate = 1/(float(fTotalTime)/fNumFired);
// println(fCurrentFiringRate + " " + fAvgFiringRate);
}
fLastFired = current;
}
}
public float getAvgFiringRate() {
return fAvgFiringRate;
}
public float getCurrentFiringRate() {
return fCurrentFiringRate;
}
protected abstract boolean fireSignals();
public void addPath(Path p) {
if (p.getType() ==DENDRITE)
fDendrites.add(p);
else if (p.getType() == AXON)
fAxons.add(p);
}
public ArrayList<Path> getAxons() {
return fAxons;
}
public ArrayList<Path> getDendrites() {
return fDendrites;
}
public abstract void copyAttributes(Cell c);
public boolean isInBounds(float x, float y) {
return PVector.dist(fLoc, new PVector(x, y)) <= fSize;
}
public void flipColor() {
super.flipColor();
for (Path p : fAxons)
p.flipColor();
for (Path p : fDendrites)
p.flipColor();
}
public boolean onDblClick(float x, float y) {
if (isInBounds(x, y)) {
flipColor();
return true;
}
return false;
}
public boolean onMouseDown(float x, float y) {
for (Control c : fControls) {
if (c.fVisible && c.onMouseDown(x, y)) {
return (fSelected = true);
}
}
// for (Path p : fAxons)
// if (p.onMouseDown(x, y))
// return true;
// for (Path p : fDendrites)
// if (p.onMouseDown(x, y))
// return true;
return super.onMouseDown(x, y);
}
public void translate(PVector change) {
if (fMovable) {
for (Path dendrite : fAxons)
dendrite.translate(change);
for (Control c : fControls)
c.translate(change);
super.translate(change);
}
}
public boolean onMouseDragged(float x, float y) {
if (fSelected) {
for (Control c : fControls) {
if (c.fVisible && c.onMouseDragged(x, y))
return true;
}
translate(new PVector(x - fLoc.x, y - fLoc.y));
return true;
}
// for (Path p : fAxons)
// if (p.onMouseDragged(x, y))
// return true;
// for (Path p : fDendrites)
// if (p.onMouseDragged(x, y))
// return true;
return super.onMouseDragged(x, y);
}
public boolean onMouseMoved(float x, float y) {
for (Control c : fControls) {
if (c.fVisible && c.onMouseMoved(x, y))
return true;
}
// for (Path p : fAxons)
// if (p.onMouseMoved(x, y))
// return true;
// for (Path p : fDendrites)
// if (p.onMouseMoved(x, y))
// return true;
return super.onMouseMoved(x, y);
}
public boolean onMouseUp(float x, float y) {
for (Control c : fControls) {
if (c.fVisible && c.onMouseUp(x, y))
return true;
}
// for (Path p : fAxons)
// if (p.onMouseUp(x, y))
// return true;
// for (Path p : fDendrites)
// if (p.onMouseUp(x, y))
// return true;
return super.onMouseUp(x, y);
}
}