diff --git a/Valentines/HappyMonkey-Regular.ttf b/Valentines/HappyMonkey-Regular.ttf new file mode 100644 index 0000000..71be51d Binary files /dev/null and b/Valentines/HappyMonkey-Regular.ttf differ diff --git a/Valentines/Heart.js b/Valentines/Heart.js new file mode 100644 index 0000000..d70a876 --- /dev/null +++ b/Valentines/Heart.js @@ -0,0 +1,68 @@ +class Heart { + constructor(x = 0, y = 0, radius = 10, pulseRadius = 5, falling = false) { + this.x = x; + this.y = y; + this.points = []; + this.angle = 0; + this.radius = radius; + this.pulse = 1; + this.pulseRadius = pulseRadius; + this.beat = true; + this.falling = falling; + } + + oneCycle() { + this.radius += 0.005; + for (let a = 0; a < TWO_PI; a += 0.3) { + let x = this.radius * 16 * pow(sin(a), 3); + let y = -this.radius * (13 * cos(a) - 6 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)); + if (this.beat) { + this.pulse = map(cos(a), 0, this.pulseRadius, 0.5, -1); + } + + if (this.points.length < 500) { + this.points.push(createVector(x, y)); + } + } + } + + + update() { + let x = this.radius * 16 * pow(sin(this.angle), 3); + let y = -this.radius * (13 * cos(this.angle) - 6 * cos(2 * this.angle) - 2 * cos(3 * this.angle) - cos(4 * this.angle)); + this.radius += 0.005; + this.angle += 0.05; + if (this.beat) { + this.pulse = map(cos(this.angle), 0, this.pulseRadius, 0.5, -1); + } + + if (this.points.length < 500) { + // this.points.pop(); + this.points.push(createVector(x, y)); + } + } + + render(x, y) + { + stroke('white'); + strokeWeight(2); + strokeJoin(ROUND); + let opacity = 1; + if (this.falling) { + this.x = x; + this.y = y; + opacity = 0.6; + noStroke(); + } + push(); + translate(this.x, this.y); + fill(255, 101, 186, opacity * 255); + beginShape(); + for (let v of this.points) { + vertex(this.pulse * v.x, this.pulse * v.y); + } + endShape(); + pop(); + } + } + \ No newline at end of file diff --git a/Valentines/HeartRain.js b/Valentines/HeartRain.js new file mode 100644 index 0000000..6e6a399 --- /dev/null +++ b/Valentines/HeartRain.js @@ -0,0 +1,32 @@ +class HeartRain { + constructor() { + let startingX = floor(random(width) * 2); + let startingY = floor(random(width) * 2); + this.pos = createVector(startingX, startingY); + this.vel = createVector(cos(random(-5, 5)), 0.5 + Math.random() * 5); + this.acc = createVector(0, 0); + this.heart = new Heart(this.pos.x, this.pos.y, random(1, 3), random(5, 10), true); + this.heart.oneCycle(); + } + + update() { + this.vel.add(this.acc); + this.pos.add(this.vel); + this.vel.limit(5); + + if (this.pos.y > height) { + this.pos.y = -10; + } + if (this.pos.x > width) { + this.vel.x *= -1; + } else if (this.pos.x < -10) { + this.pos.x = width; + } + this.acc.mult(0) + } + + render() { + this.heart.render(this.pos.x, this.pos.y); + } + + } \ No newline at end of file diff --git a/Valentines/README.md b/Valentines/README.md new file mode 100644 index 0000000..59a2243 --- /dev/null +++ b/Valentines/README.md @@ -0,0 +1,7 @@ +# Double Click Heart +An Valentines created using pure HTML, Inline CSS and JS when you click on it. It gives Rain of Hearts + +## Setup +Just download and open index.html. + + diff --git a/Valentines/index.html b/Valentines/index.html new file mode 100644 index 0000000..33c1af9 --- /dev/null +++ b/Valentines/index.html @@ -0,0 +1,41 @@ + + + +
+ + + +Click to make hearts
+ + + + + + + \ No newline at end of file diff --git a/Valentines/index.js b/Valentines/index.js new file mode 100644 index 0000000..47b0c02 --- /dev/null +++ b/Valentines/index.js @@ -0,0 +1,40 @@ +let hearts = []; +let fallingHearts = []; + +function preload() { + font = loadFont("./HappyMonkey-Regular.ttf"); +} + +function setup() { + createCanvas(windowWidth, windowHeight); + hearts[0] = new Heart(width / 2, height / 2); + for (let i = 0; i < 100; i++) { + fallingHearts.push(new HeartRain()); + } + + textFont(font); + textAlign(CENTER, CENTER); +} + + +window.addEventListener('click', function () { + hearts.push(new Heart(mouseX, mouseY, random(2, 5), random(10, 15))) +}) + +function draw() { + background(255); + for (let i = 0; i < fallingHearts.length; i++) { + fallingHearts[i].update(); + fallingHearts[i].render(); + } + + for (let heart of hearts) { + heart.update(); + heart.render(); + } + + noStroke(); + fill(255); + textSize(hearts[0].pulse * 25) + text("Happy V-Day", width / 2, (height / 2)) +} \ No newline at end of file