feat: 音を鳴らす

This commit is contained in:
Nebel 2020-12-29 17:49:51 +09:00
parent 9e47940615
commit d3b462fa53
3 changed files with 47 additions and 1 deletions

View file

@ -8,7 +8,8 @@
"license": "MIT",
"devDependencies": {
"snowpack": "^2.18.5",
"three": "^0.124.0"
"three": "^0.124.0",
"tone": "^14.7.58"
},
"scripts": {
"dev": "snowpack dev",

View file

@ -9,6 +9,7 @@ import {
Vector2,
WebGLRenderer,
} from "three";
import { Synth } from "tone";
import randomInt from "./randomInt";
import keyPosition from "./keyPosition";
import keyLayouts from "./config/keyLayouts";
@ -28,6 +29,7 @@ const panels = Array.from({ length: grid.colum * grid.row }, () => {
const renderer = new WebGLRenderer();
const canvas = renderer.domElement;
const raycaster = new Raycaster();
const synth = new Synth({ oscillator: { type: "square" } }).toDestination();
function render() {
renderer.render(scene, camera);
@ -38,6 +40,7 @@ function drawRect() {
const [intersect] = raycaster.intersectObjects(panels);
if (!intersect) return;
synth.triggerAttackRelease("C4", "16n");
const color = pallet[randomInt(pallet.length - 1)];
const geometry = new PlaneGeometry(1, 1);
const material = new MeshBasicMaterial({ color });

View file

@ -23,6 +23,13 @@
chalk "^2.0.0"
js-tokens "^4.0.0"
"@babel/runtime@^7.12.5":
version "7.12.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
dependencies:
regenerator-runtime "^0.13.4"
"@npmcli/move-file@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464"
@ -227,6 +234,14 @@ assert@^1.4.1:
object-assign "^4.1.1"
util "0.10.3"
automation-events@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/automation-events/-/automation-events-3.0.3.tgz#08de5bdef461bd0c9ed6cd3a7a660afa7112cecd"
integrity sha512-iFZcgSVwp8JnSXCv15LQ/tyKEAm+ToBTseD3bYWwIUUUzWQGwUMKMmIm2hM+KlfC0qBZu1xj/WqidhqvGvA3sA==
dependencies:
"@babel/runtime" "^7.12.5"
tslib "^2.0.3"
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@ -1433,6 +1448,11 @@ readdirp@~3.5.0:
dependencies:
picomatch "^2.2.1"
regenerator-runtime@^0.13.4:
version "0.13.7"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
@ -1620,6 +1640,15 @@ ssri@^8.0.0:
dependencies:
minipass "^3.1.1"
standardized-audio-context@^25.0.4:
version "25.1.6"
resolved "https://registry.yarnpkg.com/standardized-audio-context/-/standardized-audio-context-25.1.6.tgz#c1908fe6b8fe221cc2836c9873573474f7992ad0"
integrity sha512-iHvPiwbDctxpmP9sufnADBeiBpYc8km6i53TFGVGkc5usBmAJ8YNhATXXrSFZYR4MGxIImZGWCCH4LrPatPFrQ==
dependencies:
"@babel/runtime" "^7.12.5"
automation-events "^3.0.2"
tslib "^2.0.3"
string-hash@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"
@ -1680,6 +1709,19 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"
tone@^14.7.58:
version "14.7.58"
resolved "https://registry.yarnpkg.com/tone/-/tone-14.7.58.tgz#c1a31597184115aedf44ea6310a30efe902645e7"
integrity sha512-OzXsCkmaU/tLcNBc4M4dzHAjBzUGm+29DbWmAkAcCvpzWkLqo61RTcJa8tmS63F/7JHPiAJEOpuInMXw3mCvIg==
dependencies:
standardized-audio-context "^25.0.4"
tslib "^2.0.1"
tslib@^2.0.1, tslib@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.3.tgz#8e0741ac45fc0c226e58a17bfc3e64b9bc6ca61c"
integrity sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==
uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"