-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>LoveHearts | Ayush</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script> | ||
|
||
<style> | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
.info { | ||
position: absolute; | ||
color: white; | ||
top: 0; | ||
left: 0; | ||
padding: 5px; | ||
font-size: 14px; | ||
border-radius: 0 0 10px 0; | ||
background-color : rgba(255, 101, 186, 0.8); | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<p class="info">Click to make hearts</p> | ||
|
||
<script src="./Heart.js"></script> | ||
<script src="./HeartRain.js"></script> | ||
<script src="./index.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |