xxxxxxxxxx
237
let yesAll = 0;
let noAll = 0;
let allYN = yesAll + noAll;
let yesPer = 0;
let yesRotate = 0;
// COPY NEW
let qFont;
let yNBall;
let yNHand;
let yNBg;
// COPY NEW
let yesButton;
let noButton;
let pickYes = "Hell yeah"
let pickNo = "Gross No"
let theHotTake = "write a hot take write a hot take write a hot"
let hotTakeinput;
let inputButton;
// serial
let serial; // variable for the serial object
let latestData = "waiting for data"; // variable to hold the data
// COPY NEW
function preload(){
yNBall = loadImage(
"Hawt taker final_ne.png"
);
yNHand = loadImage(
"Hawt taker final_hand-26.png"
);
yNBg = loadImage(
"Hawt taker final_bg.png"
);
qFont = loadFont('Deep-Dream-Eighties-Regular.ttf');
console.log("image loaded")
}
// COPY NEW
function setup() {
// COPY NEW
// createCanvas(windowWidth, windowHeight-50);
createCanvas(windowWidth, windowWidth/16*9);
// COPY NEW
yesButton = createButton("hell yeah");
yesButton.mousePressed(countYes);
noButton = createButton("gross no");
noButton.mousePressed(countNo);
hotTakeinput = createInput()
hotTakeinput.value("write a hot take")
inputButton = createButton('submit');
inputButton.mousePressed(submitInput);
// serial
// serial constructor
serial = new p5.SerialPort();
// get a list of all connected serial devices
serial.list();
// serial port to use - you'll need to change this
serial.open('/dev/tty.usbmodem14601');
// callback for when the sketchs connects to the server
serial.on('connected', serverConnected);
// callback to print the list of serial devices
serial.on('list', gotList);
// what to do when we get serial data
serial.on('data', gotData);
// what to do when there's an error
serial.on('error', gotError);
// when to do when the serial port opens
serial.on('open', gotOpen);
// what to do when the port closes
serial.on('close', gotClose);
}
function gotData() {
let currentString = serial.readLine(); // store the data in a variable
trim(currentString); // get rid of whitespace
if (!currentString) return; // if there's nothing in there, ignore it
console.log(currentString); // print it out
latestData = currentString; // save it to the global variable
console.log("Data");
runData()
}
function runData(){
if (latestData == "YES") {
countYes()
} else if (latestData == "NO") {
countNo()
}
}
function submitInput(){
theHotTake = hotTakeinput.value()
console.log(hotTakeinput.value())
hotTakeinput.value("write a hot take")
yesAll = 0;
noAll = 0;
allYN = yesAll + noAll;
yesPer = 0;
}
function countYes(){
yesAll += 1
// console.log(yesAll)
// console.log("yes")
countAll()
}
function countNo(){
noAll += 1
// console.log(noAll)
// console.log("no")
countAll()
}
function countAll() {
allYN = yesAll+noAll
yesPer = yesAll / allYN * 100
console.log(yesPer)
yesRotate = map(yesPer, 0, 100, 80, -80)
console.log(yesRotate)
// console.log("count")
}
function draw() {
// COPY NEW
image(yNBg, 0, 0, windowWidth, windowWidth/16*9);
// hot take
fill(0, 0, 0)
textFont(qFont);
textSize(110)
fill(228, 227, 222)
textAlign(CENTER, CENTER);
textWrap(WORD);
textLeading(80);
text(theHotTake, 0 + ((width/8)/2), 0 -height/3, width - (width/8), height)
// COPY NEW
// score
textSize(50)
textAlign(CENTER, CENTER);
fill(187, 0, 41)
ellipse(width - width/7, height, width/8, width/8);
fill(228, 227, 222)
text(noAll, width - (width/7), height - width/23)
// text(pickNo, width - (width/4), height/2)
fill(59, 0, 238)
ellipse(width/7, height, width/8, width/8);
fill(228, 227, 222)
text(yesAll, width/7, height - width/23)
// text(pickYes, width/4, height/2)
// Main thibng
push();
translate(width/2, height);
scale(-2)
angleMode(DEGREES);
rectMode(RADIUS);
rotate(yesRotate);
noStroke()
// COPY NEW
// BALL
image(yNBall, -width/16, -width/16, width/8, width/8);
push()
// HAND
rotate(180);
image(yNHand, -width/22, -width/4.8, width/5*0.63, width/5);
pop()
pop()
// COPY NEW
}
function serverConnected() {
console.log("Connected to Server");
}
// list the ports
function gotList(thelist) {
console.log("List of Serial Ports:");
for (let i = 0; i < thelist.length; i++) {
console.log(i + " " + thelist[i]);
}
}
function gotOpen() {
console.log("Serial Port is Open");
}
function gotClose() {
console.log("Serial Port is Closed");
latestData = "Serial Port is Closed";
}
function gotError(theerror) {
console.log(theerror);
}