xxxxxxxxxx
118
var captureW = 600;
var captureH = 450;
var webcam;
var active = true; // to test camera on and off
var nameInput; //text input for name
var darkness; //sound
var spirits = []; //array of spirits filter:
var i = 0; //to generate a random spirit from []
var ghost;
var demon;
var clown;
let save; //FOR SAVE BUTTON
let msg = 0; //to generate a random message from messages[]
let messages = [
"You will be haunted by ghosts of pcomp past",
"You will be haunted by arduino ghost",
"You will not fail your pcomp final...probably",
"Your next 70 LEDs will explode",
"An army of jumper wires will jump to you in your sleep",
"You will solder your next 10 sensor pins together",
"Your USB port will never show up on your Arduino IDE",
"You will lose your toolbox next week",
"Your computer will crash before you save your code"
];
function preload() {
darkness = loadSound('Darkness.mp3');
scaryFont = loadFont('font.ttf');
}
function setup() {
//play sound
if (darkness.isLoaded) {
darkness.loop();
}
//load images
ghost = loadImage('ghost720p.png');
demon = loadImage('demon720p.png');
clown = loadImage('it.png');
spirits = [ghost, demon, clown];
cnv = createCanvas(captureW, captureH);
cnv.position((windowWidth - width) / 2, (windowHeight - height) / 2);
background(20);
imageMode(CENTER);
//WEBCAM SETUP
webcam = createCapture(VIDEO);
webcam.size(captureW, captureH);
webcam.hide();
//TEXTBOX FOR NAME
nameInput = createInput('type your name');
nameInput.position((windowWidth - width) / 2, (windowHeight + height) / 2);
//BUTTON THAT TAKES PHOTO
boo = createButton("say BOO");
boo.mousePressed(takePic);
boo.position((windowWidth - width) / 2 + 200, (windowHeight + height) / 2);
//BUTTON THAT SAVES PHOTO
save = createButton('save');
save.mousePressed(savePic);
save.position((windowWidth - width) / 2 + 300, (windowHeight + height) / 2);
//BUTTON THAT RESETS CAMERA
button = createButton("reset");
button.mousePressed(reset);
button.position((windowWidth - width) / 2 + 400, (windowHeight + height) / 2);
}
function draw() {
if (active == true) {
image(webcam, width / 2, height / 2);
filter('INVERT');
movingSpirits();
}
}
function movingSpirits() {
tint(255, 127);
//change random(-5,5) to accelerometer x,y readings
image(spirits[i], width / 2 + random(-5, 5), height / 2 + random(-5, 5));
filter('INVERT');
}
function takePic() {
if (active == true) {
image(webcam, captureW / 2, captureH / 2);
filter('INVERT');
displayMessage();
}
active = false;
}
function savePic() {
saveCanvas(cnv, nameInput.value(), 'png');
}
function reset() {
active = true;
i = floor(random(spirits.length));
msg = floor(random(messages.length));
}
function displayMessage() {
textSize(40);
fill('#a81300');
textFont(scaryFont);
text(nameInput.value() + ', ' , 20, 375);
textSize(15);
text(messages[msg],20,400);
}