forked from yangsu/Synaptic-Wall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControllerSynapse.pde
171 lines (152 loc) · 4.21 KB
/
ControllerSynapse.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
public class ControllerSynapse extends Synapse {
private CircularSlider fRateSlider, fTimeSlider, fNormSlider;
private DoubleEndedSlider fSignalRangeSlider;
private float fRate, fTime, fNorm, fRangeMin, fRangeMax;
private final int RATE = 0;
private final int TIME = 1;
private final int NORM = 2;
private final int RANGE = 3;
public ControllerSynapse(float x, float y) {
this(null, x, y, EX_HIGHLIGHT_COLOR);
}
public ControllerSynapse(Path axon, float x, float y, color cc) {
this(axon, x, y, cc, SYNAPSE_STRENGTH);
}
public ControllerSynapse(Path axon, float x, float y, color cc, float strength) {
super(axon, x, y, cc, strength);
fRate = 0;
fTime = 0;
fNorm = 0;
fRangeMin = fRangeMax = 0.5;
initControls();
}
private void initControls() {
float controlSize = fSize + 3 * SLIDER_BAR_WIDTH;
fNormSlider = new CircularSlider(
fLoc.x, fLoc.y, controlSize,
0, TWO_PI/3,
fNorm, 0, 1.0,
NORM, this
);
fControls.add(fNormSlider);
fTimeSlider = new DiscreteCircularSlider(
fLoc.x, fLoc.y, controlSize,
TWO_PI/3, 2 * TWO_PI/3,
fTime, 0, 1,
TIME, this
);
fControls.add(fTimeSlider);
fRateSlider = new DiscreteCircularSlider(
fLoc.x, fLoc.y, controlSize,
2 * TWO_PI/3, TWO_PI,
fRate, 0, 1,
RATE, this
);
fControls.add(fRateSlider);
fSignalRangeSlider = new DoubleEndedSlider(
fLoc.x, fLoc.y,
fSize + SLIDER_BAR_WIDTH*1.25, SLIDER_BAR_WIDTH*0.75,
PI, TWO_PI,
fRangeMin, fRangeMax, 0, 1,
RANGE, this
);
fControls.add(fSignalRangeSlider);
showControls();
}
private void drawLabels() {
pushStyle();
strokeWeight(CP_BORDER_WIDTH);
rectMode(CORNER);
stroke(CP_TEXT_COLOR);
float r = fSize + 3 * SLIDER_BAR_WIDTH + CP_TEXT_OFFSET;
float r2 = fSize + 4 * SLIDER_BAR_WIDTH;
float textsize = 9;
float v = fNormSlider.getValue();
float t = fNormSlider.getSliderPosition();
String s ="I-Norm";
float w = textWidth(s);
float x = fLoc.x + cos(t)*r;
float y = fLoc.y + sin(t)*(r + textsize);
noFill();
rect(x, y, w + 2 * CP_PADDING, textsize + 2 * CP_PADDING);
float x2 = fLoc.x + cos(t)*r2;
float y2 = fLoc.y + sin(t)*r2;
line(x, y, x2, y2);
fill(CP_TEXT_COLOR);
x2 = x + CP_PADDING;
y2 = y + CP_PADDING + textsize;
text(s, x2, y2);
v = fRateSlider.getValue();
t = fRateSlider.getSliderPosition();
s = "I-Rate";
w = textWidth(s);
x = fLoc.x + cos(t)*r;
y = fLoc.y + sin(t)*(r + textsize);
noFill();
rect(x, y, w + 2 * CP_PADDING, textsize + 2 * CP_PADDING);
x2 = fLoc.x + cos(t)*r2;
y2 = fLoc.y + sin(t)*r2;
line(x, y, x2, y2);
fill(CP_TEXT_COLOR);
x2 = x + CP_PADDING;
y2 = y + CP_PADDING + textsize;
text(s, x2, y2);
v = fTimeSlider.getValue();
t = fTimeSlider.getSliderPosition();
s = "I-Time";
w = textWidth(s);
x = fLoc.x + cos(t)*r - w;
y = fLoc.y + sin(t)*(r + textsize);
noFill();
rect(x, y, w + 2 * CP_PADDING, textsize + 2 * CP_PADDING);
x2 = fLoc.x + cos(t)*r2;
y2 = fLoc.y + sin(t)*r2;
line(x, y, x2, y2);
fill(CP_TEXT_COLOR);
x2 = x + CP_PADDING;
y2 = y + CP_PADDING + textsize;
text(s, x2, y2);
popStyle();
}
private void drawCenterPiece() {
pushStyle();
// Center
fill(EX_COLOR);
float s = PATH_JUNCTION_WIDTH;
ellipse(fLoc.x, fLoc.y, s, s);
// Stem
strokeWeight(s);
stroke(EX_COLOR);
line(fLoc.x, fLoc.y, fLoc.x, fLoc.y - fSize);
popStyle();
}
public void drawBackground() {
drawCenterPiece();
super.drawBackground();
}
public void drawForeground() {
super.drawForeground();
drawControls();
drawLabels();
}
public void onEvent(int controlID, float value) {
switch (controlID) {
case RATE:
fRate = value;
break;
case TIME:
fTime = value;
break;
case NORM:
fNorm = value;
break;
case RANGE:
fRangeMin = fSignalRangeSlider.getValue();
fRangeMax = fSignalRangeSlider.getValue2();
println("min " + fRangeMin + " max " + fRangeMax);
break;
default:
break;
}
}
}