xxxxxxxxxx
242
let x = 20;
let speed;
let y = 0
let dd = x;
let me = dd;
let easing = 0.05;
let starX;
let starY;
let starSize;
let time = 7000;
let time2 = 1500;
let time3 = 2000;
let zz = 0
let serial;
let portName = '/dev/tty.usbmodem14501'; // 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;
let ii;
let pp;
let ee;
let pp2;
let mus
function preload(){
mus = loadSound("Pad-Crystalglass2.wav")
}
function setup() {
createCanvas(windowWidth, windowHeight);
//activate breathing
inhale()
//serial stuff
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
background(0)
}
function draw() {
//background(zz)
// background no trace
fill(zz)
noStroke()
rect(0, 0, width, height - 100)
rect(0, 0, 50, height)
// white fade circles and circle
for (let a = 1; a <= 100; a++) {
let c = map(a, 1, 100, 100, 0)
let b = dd - a
let d = dd + a
if (b <= 0) {
b = 0
} else {
b = dd - a
}
strokeWeight(1)
noFill()
stroke(255, 255, 255, 2)
circle(width / 2, height / 2, dd)
stroke(255, 255, 255, c)
circle(width / 2, height / 2, d)
stroke(255, 255, 255, c)
circle(width / 2, height / 2, b)
}
// breathing circle
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)
}
// diameter -- increasing
x = x + speed
dd = x
dd = constrain(dd, 0, 450)
console.log(dd)
// background becoming lighter
if (breathe == dd) {
good()
} else {
zz = 0
}
//breathe= map(breathe, 0, 255, 0, 1900)
// wave ease - in
let op = map(dd, 0, 450, height - 25, height - 100)
let targetY = op; // circle
let dy = targetY - me;
me += dy * easing;
// breathing wave ease - in
let op2 = map(breathe, 0, 255, height - 25, height - 57)
let targetY2 = op2; // breathing input
let dy2 = targetY2 - me2;
me2 += dy2 * easing2;
// wave trail
noFill()
stroke(255)
strokeWeight(2) //10
point(0 + y, me);
y = y + 0.1
// breathing wave trail
noFill()
stroke(0, 20, 255)
strokeWeight(2) //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 - 100);
starSize = random(0.1, 0.5);
starXa = random(0, width);
starYa = random(0, height - 100);
starSizea = random(0.2, 0.8);
starXb = random(0, width);
starYb = random(0, height - 100);
starSizeb = random(0, 0.45);
ellipse(starX, starY, starSize);
ellipse(starXa, starYa, starSizea);
ellipse(starXb, starYb, starSizeb);
}
function inhale() {
clearTimeout(ii);
speed = 1
pp = setTimeout(pause, time);
console.log(speed)
mus.play()
mus.setVolume(0.2)
}
function pause() {
clearTimeout(pp, time2)
speed = 0
ee = setTimeout(exhale, time2);
console.log(speed)
}
function exhale() {
clearTimeout(ee)
speed = -1
// speed = -speed
pp2 = setTimeout(pause2, time);
console.log(speed)
}
function pause2() {
clearTimeout(pp2, time2)
speed = 0
ii = setTimeout(inhale, time2);
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
}