xxxxxxxxxx
57
let hr2rr = 4; // heart to respiration rate ratio
let pi = 1 // pressure-intensity
function setup() {
createCanvas(400, 400);
noStroke();
t = 0
}
function draw() {
t += 0.03; // time passing
background(255); // cleaning past frames
let br = sin(t); // breathing rate
let bpm = sin(t * hr2rr); // heart rate
// outer pressure in shoulders
if (t > 1.5) {
if (bpm > 0.25) {
fill(175)
} else {
fill(200)
}
ellipse(200, 190 * random(1-pi/100,1+pi/100), 375, 375)
}
// outer pressure baloon
fill(0);
ellipse(200, 200, 75 + min(225 * t, 300), 75 + min(225 * t, 300));
// inner pressure baloon
if (t > 2) {
if (bpm > 0.25) {
fill(175)
} else {
fill(200)
}
const d = sin(t) * pow(0.5 * t, 2)
if (d > 375) {
background(255)
noLoop()
}
let py = 200
if (t > 15) {
py *= random(1-pi/100,1+pi/100)
}
ellipse(200, py, d, d);
}
}
function keyPressed() {
// this will download the first 5 seconds of the animation!
if (key === 's') {
saveGif('S4.gif', 20);
}
}