xxxxxxxxxx
112
let rVal = 0;
let pulse = 255;
let left = 0;
let right = 0;
let stars = [];
let ellipseVisible = false;
let starsVisible = false;
let keyPressedOnce = false;
let showAdditionalText = false;
function setup() {
createCanvas(600, 600);
textSize(18);
createStars();
}
function draw() {
background(0);
fill(255);
textAlign(CENTER, CENTER);
if (!serialActive) {
text("PRESS SPACE TO SELECT SERIAL PORT", width / 2, height / 2);
} else if (!ellipseVisible && !starsVisible) {
text("LIGHTLY TOUCH YOUR FINGER TO THE PULSE SENSOR", width / 2, height / 2);
} else if (ellipseVisible || starsVisible) {
drawingContext.shadowBlur = 80;
drawingContext.shadowColor = color(255);
let ellipseSize = map(pulse, 0, 255, 10, 100);
ellipse(width / 2, height / 2, ellipseSize);
}
if (ellipseVisible && !starsVisible) {
text("GIVE THE SENSOR TIME TO PICK UP ON THE PULSE\nACKNOWLEDGE THAT THIS PULSE IS YOU\nWHEN YOU'RE READY, PRESS 'm'", width / 2, height - 110);
} else if (starsVisible && !keyPressedOnce) {
moveStars();
displayStars();
text("THIS IS YOU IN THE UNIVERSE\nONE PULSE AMONG ALL THE STARS\nDOES IT MAKE YOU FEEL SMALL? PRESS 'o'", width / 2, height - 110);
} else if (starsVisible && !showAdditionalText) {
text("DON'T. BECAUSE A GREAT POET RUMI ONCE SAID\nYOU ARE NOT A DROP IN THE OCEAN,\nTRULY,YOU ARE THE OCEAN IN A DROP\nPRESS 'v'", width / 2, height - 110);
} else if (showAdditionalText) {
text("ALWAYS REMEMBER\nYOU ARE NOT IN THE UNIVERSE\nTHE UNIVERSE IS IN YOU", width / 2, height - 110);
}
}
function createStars() {
for (let i = 0; i < 100; i++) {
let x = random(width);
let y = random(height);
let radius = random(1, 3);
let speedX = random(1, 3) * (random() > 0.5 ? 1 : -1);
let speedY = random(1, 3) * (random() > 0.5 ? 1 : -1);
stars.push({ x, y, radius, speedX, speedY });
}
}
function moveStars() {
for (let star of stars) {
star.x += star.speedX;
star.y += star.speedY;
if (star.x < 0 || star.x > width || star.y < 0 || star.y > height) {
star.x = random(width);
star.y = random(height);
}
}
}
function displayStars() {
fill(255);
noStroke();
for (let star of stars) {
ellipse(star.x, star.y, star.radius * 2, star.radius * 2);
}
}
function keyPressed() {
if (key == ' ' && !serialActive) {
setUpSerial();
} else if (key == 'n' && ellipseVisible && !starsVisible) {
starsVisible = true;
} else if (key == 'm' && starsVisible) {
keyPressedOnce = true;
} else if (key == 'v' && starsVisible && keyPressedOnce) {
showAdditionalText = true;
}
}
function readSerial(data) {
if (data != null) {
let fromArduino = split(trim(data), ",");
if (fromArduino.length == 2) {
rVal = fromArduino[0];
pulse = fromArduino[1];
}
let sendToArduino = left + "," + right + "\n";
writeSerial(sendToArduino);
if (pulse > 0 && !ellipseVisible) {
ellipseVisible = true;
}
}
}
function mousePressed() {
if (!starsVisible && ellipseVisible) {
keyPressedOnce = true;
starsVisible = true;
}
}