Skip to content

Commit

Permalink
Merge pull request #5 from sup39/main
Browse files Browse the repository at this point in the history
Add timestamp to saved png file name
  • Loading branch information
wiwikuan authored Apr 17, 2023
2 parents 2d9b98f + d86a637 commit 3377d1c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions piano-visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,17 @@ function truncateString(str, maxLength = 40) {
function mouseClicked() {
// Save the canvas content as an image file
if (mouseX < 50 && mouseY < 50) {
saveCanvas('nicechord-pianometer', 'png');
const now = new Date();
const strDate =
now.getFullYear() +
String(now.getMonth()+1).padStart(2, '0') +
String(now.getDate()).padStart(2, '0');
const strTime =
String(now.getHours()).padStart(2, '0') +
String(now.getMinutes()).padStart(2, '0') +
String(now.getSeconds()).padStart(2, '0');
const fileName = `nicechord-pianometer-${strDate}_${strTime}`;
saveCanvas(fileName, 'png');
}
if (mouseY > 76) {
if (mouseX <= 84) {
Expand All @@ -245,4 +255,4 @@ function mouseClicked() {
}
}
console.log(mouseX, mouseY);
}
}

0 comments on commit 3377d1c

Please sign in to comment.