xxxxxxxxxx
let video;
let font;
let polygons;
let polygonsX = [];
let polygonsY = [];
var fontfile = "Oswald.ttf";
//sound array
let mySounds = [];
let mySound1;
let mySound2;
let mySound3;
let f1 = 20;
let f2 = 51;
let size = 600;
// This isn't used, but it might be better to initialize this in the setup
// function. Some p5 library resource may not be declared at the time your
// script is evaluated.
// Also you should use let here.
fft = new p5.FFT();
function preload() {
font = loadFont(fontfile);
//sound
mySound1 = loadSound('TADA.WAV');
mySound2 = loadSound('CHIMES.WAV');
mySound3 = loadSound('CHORD.WAV');
//剩下的sound都在这里
}
function setup() {
createCanvas(windowWidth, windowHeight);
textFont(font);
frameRate(60);
// Not used, but this ought to be declared with let somewhere
// global variables are bad practice
amplitude = new p5.Amplitude();
//create sound array
mySounds = [mySound1, mySound2, mySound3];
//scence manager
mgr = new SceneManager();
mgr.showScene(intro);
// I added this because otherwise there was no reference to the question scene
mgr.addScene(question);
// mgr.showNextScene();
}
// Added a way to move to the next scene for testing
function doubleClicked() {
mgr.showNextScene();
}
// On window resize, update the canvas size
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
// Render loop that draws shapes with p5
function draw() {
// scene
mgr.draw();
}
function intro() {
this.draw = function() {
background(255);
noFill();
let i = floor(millis() / 2000) % 2;
let angle1 = map(millis() % 1000, 0, 1000, 0, TWO_PI);
let angle2 = map(millis() % 2000, 0, 2000, 0, TWO_PI);
arc(width / 2, height / 2, 200, 200, i == 0 ? angle1 : angle2, i == 0 ? angle2 : angle1);
};
}
function question() {
console.log('iam here');
var video;
var snapshot = [];
this.enter = function() {
// added background to make the scene transition obvious
background('gray');
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
setTimeout(askQuestion, 5000);
setTimeout(systemText, 10000);
setTimeout(systemError, 10000);
}
this.draw = function() {
image(video, 10, 10, 128, 96);
}
function askQuestion() {
//alex introduces itself, 15 sec audio
mySound2.play();
}
function systemError() {
mySound3.play();
}
function systemText() {
textSize(50);
noStroke();
fill("#ffb0ea");
textAlign(CENTER, CENTER);
text("system error\n the next programe will be excuted ", width / 2, height / 2);
}
}