xxxxxxxxxx
272
let yesAll = 0;
let noAll = 0;
let allYN = yesAll + noAll;
let yesPer = 0;
let yesRotate = 0;
let qFont;
let yNBall;
let yNHand;
let yNBg;
// NEW JSONNNN
let results;
let takeObj;
let takeArray;
let yesButton;
let noButton;
let pickYes = "Hell yeah"
let pickNo = "Gross No"
let theHotTake = "what in the world"
let hotTakeinput;
let inputButton;
// The serviceUuid must match the serviceUuid of the device you would like to connect
const serviceUuid = "a75e7813-2c59-438a-8606-68ba69943c04";
let myCharacteristic;
let latestData = 0;
let myBLE;
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');
// NEW JSONNNN
results = loadJSON("takes.json")
console.log("image loaded")
}
function setup() {
createCanvas(windowWidth, windowWidth/16*9);
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);
// NEW JSONNNN
takeArray = [];
myBLE = new p5ble();
const connectButton = createButton('Connect')
connectButton.mousePressed(connectToBle);
// NEW JSONNNN
const downloadJson = createButton("download");
downloadJson.mousePressed(savvve);
}
function connectToBle() {
// Connect to a device by passing the service UUID
myBLE.connect(serviceUuid, gotCharacteristics);
}
// NEW JSONNNN
function saveJSONfile() {
takeObj = {};
takeObj.take = theHotTake;
takeObj.yes = yesAll;
takeObj.no = noAll;
takeArray.push(takeObj);
print(takeArray)
//results.push(takeArray)
}
// NEW JSONNNN
function savvve(){
saveJSON(takeArray, 'takes.json');
}
function gotCharacteristics(error, characteristics) {
if (error) console.log('error: ', error);
console.log('characteristics: ', characteristics);
myCharacteristic = characteristics[0];
// Read the value of the first characteristic
myBLE.read(myCharacteristic, gotValue);
}
function gotValue(error, value) {
if (error) console.log('error: ', error);
console.log('value: ', value);
if (value != latestData){
latestData = value;
runData()
console.log('data: ', latestData);
}
myBLE.read(myCharacteristic, gotValue);
}
function runData(){
if (latestData == 1) {
countNo()
} else if (latestData == 2){
countYes()
}
}
function submitInput(){
theHotTake = hotTakeinput.value()
console.log(hotTakeinput.value())
hotTakeinput.value("write a hot take")
yesAll = 0;
noAll = 0;
allYN = yesAll + noAll;
yesPer = 0;
countAll()
}
function countYes(){
yesAll += 1
// console.log(yesAll)
// console.log("yes")
countAll()
// NEW JSONNNN
saveJSONfile()
}
function countNo(){
noAll += 1
// console.log(noAll)
// console.log("no")
countAll()
// NEW JSONNNN
saveJSONfile()
}
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
// NEW JSONNNN
let now = new Date();
// Extract hours, minutes, and seconds
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
// Display the local time
timeString = nf(hours, 2) + ':' + nf(minutes, 2) + ':' + nf(seconds, 2);
if (timeString == "08:02:10" || timeString == "11:12:09" || timeString == "14:12:09" || timeString == "16:22:09" || timeString == "17:32:09" || timeString == "19:02:10" || timeString == "21:02:19" || timeString == "03:01:19") {
savvve()
print(takeArray)
}
}