create a bleeding effect in javascript

To create a bleeding effect in JavaScript, you can make use of the HTML5 canvas element and some basic graphic manipulation techniques. Here's a simple code snippet that creates a red circle with a bleeding effect:

<canvas id="myCanvas" width="300" height="300"></canvas>
57 chars
2 lines
index.tsx
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

let radius = 50;
let x = canvas.width / 2;
let y = canvas.height / 2;

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

  // Draw outer circle
  ctx.beginPath();
  ctx.arc(x, y, radius + 10, 0, Math.PI * 2);
  ctx.fillStyle = 'red';
  ctx.fill();

  // Draw inner circle
  ctx.beginPath();
  ctx.arc(x, y, radius, 0, Math.PI * 2);
  ctx.fillStyle = '#fff';
  ctx.fill();
  radius -= 0.5;
  if (radius < 1) {
    radius = 50;
  }
  requestAnimationFrame(draw);
}

draw();
583 chars
30 lines

This code creates a canvas element and a 2D rendering context. It then draws two circles, one slightly larger and filled with red color, and another smaller white circle on top with a transparent fill. The radius of the smaller circle is then gradually decreased to create the bleeding effect in an endless loop with the requestAnimationFrame() method. You can experiment with different colors, radii, and animation techniques to customize the bleeding effect to your liking.

gistlibby LogSnag