回答編集履歴
3
追記2
test
CHANGED
@@ -48,8 +48,9 @@
|
|
48
48
|
import oscP5.*;
|
49
49
|
|
50
50
|
OscP5 osc;
|
51
|
-
String emotion;
|
51
|
+
ArrayList<String> emotion_list = new ArrayList<String>();
|
52
52
|
String scene = "start";
|
53
|
+
String tmp_scene;
|
53
54
|
|
54
55
|
void setup() {
|
55
56
|
size(1600, 900);
|
@@ -70,15 +71,18 @@
|
|
70
71
|
|
71
72
|
void oscEvent(OscMessage msg) {
|
72
73
|
if (msg.checkAddrPattern("/Emotion")) {
|
73
|
-
emotion = msg.get(0).stringValue();
|
74
|
+
String emotion = msg.get(0).stringValue();
|
74
75
|
println(emotion);
|
75
76
|
|
77
|
+
emotion_list.add(emotion);
|
78
|
+
if (10 == emotion_list.size()) {
|
76
|
-
emotion_branch();
|
79
|
+
emotion_branch(emotion);
|
77
|
-
|
80
|
+
osc.stop(); // oscを止める
|
81
|
+
}
|
78
82
|
}
|
79
83
|
}
|
80
84
|
|
81
|
-
void emotion_branch() {
|
85
|
+
void emotion_branch(String emotion) {
|
82
86
|
if (scene.equals("scene1")) {
|
83
87
|
switch(emotion) {
|
84
88
|
case "Happy":
|
@@ -87,10 +91,10 @@
|
|
87
91
|
case "Sad":
|
88
92
|
case "Angry":
|
89
93
|
case "Disgust":
|
90
|
-
scene = "sceneP2";
|
94
|
+
tmp_scene = "sceneP2";
|
91
95
|
break;
|
92
96
|
case "Fear":
|
93
|
-
scene = "sceneP1";
|
97
|
+
tmp_scene = "sceneP1";
|
94
98
|
break;
|
95
99
|
}
|
96
100
|
}
|
@@ -103,7 +107,11 @@
|
|
103
107
|
}
|
104
108
|
|
105
109
|
void keyPressed() {
|
106
|
-
if (scene.equals("scene
|
110
|
+
if (scene.equals("scene1")) {
|
111
|
+
if (key == ENTER && tmp_scene != null) {
|
112
|
+
scene = tmp_scene;
|
113
|
+
}
|
114
|
+
} else if (scene.equals("sceneP1")) {
|
107
115
|
if (key == ' ') {
|
108
116
|
sceneP1_text = sceneP1_next_text; // テキスト入れ替え
|
109
117
|
} else if (key == ENTER) {
|
@@ -258,7 +266,7 @@
|
|
258
266
|
"ごめん、ごめん。ちょっと冗談きつかったね。";
|
259
267
|
```
|
260
268
|
|
261
|
-
送信側(1
|
269
|
+
送信側(1秒ごとにランダムで`Emotion`を送信)
|
262
270
|
```Processing
|
263
271
|
import oscP5.*;
|
264
272
|
import netP5.*;
|
@@ -268,7 +276,7 @@
|
|
268
276
|
|
269
277
|
void setup() {
|
270
278
|
size(300, 200);
|
271
|
-
frameRate(
|
279
|
+
frameRate(1); // 1秒ごと
|
272
280
|
textAlign(CENTER, CENTER);
|
273
281
|
textSize(40);
|
274
282
|
|
2
追記(雑な送信側付き)
test
CHANGED
@@ -39,20 +39,20 @@
|
|
39
39
|
* Java
|
40
40
|
Pythonのほうがお得意ならPythonモードもございます。
|
41
41
|
|
42
|
-
|
42
|
+
---
|
43
|
+
|
44
|
+
### 追記(雑な送信側付き)
|
45
|
+
|
46
|
+
受信側
|
43
47
|
```Processing
|
44
|
-
import netP5.*;
|
45
48
|
import oscP5.*;
|
46
49
|
|
47
50
|
OscP5 osc;
|
48
51
|
String emotion;
|
49
52
|
String scene = "start";
|
50
|
-
ArrayList<String> emotion_list = new ArrayList<String>();
|
51
|
-
ArrayList<Float> max_v_list = new ArrayList<Float>();
|
52
|
-
|
53
53
|
|
54
54
|
void setup() {
|
55
|
-
size(1
|
55
|
+
size(1600, 900);
|
56
56
|
textFont(createFont("NSimSun-48", 40));
|
57
57
|
osc = new OscP5(this, 8000);
|
58
58
|
}
|
@@ -70,23 +70,16 @@
|
|
70
70
|
|
71
71
|
void oscEvent(OscMessage msg) {
|
72
72
|
if (msg.checkAddrPattern("/Emotion")) {
|
73
|
-
for (int x = 0; x < 11; x++) {
|
74
|
-
|
73
|
+
emotion = msg.get(0).stringValue();
|
75
|
-
emotion_list.add(emotion);
|
76
|
-
|
74
|
+
println(emotion);
|
77
|
-
|
78
|
-
|
75
|
+
|
79
|
-
max_v_list.add(max_v);
|
80
|
-
println(max_v);
|
81
|
-
}
|
82
|
-
|
83
|
-
emotion_branch();
|
76
|
+
emotion_branch();
|
77
|
+
//osc.stop(); // oscを止める
|
84
78
|
}
|
85
79
|
}
|
86
80
|
|
87
81
|
void emotion_branch() {
|
88
82
|
if (scene.equals("scene1")) {
|
89
|
-
String emotion = emotion_list.get(emotion_list.size() - 1);
|
90
83
|
switch(emotion) {
|
91
84
|
case "Happy":
|
92
85
|
case "Neutral":
|
@@ -132,52 +125,47 @@
|
|
132
125
|
|
133
126
|
void start_scene() {
|
134
127
|
fill(0);
|
128
|
+
textSize(40);
|
129
|
+
textAlign(CENTER, CENTER);
|
135
|
-
text("
|
130
|
+
text("right mouse click", 0, 0, width, height);
|
136
131
|
}
|
137
132
|
|
138
133
|
void scene_1() {
|
139
|
-
fill(255);
|
140
|
-
rect(150, 500, 2000, 900);
|
141
|
-
fill(0);
|
142
|
-
textAlign(LEFT, TOP);
|
143
|
-
text
|
134
|
+
draw_text(scene1_text);
|
144
|
-
textSize(45);
|
145
|
-
text(scene1_text, 150, 500, 2000, 900);
|
146
135
|
}
|
147
136
|
|
148
137
|
void Pattern1_scene() {
|
138
|
+
draw_text(sceneP1_text);
|
139
|
+
}
|
140
|
+
|
149
|
-
|
141
|
+
void Pattern2_scene() {
|
150
|
-
re
|
142
|
+
draw_text(sceneP2_text);
|
143
|
+
}
|
144
|
+
|
145
|
+
void scene2() {
|
146
|
+
draw_text(scene2_text);
|
147
|
+
}
|
148
|
+
|
149
|
+
void clear_scene() {
|
151
|
-
fill(0);
|
150
|
+
fill(0);
|
152
|
-
textAlign(LEFT, TOP);
|
153
|
-
textLeading(60);
|
154
151
|
textSize(40);
|
152
|
+
textAlign(CENTER, CENTER);
|
155
|
-
text(
|
153
|
+
text("end", 0, 0, width, height);
|
156
|
-
}
|
154
|
+
}
|
157
|
-
|
155
|
+
|
158
|
-
void
|
156
|
+
void draw_text(String text) {
|
159
|
-
fill(255);
|
157
|
+
//fill(255);
|
160
|
-
rect(150, 500, 2000, 900);
|
158
|
+
//rect(150, 500, 2000, 900);
|
159
|
+
//fill(0);
|
160
|
+
//textAlign(LEFT, TOP);
|
161
|
+
//textLeading(60);
|
162
|
+
//textSize(45);
|
163
|
+
//text(text, 150,500, 2000, 900);
|
164
|
+
|
161
|
-
fill(0);
|
165
|
+
fill(0);
|
162
|
-
textAlign(LEFT, T
|
166
|
+
textAlign(LEFT, CENTER);
|
163
|
-
textLeading(60);
|
164
|
-
textSize(40);
|
165
|
-
text(sceneP2_text, 150, 500, 2000, 900);
|
166
|
-
}
|
167
|
-
|
168
|
-
void scene2() {
|
169
|
-
fill(255);
|
170
|
-
rect(150, 500, 2000, 900);
|
171
|
-
fill(0);
|
172
|
-
textAlign(LEFT, TOP);
|
173
|
-
textLeading(60);
|
174
|
-
textSize(
|
167
|
+
textSize(35);
|
175
|
-
text(
|
168
|
+
text(text, 0, 0, width, height);
|
176
|
-
}
|
177
|
-
|
178
|
-
void clear_scene() {
|
179
|
-
fill(0);
|
180
|
-
text("aaaaaaaaaaaaaaaaaaaaaaaaa", width / 3, height / 2);
|
181
169
|
}
|
182
170
|
|
183
171
|
|
@@ -269,3 +257,41 @@
|
|
269
257
|
"一人じゃ出来ないから、口の堅いお友達を呼んで。証拠隠滅もお手伝いしてもらって・・・・。\n" +
|
270
258
|
"ごめん、ごめん。ちょっと冗談きつかったね。";
|
271
259
|
```
|
260
|
+
|
261
|
+
送信側(10秒ごとにランダムで`Emotion`を送信)
|
262
|
+
```Processing
|
263
|
+
import oscP5.*;
|
264
|
+
import netP5.*;
|
265
|
+
|
266
|
+
OscP5 oscP5;
|
267
|
+
NetAddress myRemoteLocation;
|
268
|
+
|
269
|
+
void setup() {
|
270
|
+
size(300, 200);
|
271
|
+
frameRate(0.1);
|
272
|
+
textAlign(CENTER, CENTER);
|
273
|
+
textSize(40);
|
274
|
+
|
275
|
+
oscP5 = new OscP5(this, 8000);
|
276
|
+
myRemoteLocation = new NetAddress("127.0.0.1", 8000);
|
277
|
+
}
|
278
|
+
|
279
|
+
void draw() {
|
280
|
+
background(255);
|
281
|
+
fill(0);
|
282
|
+
|
283
|
+
String[] emotions = { "Happy", "Neutral", "Surprise", "Sad", "Angry", "Disgust", "Fear" };
|
284
|
+
float v = random(emotions.length);
|
285
|
+
String emotion = emotions[int(v)];
|
286
|
+
text(emotion, 0, 0, width, height);
|
287
|
+
|
288
|
+
OscMessage msg = new OscMessage("/Emotion");
|
289
|
+
msg.add(emotion);
|
290
|
+
msg.add(v);
|
291
|
+
oscP5.send(msg, myRemoteLocation);
|
292
|
+
|
293
|
+
//exit(); // 終了
|
294
|
+
}
|
295
|
+
```
|
296
|
+
|
297
|
+
PDEを2つ開いて、受信側-送信側の順で実行する。
|
1
ちょんちょん
test
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
符号が逆のため1回も回っていません。
|
26
26
|
* `System.out.println`
|
27
27
|
`println`だけでいいです。
|
28
|
-
* if (scene == "start")
|
28
|
+
* `if (scene == "start")`
|
29
29
|
文字列の比較は`equals`を使用してください。
|
30
30
|
* `if(emotion_list.get(-1) == "Happy"){`
|
31
31
|
-1だとエラーになるはずですが...
|