function generateRelativityField (ctx, size, color) {
  const centerX = size / 2
  const centerY = size / 2
  const gridLines = 8 + Math.floor(Math.random() * 7)
  const massPoints = 2 + Math.floor(Math.random() * 3)
  const distortion = 0.2 + Math.random() * 0.5

  ctx.strokeStyle = color
  ctx.lineWidth = 1

  // Create mass points that distort spacetime
  const masses = []
  for (let i = 0; i < massPoints; i++) {
    masses.push({
      x: centerX + (Math.random() - 0.5) * size * 0.6,
      y: centerY + (Math.random() - 0.5) * size * 0.6,
      mass: 0.3 + Math.random() * 0.7
    })
  }

  // Draw a grid that gets distorted by the masses
  for (let i = 0; i <= gridLines; i++) {
    // Horizontal lines
    ctx.beginPath()
    for (let x = 0; x < size; x += 2) {
      let y = (i / gridLines) * size

      // Apply distortion from masses
      for (const mass of masses) {
        const dx = x - mass.x
        const dy = y - mass.y
        const distance = Math.sqrt(dx * dx + dy * dy)
        const force = mass.mass * distortion * size / (distance + 10)

        // Add gravitational displacement
        y += force * (y - mass.y) / (distance + 1)
      }

      if (x === 0) {
        ctx.moveTo(x, y)
      } else {
        ctx.lineTo(x, y)
      }
    }
    ctx.stroke()

    // Vertical lines
    ctx.beginPath()
    for (let y = 0; y < size; y += 2) {
      let x = (i / gridLines) * size

      // Apply distortion from masses
      for (const mass of masses) {
        const dx = x - mass.x
        const dy = y - mass.y
        const distance = Math.sqrt(dx * dx + dy * dy)
        const force = mass.mass * distortion * size / (distance + 10)

        // Add gravitational displacement
        x += force * (x - mass.x) / (distance + 1)
      }

      if (y === 0) {
        ctx.moveTo(x, y)
      } else {
        ctx.lineTo(x, y)
      }
    }
    ctx.stroke()
  }
}
Generates a relativity field with curved spacetime