,

Colorful Python Animation

Posted by

PYTHON Colorful Animation

body {
background-color: #f0f0f0;
text-align: center;
}
h1 {
color: #333333;
}
#animation {
width: 400px;
height: 400px;
margin: 0 auto;
}

PYTHON Colorful Animation

const canvas = document.getElementById(‘animation’);
const ctx = canvas.getContext(‘2d’);

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

const colors = [‘#f7e4f7’, ‘#ffc2d7’, ‘#ffb8d1’, ‘#ff9999’, ‘#ff6666’, ‘#ff4d4d’, ‘#cc3300’];

function getRandomColor() {
return colors[Math.floor(Math.random() * colors.length)];
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);

for (let i = 0; i < 100; i++) {
const x = Math.random() * canvas.width;
const y = Math.random() * canvas.height;
const size = Math.random() * 20 + 10;

ctx.beginPath();
ctx.arc(x, y, size, 0, Math.PI * 2);
ctx.fillStyle = getRandomColor();
ctx.fill();
}

requestAnimationFrame(draw);
}

draw();