回答編集履歴
3
pushMatrix()/popMatrix()を除去
test
CHANGED
@@ -60,8 +60,6 @@
|
|
60
60
|
|
61
61
|
// 三角形の描画に関する処理
|
62
62
|
|
63
|
-
pushMatrix();
|
64
|
-
|
65
63
|
translate(x+500, y+500);
|
66
64
|
|
67
65
|
float x1 = sin(radians(120)); // 0.866;
|
@@ -88,8 +86,6 @@
|
|
88
86
|
|
89
87
|
triangle(x1, y1, x2, y2, x3, y3);
|
90
88
|
|
91
|
-
popMatrix();
|
92
|
-
|
93
89
|
}
|
94
90
|
|
95
91
|
```
|
2
三角形の座標をマジックナンバーではなくsin/cosで表すよう変更
test
CHANGED
@@ -20,8 +20,6 @@
|
|
20
20
|
|
21
21
|
float SCALE = 10;
|
22
22
|
|
23
|
-
|
24
|
-
|
25
23
|
void setup(){
|
26
24
|
|
27
25
|
size(1000,1000);
|
@@ -40,6 +38,8 @@
|
|
40
38
|
|
41
39
|
void draw() {
|
42
40
|
|
41
|
+
// 円周の位置を計算(10度単位)
|
42
|
+
|
43
43
|
t += PI * 10 / 180;
|
44
44
|
|
45
45
|
float x = r * sin(t);
|
@@ -47,6 +47,8 @@
|
|
47
47
|
float y = r * cos(t);
|
48
48
|
|
49
49
|
|
50
|
+
|
51
|
+
// 三角形の線の太さと色を指定
|
50
52
|
|
51
53
|
strokeWeight(0.1);
|
52
54
|
|
@@ -56,25 +58,33 @@
|
|
56
58
|
|
57
59
|
|
58
60
|
|
61
|
+
// 三角形の描画に関する処理
|
62
|
+
|
59
63
|
pushMatrix();
|
60
64
|
|
61
65
|
translate(x+500, y+500);
|
62
66
|
|
63
|
-
float x1 =
|
67
|
+
float x1 = sin(radians(120)); // 0.866;
|
64
68
|
|
65
|
-
float y1 = -0.5;
|
69
|
+
float y1 = cos(radians(120)); // -0.5;
|
66
70
|
|
67
|
-
float x2 = 0.866;
|
71
|
+
float x2 = sin(radians(240)); // -0.866;
|
68
72
|
|
69
|
-
float y2 = -0.5;
|
73
|
+
float y2 = cos(radians(240)); // -0.5;
|
70
74
|
|
71
|
-
float x3 = 0.0;
|
75
|
+
float x3 = sin(radians(360)); // 0.0;
|
72
76
|
|
73
|
-
float y3 = 1.0;
|
77
|
+
float y3 = cos(radians(360)); // 1.0;
|
78
|
+
|
79
|
+
// 回転
|
74
80
|
|
75
81
|
rotate(-t);
|
76
82
|
|
83
|
+
// 拡大
|
84
|
+
|
77
85
|
scale(SCALE);
|
86
|
+
|
87
|
+
// 三角形の描画
|
78
88
|
|
79
89
|
triangle(x1, y1, x2, y2, x3, y3);
|
80
90
|
|
1
ソースコードを簡素化
test
CHANGED
@@ -16,9 +16,11 @@
|
|
16
16
|
|
17
17
|
float t;
|
18
18
|
|
19
|
-
float
|
19
|
+
float r;
|
20
20
|
|
21
|
-
float
|
21
|
+
float SCALE = 10;
|
22
|
+
|
23
|
+
|
22
24
|
|
23
25
|
void setup(){
|
24
26
|
|
@@ -28,7 +30,7 @@
|
|
28
30
|
|
29
31
|
t = 0;
|
30
32
|
|
31
|
-
r = (550+
|
33
|
+
r = (550+SCALE)/2;
|
32
34
|
|
33
35
|
noStroke();
|
34
36
|
|
@@ -44,33 +46,35 @@
|
|
44
46
|
|
45
47
|
float y = r * cos(t);
|
46
48
|
|
47
|
-
|
48
49
|
|
50
|
+
|
49
|
-
strokeWeight(1);
|
51
|
+
strokeWeight(0.1);
|
50
52
|
|
51
53
|
stroke(255, 0, 0);
|
52
54
|
|
53
55
|
noFill();
|
54
56
|
|
55
|
-
|
57
|
+
|
56
58
|
|
57
59
|
pushMatrix();
|
58
60
|
|
59
61
|
translate(x+500, y+500);
|
60
62
|
|
61
|
-
float x1 = -0.866
|
63
|
+
float x1 = -0.866;
|
62
64
|
|
63
|
-
float y1 = -0.5
|
65
|
+
float y1 = -0.5;
|
64
66
|
|
65
|
-
float x2 = 0.866
|
67
|
+
float x2 = 0.866;
|
66
68
|
|
67
|
-
float y2 = -0.5
|
69
|
+
float y2 = -0.5;
|
68
70
|
|
69
|
-
float x3 = 0.0
|
71
|
+
float x3 = 0.0;
|
70
72
|
|
71
|
-
float y3 = 1.0
|
73
|
+
float y3 = 1.0;
|
72
74
|
|
73
75
|
rotate(-t);
|
76
|
+
|
77
|
+
scale(SCALE);
|
74
78
|
|
75
79
|
triangle(x1, y1, x2, y2, x3, y3);
|
76
80
|
|