回答編集履歴
1
説明を追加
test
CHANGED
@@ -4,35 +4,41 @@
|
|
4
4
|
|
5
5
|
```processing
|
6
6
|
|
7
|
-
void mousePressed(){
|
7
|
+
void mousePressed() {
|
8
8
|
|
9
|
-
noStroke();
|
9
|
+
noStroke();
|
10
10
|
|
11
|
-
|
11
|
+
// マウス座標の 0~400 を 1~8 に変換
|
12
12
|
|
13
|
-
int
|
13
|
+
int x_pos = (int)map(mouseX, 0, 400, 1, 8);
|
14
14
|
|
15
|
-
int
|
15
|
+
int y_pos = (int)map(mouseY, 0, 400, 1, 8);
|
16
16
|
|
17
|
-
|
17
|
+
// 1マスのサイズを計算
|
18
18
|
|
19
|
-
int x
|
19
|
+
int x_size = 400 / 8;
|
20
20
|
|
21
|
-
int y
|
21
|
+
int y_size = 400 / 8;
|
22
22
|
|
23
|
-
|
23
|
+
// 配置位置を計算
|
24
24
|
|
25
|
-
|
25
|
+
int x = x_pos * x_size - x_size / 2;
|
26
26
|
|
27
|
-
|
27
|
+
int y = y_pos * y_size - y_size / 2;
|
28
28
|
|
29
|
-
|
29
|
+
if (mouseButton == LEFT) {
|
30
30
|
|
31
|
-
fill(
|
31
|
+
fill(255);
|
32
32
|
|
33
|
-
ellipse(x, y,35,35);
|
33
|
+
ellipse(x, y, 35, 35);
|
34
34
|
|
35
|
+
} else if (mouseButton == RIGHT) {
|
36
|
+
|
37
|
+
fill(0);
|
38
|
+
|
39
|
+
ellipse(x, y, 35, 35);
|
40
|
+
|
35
|
-
}
|
41
|
+
}
|
36
42
|
|
37
43
|
}
|
38
44
|
|