xxxxxxxxxx
233
//Made with the help of Ben Grosser
let inTouch = false;
let waterDrops = [];
let waterDrop;
let sleep = false;
let sleepy = 0;
let r = 0;
let blinkO = 0;
let step = 3;
function setup() {
createCanvas(windowWidth, windowHeight);
background(40);
}
function draw() {
if (sleep == true) {
if (sleepy < 15001) {
fill(40, 5);
noStroke();
rect(0, 0, width, height);
for (let i = 0; i < waterDrops.length; i = i + 1) {
waterDrops[i].update();
}
sleepy = sleepy + 10;
}
if (sleepy > 15000 && sleepy < 25001) {
let r = random(100);
if (r > 99.5) {
blink();
}
if (r > 95) {
freeze();
} else {
endFreeze();
}
sleepy = sleepy + 10
}
if (sleepy > 25000 && sleepy < 25401) {
print("sleepy");
finalFreeze();
sleepy = sleepy + 10
}
if (sleepy > 25400 && sleepy < 29001) {
// print("blink");
//background(100);
touchEnded();
blinko();
sleepy = sleepy + 10
}
if (sleepy > 29000) {
print("asleep");
background(0);
fill(100, 100, 100, 80);
textSize(100);
textAlign(CENTER);
textStyle(ITALIC);
textFont('Vladimir Script');
text("Goodnight.", width / 2, height / 2);
}
}
}
function touchStarted() {
inTouch = true;
sleep = true;
if (sleepy > 25000) {} else if (sleepy > 15001 && random(100) >= 40) {
waterDrops.push(new WaterDrop(
random(width), // x location
random(height), // y location
20, // height
20, // width
3, // speed
random(255), // opacity
255, // color
random(255) // stroke
));
} else {
waterDrops.push(new WaterDrop(
mouseX, //x location
mouseY, // y location
20, // height
20, // width
10, // speed
random(10, 250), // opacity
255, // color
random(10, 250) // stroke
));
}
return false;
}
function touchMoved() {}
function touchEnded() {
inTouch = false;
return false;
}
function freeze() {
frameRate(random(1, 10));
fill(40, 5);
noStroke();
rect(0, 0, width, height);
let r = random(100);
if (r > 50) {
for (let i = 0; i < waterDrops.length; i = i + 50) {
waterDrops[i].update();
}
} else {
for (let i = 0; i < waterDrops.length; i = i + 10) {
waterDrops[i].update();
}
}
}
function endFreeze() {
frameRate(30);
fill(40, 5);
noStroke();
rect(0, 0, width, height);
for (let i = 0; i < waterDrops.length; i = i + 1) {
waterDrops[i].update();
}
}
function blink() {
frameRate(30);
background(20);
fill(random(19, 20));
noStroke();
rect(0, 0, width, height);
}
function blinko() {
print(blinkO);
frameRate(30);
fill(100, 100, 100, 70);
textSize(100);
textAlign(CENTER);
textStyle(ITALIC);
textFont('Vladimir Script');
text("Goodnight.", width / 2, height / 2);
fill(0, blinkO);
noStroke();
rect(0, 0, width, height);
blinkO = blinkO + step;
if (blinkO > 255) {
step = step * -1;
}
if (blinkO < 0) {
step = step * -1;
}
}
function finalFreeze() {
frameRate(3);
}
class WaterDrop {
constructor(x, y, h, w, speed, opacity, col, str) {
this.x = x
this.y = y
this.h = h
this.w = w
this.speed = speed
this.opacity = opacity
this.col = col;
this.str = str;
}
update() {
noFill(this.col);
stroke(random(this.str), this.opacity);
ellipse(this.x, this.y, this.h, this.h);
if (this.h < 300) {
this.h = constrain(this.h + random(-this.speed, this.speed), 20, random(200, 500));
}
if (this.opacity <= 100 && this.opacity > 0) {
this.opacity = this.opacity - 0.1;
}
}
}