增加音名顯示功能
This commit is contained in:
@@ -17,6 +17,7 @@ let bRadius = 4; // 黑鍵圓角(default: 4)
|
|||||||
let keyAreaY = 3; // 白鍵從 Y 軸座標多少開始?(default: 3)
|
let keyAreaY = 3; // 白鍵從 Y 軸座標多少開始?(default: 3)
|
||||||
let keyAreaHeight = 70; // 白鍵多高?(default: 70)
|
let keyAreaHeight = 70; // 白鍵多高?(default: 70)
|
||||||
let rainbowMode = false; // 彩虹模式 (default: false)
|
let rainbowMode = false; // 彩虹模式 (default: false)
|
||||||
|
let displayNoteNames = false; // 白鍵要不要顯示音名 (default: false)
|
||||||
let cc64now = 0; // 現在的踏板狀態
|
let cc64now = 0; // 現在的踏板狀態
|
||||||
let cc67now = 0;
|
let cc67now = 0;
|
||||||
|
|
||||||
@@ -136,6 +137,10 @@ function toggleRainbowMode(cb) {
|
|||||||
select('#colorpicker').removeAttribute('disabled')
|
select('#colorpicker').removeAttribute('disabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleDisplayNoteNames(cb) {
|
||||||
|
displayNoteNames = cb.checked;
|
||||||
|
}
|
||||||
|
|
||||||
function changeColor() {
|
function changeColor() {
|
||||||
keyOnColor = pedaledColor = color(select('#colorpicker').value());
|
keyOnColor = pedaledColor = color(select('#colorpicker').value());
|
||||||
darkenedColor = keyOnColor.levels.map(x => floor(x * .7));
|
darkenedColor = keyOnColor.levels.map(x => floor(x * .7));
|
||||||
|
@@ -35,6 +35,13 @@
|
|||||||
<span class="switch-txt" turnOn="On" turnOff="Off"></span>
|
<span class="switch-txt" turnOn="On" turnOff="Off"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="display: flex; align-items: center;">
|
||||||
|
<span style="margin-right: 5px;">顯示音名</span>
|
||||||
|
<input type="checkbox" id="display-note-names-checkbox" onclick="toggleDisplayNoteNames(this)">
|
||||||
|
<label for="display-note-names-checkbox">
|
||||||
|
<span class="switch-txt" turnOn="On" turnOff="Off"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -14,9 +14,7 @@ function draw() {
|
|||||||
pushHistories();
|
pushHistories();
|
||||||
drawWhiteKeys();
|
drawWhiteKeys();
|
||||||
drawBlackKeys();
|
drawBlackKeys();
|
||||||
// drawPedalLines();
|
if (displayNoteNames) {drawNoteNames();};
|
||||||
// drawNotes();
|
|
||||||
|
|
||||||
drawTexts();
|
drawTexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +96,25 @@ function drawBlackKeys() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawNoteNames() {
|
||||||
|
let noteNames = ["A", "B", "C", "D", "E", "F", "G"]; // 音名數組
|
||||||
|
|
||||||
|
textSize(12); // 設置文字大小
|
||||||
|
noStroke();
|
||||||
|
fill(0, 0, 0, 75); // 設置文字顏色為黑色
|
||||||
|
textAlign(CENTER, CENTER); // 設置文字對齊方式為居中
|
||||||
|
textStyle(NORMAL);
|
||||||
|
|
||||||
|
let wIndex = 0; // 白鍵索引
|
||||||
|
for (let i = 0; i < 52; i++) { // 遍歷所有白鍵
|
||||||
|
let thisX = border + wIndex * (whiteKeyWidth + whiteKeySpace);
|
||||||
|
let thisY = keyAreaY + keyAreaHeight - 11; // 調整文字的垂直位置
|
||||||
|
let noteName = noteNames[i % 7]; // 獲取對應的音名
|
||||||
|
text(noteName, thisX + whiteKeyWidth / 2, thisY); // 繪製音名文字
|
||||||
|
wIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function drawTexts() {
|
function drawTexts() {
|
||||||
stroke(0, 0, 10, 100);
|
stroke(0, 0, 10, 100);
|
||||||
fill(0, 0, 100, 90)
|
fill(0, 0, 100, 90)
|
||||||
|
15
style.css
15
style.css
@@ -552,7 +552,8 @@ input[type=checkbox] {
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
label[for=rainbow-mode-checkbox] {
|
label[for=rainbow-mode-checkbox],
|
||||||
|
label[for=display-note-names-checkbox] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
@@ -563,7 +564,8 @@ label[for=rainbow-mode-checkbox] {
|
|||||||
transition: .3s;
|
transition: .3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
label[for=rainbow-mode-checkbox]:after {
|
label[for=rainbow-mode-checkbox]:after,
|
||||||
|
label[for=display-note-names-checkbox]:after {
|
||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 1.25px;
|
top: 1.25px;
|
||||||
@@ -575,15 +577,18 @@ label[for=rainbow-mode-checkbox]:after {
|
|||||||
transition: .3s;
|
transition: .3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:checked + label[for=rainbow-mode-checkbox] {
|
input:checked + label[for=rainbow-mode-checkbox],
|
||||||
|
input:checked + label[for=display-note-names-checkbox] {
|
||||||
background: #6f42c1;
|
background: #6f42c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
label[for=rainbow-mode-checkbox]:active:after {
|
label[for=rainbow-mode-checkbox]:active:after,
|
||||||
|
label[for=display-note-names-checkbox]:active:after {
|
||||||
width: 32.5px;
|
width: 32.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:checked + label[for=rainbow-mode-checkbox]:after {
|
input:checked + label[for=rainbow-mode-checkbox]:after,
|
||||||
|
input:checked + label[for=display-note-names-checkbox]:after {
|
||||||
left: calc(100% - 1.25px);
|
left: calc(100% - 1.25px);
|
||||||
transform: translateX(-100%);
|
transform: translateX(-100%);
|
||||||
}
|
}
|
Reference in New Issue
Block a user