Oscillating Canvas Wave
const c = document.body
.appendChild(document.createElement('canvas'))
.getContext('2d');
Object.assign(document.body.style, {
margin: 0,
height: '100%'
});
Object.assign(c.canvas.style, {
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%'
});
let t = 0;
function resize() {
c.canvas.width = innerWidth * 2;
c.canvas.height = innerHeight * 2;
draw();
}
window.addEventListener('resize', resize);
resize();
function draw() {
const {
canvas: { width, height }
} = c;
c.fillStyle = 'rgba(155, 155, 155, .4)';
c.fillRect(0, 0, width, height);
c.fillStyle = '#000';
let x = innerWidth;
let y = 0;
t += 0.05;
for (let i = 0; i < innerHeight; i++) {
x += 2 * Math.cos(t + i * 0.1 * Math.cos(i / 200));
y += 2;
c.fillRect(x, y, 100, 1);
}
}
function loop() {
draw();
window.requestAnimationFrame(loop);
}
loop();
Speed coded oscillating wave on canvas… Looks better in fullscreen.