-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwater-reflection.js
30 lines (24 loc) · 1.02 KB
/
water-reflection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
window.addEventListener('load', function() {
var canvas = document.getElementById('reflection-canvas');
var context = canvas.getContext('2d');
var image = new Image();
image.src = 'images/blog/AI.png';
image.addEventListener('load', function() {
canvas.width = image.width;
canvas.height = image.height;
// Draw the original image
context.drawImage(image, 0, 0);
// Reflect the image vertically
context.save();
context.scale(1, -1);
context.drawImage(image, 0, -image.height * 2); // Adjust the height multiplier as needed
context.restore();
// Apply a linear opacity gradient to the reflection
var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
gradient.addColorStop(0, 'rgba(0, 0, 0, 0.4)');
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
context.globalCompositeOperation = 'destination-out';
context.fillStyle = gradient;
context.fillRect(0, 0, canvas.width, canvas.height);
});
});