-
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.
Merge pull request #26 from Ayush7614/temp
Temp
- Loading branch information
Showing
10 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
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 Double Click Heart created using pure HTML, CSS and JS when you click on it. It gives heart like whwn you click on any instagram post | ||
|
||
## 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,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<title>Double Click Heart</title> | ||
</head> | ||
<body> | ||
<h3>Double click on the image to <i class="fas fa-heart"></i> it</h3> | ||
<small>You liked it <span id="times">0</span> times</small> | ||
|
||
<div class="loveMe"></div> | ||
|
||
<script src="script.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,42 @@ | ||
const loveMe = document.querySelector('.loveMe') | ||
const times = document.querySelector('#times') | ||
|
||
let clickTime = 0 | ||
let timesClicked = 0 | ||
|
||
loveMe.addEventListener('click', (e) => { | ||
if(clickTime === 0) { | ||
clickTime = new Date().getTime() | ||
} else { | ||
if((new Date().getTime() - clickTime) < 800) { | ||
createHeart(e) | ||
clickTime = 0 | ||
} else { | ||
clickTime = new Date().getTime() | ||
} | ||
} | ||
}) | ||
|
||
const createHeart = (e) => { | ||
const heart = document.createElement('i') | ||
heart.classList.add('fas') | ||
heart.classList.add('fa-heart') | ||
|
||
const x = e.clientX | ||
const y = e.clientY | ||
|
||
const leftOffset = e.target.offsetLeft | ||
const topOffset = e.target.offsetTop | ||
|
||
const xInside = x - leftOffset | ||
const yInside = y - topOffset | ||
|
||
heart.style.top = `${yInside}px` | ||
heart.style.left = `${xInside}px` | ||
|
||
loveMe.appendChild(heart) | ||
|
||
times.innerHTML = ++timesClicked | ||
|
||
setTimeout(() => heart.remove(), 1000) | ||
} |
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,52 @@ | ||
@import url('https://fonts.googleapis.com/css?family=Oswald'); | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: 'Oswald', sans-serif; | ||
text-align: center; | ||
overflow: hidden; | ||
margin: 0; | ||
} | ||
|
||
h3 { | ||
margin-bottom: 0; | ||
text-align: center; | ||
} | ||
|
||
small { | ||
display: block; | ||
margin-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
.fa-heart { | ||
color: red; | ||
} | ||
|
||
.loveMe { | ||
height: 440px; | ||
width: 300px; | ||
background: url('https://images.unsplash.com/photo-1504215680853-026ed2a45def?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80') | ||
no-repeat center center/cover; | ||
margin: auto; | ||
cursor: pointer; | ||
max-width: 100%; | ||
position: relative; | ||
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); | ||
} | ||
|
||
.loveMe .fa-heart { | ||
position: absolute; | ||
animation: grow 0.6s linear; | ||
transform: translate(-50%, -50%) scale(0); | ||
} | ||
|
||
@keyframes grow { | ||
to { | ||
transform: translate(-50%, -50%) scale(10); | ||
opacity: 0; | ||
} | ||
} |
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)) | ||
} |