xxxxxxxxxx
213
let x=20;
let speed;
let y = 0
let me = x;
let easing = 0.05;
let starX;
let starY;
let starSize;
let time = 7000;
let time2 = 2000;
let time3 = 1000;
let zz= 0
let serial;
let portName = '/dev/tty.usbmodem14601'; // fill in your serial port name here
let breathe = 10; // size of the circle)))
let max = 200; let min =0; let y2 =0; let me2 =0; let easing2 = 0.05;
function setup() {
createCanvas(windowWidth, windowHeight);
inhale()
// frameRate(100)
serial = new p5.SerialPort();
serial.on('connected', serverConnected);
serial.on('data', serialEvent); // callback for when new data arrives
serial.open(portName); // open a serial port
rectMode(CENTER)
}
function draw() {
background(zz)
for (let a =1; a<=100; a++){
let c = map(a, 1, 100, 100, 0)
let b = x -a
let d = x+a
if (b<=0){
b=0
}
else{
b = x-a
}
strokeWeight(1)
stroke(255, 255, 255,2)
circle(width / 2, height / 2, x)
stroke(255, 255, 255, c)
circle(width / 2, height / 2, d)
stroke(255, 255, 255, c)
circle(width / 2, height / 2, b)
}
for (let g =1; g<=100; g++){
let f = map(g, 1, 100, 100, 0)
let h = breathe -g
let d = breathe+g
if (h<=0){
h=0
}
else{
h = breathe-g
}
strokeWeight(1)
stroke(0, 20, 255,2)
circle(width / 2, height / 2, breathe)
stroke(0, 20, 255, f)
circle(width / 2, height / 2, d)
stroke(0-g, 20, 255-f, f)
circle(width / 2, height / 2, h)
}
x = x + speed
x = constrain(x, 0, 500)
console.log(x)
if (breathe==x){
good()
}
else {
zz=0
}
//breathe= map(breathe, 0, 255, 0, 1900)
// wave ease - in
let op = map(x, 10, 230, height-5, height-70)
let targetY = op; // circle
let dy = targetY - me;
me += dy * easing;
// your ease - in
let op2 = map(breathe, 0, 255, height-5, height-70)
let targetY2 = op2; // breathing input
let dy2 = targetY2 - me2;
me2 += dy2 * easing2;
// wave trail
noFill()
stroke(255)
strokeWeight(4) //10
point(0 + y, me);
y = y + 0.1
// wave trail
noFill()
stroke(0, 20, 255)
strokeWeight(4) //10
point(0 + y2, me2);
y2 = y2 + 0.1
// stars
let now = frameCount % 8
if (now == 0) {
drawStars();
} else {
}
}
// stars -- not even important
function drawStars() {
stroke(255)
starX = random(0, width);
starY = random(0, height);
starSize = random(0.1, 0.5);
starXa = random(0, width);
starYa = random(0, height);
starSizea = random(0.2, 0.8);
starXb = random(0, width);
starYb = random(0, height);
starSizeb = random(0, 0.45);
ellipse(starX, starY, starSize);
ellipse(starXa, starYa, starSizea);
ellipse(starXb, starYb, starSizeb);
}
function inhale() {
clearTimeout(inhale, time);
speed = 3
setTimeout(pause, time);
console.log(speed)
}
function pause() {
clearTimeout(pause, time2)
speed = 0
setTimeout(exhale, time2);
console.log(speed)
}
function exhale() {
clearTimeout(exhale, time)
speed = -3
// speed = -speed
setTimeout(pause2, time);
console.log(speed)
}
function pause2() {
clearTimeout(pause2, time3)
speed = 0
setTimeout(inhale, time3);
console.log(speed)
}
function serialEvent() {
let data = serial.read();
// if (data.length > 0) {
// // console.log(data);
// var sensors = split(data, ",");
// console.log(sensors);
// xPos = int(sensors[0]);
// yPos = int(sensors[1]);
breathe = int(data);
}
function good(){
zz = zz+5
}