xxxxxxxxxx
let soundFile;
// The midi notes of a scale
let notes = [67, 69, 71, 72, 74, 76, 78, 79];
let osc;
function preload() {
soundFile = loadSound('220612.m4a');
}
function setup() {
const cnv = createCanvas(windowWidth, windowHeight);
cnv.mousePressed(canvasPressed);
noCursor();
noStroke();
fill(200);
colorMode(HSB, 250, 100, 100, 255);
soundFile.loop();
// A triangle oscillator
//osc = new p5.TriOsc();
//osc.start();
//osc.amp(0);
}
function draw() {
background(120);
const step = 20;
for (let y = 0; y <= height; y += step) {
for (let x = 0; x <= width; x += step) {
const d = dist(x, y, mouseX, mouseY);
const size = map(sin(d * (millis() / 20000)), -1, 10, 5, 90);
fill(map(sin(d * (millis() / 5000000)), -1, 1, 100, 200), 40, 100);
rectMode(CENTER);
rect(x, y, size, size);
// 音量を変化させる
const v = map(mouseY, 0, height, 1, 0, true);
soundFile.setVolume(v);
}
}
}
function canvasPressed() {
if (!soundFile.isPlaying()) soundFile.loop();
}
// A function to play a note
//function playNote(note, duration) {
//osc.freq(midiToFreq(note));
// Fade it in
//osc.fade(0.1, 0.2);
// If we sest a duration, fade it out
//if (duration) {
//setTimeout(function () {
//osc.fade(0, 0.2);
//duration - 50);
// When we click
//function mousePressed(event) {
// if (event.clientX < width && event.clientY < height) {
// Map mouse to the key index
// let key = floor(map(mouseX, 0, width, 0, notes.length));
// playNote(notes[key]);
//}
//}
// Fade it out when we release
//function mouseReleased() {
// osc.fade(0, 1);
//}