回答編集履歴
3
調整
test
CHANGED
@@ -84,3 +84,34 @@
|
|
84
84
|
<canvas id="canvas" width=100 height=100></canvas>
|
85
85
|
<textarea id="output" rows=40 cols=40></textarea>
|
86
86
|
```
|
87
|
+
|
88
|
+
|
89
|
+
# 追加テスト
|
90
|
+
私の環境だと300*300の9万件やってもヒットしないですね
|
91
|
+
ただ、firefoxは処理がかなり重いです。chromeだと早いんですが・・・
|
92
|
+
```html
|
93
|
+
<canvas id="canvas" width=300 height=300></canvas>
|
94
|
+
<script>
|
95
|
+
const ctx = document.getElementById("canvas").getContext("2d");
|
96
|
+
dataText = "0,49,50,51,10,65,66,67,10,227,129,130,227,129,132,227,129,134";
|
97
|
+
const splText = String(dataText).split(",");
|
98
|
+
for (let i = 0; i < 300; i++) {
|
99
|
+
for (let j = 0; j < 300; j+=3) {
|
100
|
+
const r = splText [j%splText.length];
|
101
|
+
const g = splText [(j+1)%splText.length];
|
102
|
+
const b = splText [(j+2)%splText.length];
|
103
|
+
ctx.beginPath();
|
104
|
+
ctx.fillStyle = "rgb(" + Number(r) + "," + Number(g) + "," + Number(b) + ")";
|
105
|
+
ctx.fillRect(j, i, 1, 1);
|
106
|
+
ctx.stroke();
|
107
|
+
const rgb1 = [r,g,b].map(x=>Number(x).toString(16).padStart(2,'0')).join('');
|
108
|
+
|
109
|
+
ctx.beginPath();
|
110
|
+
const dataTest1 = ctx.getImageData(j, i, 1, 1);
|
111
|
+
const dataTest2 = dataTest1.data;
|
112
|
+
const rgb2 = [...dataTest2].splice(0,3).map(x=>x.toString(16).padStart(2,'0')).join('');
|
113
|
+
if(rgb1!==rgb2) console.log([i,j,rgb1,rgb2]);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
</script>
|
117
|
+
```
|
2
chousei
test
CHANGED
@@ -45,4 +45,42 @@
|
|
45
45
|
}
|
46
46
|
</script>
|
47
47
|
```
|
48
|
+
# 一覧表示
|
49
|
+
ちょっとだけリファクタリングして一覧表示にしました
|
50
|
+
これでi,jがいくつのときにどう値が違うか確認してみてください
|
51
|
+
```html
|
52
|
+
<script>
|
53
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
54
|
+
const ctx = document.getElementById("canvas").getContext("2d");
|
55
|
+
const dataText = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18";
|
56
|
+
const dataArray =dataText.split(",").map(Number);
|
57
|
+
let rgb = 0;
|
58
|
+
for (let i = 0; i < 6; i++) {
|
59
|
+
rgb = 0;
|
60
|
+
for (let j = 0; j < 6; j++) {
|
61
|
+
output.value+=`i:${i}/j:${j}/`;
|
62
|
+
const r = dataArray [rgb];
|
63
|
+
const g = dataArray [rgb + 1];
|
64
|
+
const b = dataArray [rgb + 2];
|
65
|
+
ctx.beginPath();
|
66
|
+
ctx.fillStyle = `rgb(${r},${g},${b})`;
|
67
|
+
ctx.fillRect(j * 1, i * 1, 1, 1);
|
68
|
+
ctx.stroke();
|
69
|
+
|
70
|
+
output.value+=`${r},${g},${b}-`;
|
71
|
+
ctx.beginPath();
|
72
|
+
const dataTest1 = ctx.getImageData(j * 1, i * 1, 1, 1);
|
73
|
+
const dataTest2 = dataTest1.data;
|
74
|
+
const dataTest3 = String(dataTest2).split(",", 3);
|
75
|
+
output.value+=dataTest3+"\n";
|
76
|
+
rgb = rgb + 3;
|
77
|
+
}
|
78
|
+
output.value+="-------------------------\n";
|
79
|
+
}
|
80
|
+
});
|
48
81
|
|
82
|
+
</script>
|
83
|
+
|
84
|
+
<canvas id="canvas" width=100 height=100></canvas>
|
85
|
+
<textarea id="output" rows=40 cols=40></textarea>
|
86
|
+
```
|
1
調整
test
CHANGED
@@ -11,3 +11,38 @@
|
|
11
11
|
for (let j = 0; j < 6; j++) {
|
12
12
|
```
|
13
13
|
|
14
|
+
# 全文
|
15
|
+
canvasに十分なサイズを取ってみる
|
16
|
+
```html
|
17
|
+
<canvas id="canvas" width=100 height=100></canvas>
|
18
|
+
<script>
|
19
|
+
const ctx = document.getElementById("canvas").getContext("2d");
|
20
|
+
dataText = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18"
|
21
|
+
const splText = String(dataText).split(",");
|
22
|
+
let rgb = 0;
|
23
|
+
for (let i = 0; i < 6; i++) {
|
24
|
+
rgb = 0;
|
25
|
+
for (let j = 0; j < 6; j++) {
|
26
|
+
const r = splText [rgb];
|
27
|
+
const g = splText [(rgb + 1)];
|
28
|
+
const b = splText [(rgb + 2)];
|
29
|
+
ctx.beginPath();
|
30
|
+
ctx.fillStyle = "rgb(" + Number(r) + "," + Number(g) + "," + Number(b) + ")";
|
31
|
+
ctx.fillRect(j * 1, i * 1, 1, 1);
|
32
|
+
ctx.stroke();
|
33
|
+
|
34
|
+
//追記部分
|
35
|
+
window.alert(Number(r) + "," + Number(g) + "," + Number(b));
|
36
|
+
ctx.beginPath();
|
37
|
+
const dataTest1 = ctx.getImageData(j * 1, i * 1, 1, 1);
|
38
|
+
const dataTest2 = dataTest1.data;
|
39
|
+
const dataTest3 = String(dataTest2).split(",", 3);
|
40
|
+
window.alert(dataTest3);
|
41
|
+
//
|
42
|
+
|
43
|
+
rgb = rgb + 3;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
</script>
|
47
|
+
```
|
48
|
+
|