xxxxxxxxxx
231
// Ahmed and Abigail
// IIM Final Project Professor Shiloh
// December 13, 2022
// Description: A program that allows the user to interact with the Demogorgon's head from Stranger Things! Here we give the user an introduction to what they are dealing with and allow them to choose how they interact with it using Arduino.
// any line of code with the ""//*"" after it is for serial communication between p5.js and Arduino
let rVal = 0; //*
let alpha = 255; //*
let left = 0; //*
let right = 0; //*
let gameState = "start";
let font1;
let font2;
let themeSong;
var i = 0; // for flickering start screen
function preload() {
font1 = loadFont("Benguiat.ttf");
font2 = loadFont("Play-Regular.ttf");
themeSong = loadSound("themesong.mp3");
upsidedownSound = loadSound("upsidedownsound1.mp4");
}
function setup() {
createCanvas(600, 600);
colorMode(HSB, 360, 100, 100, 100);
startScreen();
}
function draw() {
if (gameState == "start") {
startScreen();
} else if (gameState == "play") {
instructionScreen();
} else if (gameState == "end") {
interactiveScreen();
}
// SERIAL CODE
// if (!serialActive) {
// text("Press Space Bar to select Serial Port", 20, 30);
// } else {
// text("Connected", 20, 30);
// }
// // click on one side of the screen, one LED will light up
// // click on the other side, the other LED will light up
// if (mouseIsPressed) {
// if (mouseX <= width / 2) {
// left = 1;
// } else {
// right = 1;
// }
// } else {
// left = right = 0;
// }
}
function startScreen() {
background(0);
themeSong.loop();
themeSong.setVolume(0.6);
noFill();
stroke("#FF0000");
strokeWeight(2);
textAlign(CENTER, CENTER);
textSize(50);
textFont(font1);
glow(color("#FF0000"), 20);
text("INTERACTIVE", 300, 100);
text("DEMOGORGON", 310, 150);
glow(color("#FF0000"), 20);
text("INTERACTIVE", 300, 100);
text("DEMOGORGON", 310, 150);
push();
textSize(25);
strokeWeight(1);
glow(color("#FF0000"), 5);
text("FROM", 300, 220);
glow(color("#FF0000"), 10);
text("FROM", 300, 220);
pop();
glow(color("#FF0000"), 20);
text("STRANGER", 300, 300);
text("THINGS", 310, 350);
glow(color("#FF0000"), 20);
text("STRANGER", 300, 300);
text("THINGS", 310, 350);
push();
i = i + 1;
if (i % 10 === 0) {
stroke("#FFFFFF");
rectMode(CENTER);
glow(color("#FFFFFF"), 30);
// fill with 50
fill("#FFFFFF");
rect(300, 500, 300, 50);
} else {
// all the otehr times, fill with 255
stroke("#FFFFFF");
rectMode(CENTER);
glow(color("#FFFFFF"), 30);
fill(0);
rect(300, 500, 300, 50);
}
// stroke("#FFFFFF");
// rectMode(CENTER);
// glow(color("#FFFFFF"), 30);
// rect(300, 500, 300, 50);
textSize(20);
glow(color("#FFFFFF"), 30);
text("press enter to start", 300, 495);
pop();
if (keyCode == ENTER) {
gameState = "play";
themeSong.stop();
}
}
function glow(glowColor, blurriness) {
drawingContext.shadowBlur = blurriness;
drawingContext.shadowColor = glowColor;
}
function instructionScreen() {
background(0);
upsidedownSound.loop();
upsidedownSound.setVolume(0.3);
let instructions =
"Welcome. Today you will be able to interact with a Demogorgon's head. A Demogorgon is a monster that originated from the parallel dimension known as the Upside Down. It terrorizes local population as it hunts and kidnaps anyone it comes across with. This Demogorgon was captured by Eleven and is currently being studied. Here, you are able to come face to face with it without the fear of being dragged into the Upside Down. Enjoy. Don't forget to stay safe... just in case.";
fill("#FF0000");
glow(color("#FF0000"), 10);
strokeWeight(1);
textFont(font2);
textSize(35);
text("Introduction", 300, 50);
textSize(17);
textFont(font2);
text(instructions, 70, 50, 450, 300);
text("Once You are Ready to Face the Demogorgon Press Enter", 350, 400);
}
// EVERYTHING BELOW IS FROM SERIAL CODE EXAMPLE https://editor.p5js.org/aaronsherwood/sketches
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
function readSerial(data) {
////////////////////////////////////
//READ FROM ARDUINO HERE
////////////////////////////////////
if (data != null) {
// make sure there is actually a message
// split the message
let fromArduino = split(trim(data), ",");
// if the right length, then proceed
if (fromArduino.length == 2) {
// only store values here
// do everything with those values in the main draw loop
rVal = fromArduino[0];
alpha = fromArduino[1];
}
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
//////////////////////////////////
let sendToArduino = left + "," + right + "\n";
writeSerial(sendToArduino);
}
}
// ARDUINO CODE BELOW
/*
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(5, OUTPUT);
// start the handshake
while (Serial.available() <= 0) {
Serial.println("0,0"); // send a starting message
delay(300); // wait 1/3 second
}
}
void loop() {
// wait for data from p5 before doing something
while (Serial.available()) {
int left = Serial.parseInt();
int right = Serial.parseInt();
if (Serial.read() == '\n') {
digitalWrite(2, left);
digitalWrite(5, right);
int sensor = analogRead(A0);
delay(1);
int sensor2 = analogRead(A1);
delay(1);
Serial.print(sensor);
Serial.print(',');
Serial.println(sensor2);
}
}
}
*/