¡Claro que sí! Es una idea excelente y visualmente muy interesante. La combinación de física realista (gravedad, rebote), una forma no estándar (círculo irregular) y movimiento (rotación) crea una simulación dinámica y atractiva.
Para lograr esto, la mejor manera es a través de código (HTML y JavaScript), que puedes ejecutar directamente en tu navegador. También te daré una representación más simple en arte ASCII para que te hagas una idea rápida.
Opción 1: Visualización Interactiva en tu Navegador (Recomendado)
Esta es la mejor forma de verlo. Es una simulación completa con física.
Instrucciones:
- Copia todo el código de abajo.
- Pégalo en un editor de texto plano (como el Bloc de Notas en Windows o TextEdit en Mac).
- Guárdalo con el nombre
pelota.html (asegúrate de que la extensión sea .html y no .txt).
- Abre ese archivo con cualquier navegador web (Chrome, Firefox, Edge, etc.).
Verás una pelota rebotando de forma realista dentro de un círculo orgánico que gira lentamente.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pelota Rebotando</title>
<style>
body {
margin: 0;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #1a1a1a;
}
canvas {
border: 1px solid #333;
background-color: #2a2a2a;
}
</style>
</head>
<body>
<canvas id="bouncingBallCanvas"></canvas>
<script>
const canvas = document.getElementById('bouncingBallCanvas');
const ctx = canvas.getContext('2d');
// Ajustar el tamaño del canvas a la ventana
let width = canvas.width = window.innerWidth * 0.8;
let height = canvas.height = window.innerHeight * 0.8;
let centerX = width / 2;
let centerY = height / 2;
// --- PARÁMETROS DE LA SIMULACIÓN ---
// Pelota
let ball = {
x: centerX,
y: centerY - 100,
radius: 15,
vx: Math.random() * 4 - 2, // velocidad inicial X aleatoria
vy: 0,
color: '#ff6347' // Tomato
};
// Física
const gravity = 0.2;
const damping = 0.85; // Cuánta energía se pierde en cada rebote
// Círculo Irregular
const containerRadius = Math.min(width, height) / 2.5;
const numPoints = 20; // Puntos para definir la forma
const irregularity = 0.25; // Qué tan irregular es (0=perfecto, 1=muy irregular)
let rotationAngle = 0;
const rotationSpeed = 0.003; // Velocidad de giro
let shapePoints = [];
// Generar los puntos del círculo irregular
function generateShape() {
shapePoints = [];
for (let i = 0; i < numPoints; i++) {
const angle = (i / numPoints) * Math.PI * 2;
const randomFactor = 1 + (Math.random() - 0.5) * irregularity;
const r = containerRadius * randomFactor;
shapePoints.push({
x: centerX + r * Math.cos(angle),
y: centerY + r * Math.sin(angle)
});
}
}
// Función principal de animación
function animate() {
// Limpiar el canvas en cada fotograma
ctx.clearRect(0, 0, width, height);
// Actualizar rotación
rotationAngle += rotationSpeed;
// --- DIBUJAR EL CÍRCULO IRREGULAR GIRATORIO ---
ctx.beginPath();
for (let i = 0; i < numPoints; i++) {
const p = shapePoints[i];
// Aplicar rotación a cada punto
const rotatedX = centerX + (p.x - centerX) * Math.cos(rotationAngle) - (p.y - centerY) * Math.sin(rotationAngle);
const rotatedY = centerY + (p.x - centerX) * Math.sin(rotationAngle) + (p.y - centerY) * Math.cos(rotationAngle);
if (i === 0) {
ctx.moveTo(rotatedX, rotatedY);
} else {
ctx.lineTo(rotatedX, rotatedY);
}
}
ctx.closePath();
ctx.strokeStyle = '#4a90e2';
ctx.lineWidth = 3;
ctx.stroke();
// --- FÍSICA Y MOVIMIENTO DE LA PELOTA ---
// Aplicar gravedad
ball.vy += gravity;
// Mover la pelota
ball.x += ball.vx;
ball.y += ball.vy;
// --- DETECCIÓN DE COLISIÓN (Simplificado pero efectivo) ---
const distFromCenter = Math.sqrt((ball.x - centerX)**2 + (ball.y - centerY)**2);
// Ángulo de la pelota respecto al centro
const ballAngle = Math.atan2(ball.y - centerY, ball.x - centerX);
// Ángulo de la forma (teniendo en cuenta la rotación)
const shapeAngle = (ballAngle - rotationAngle + Math.PI * 4) % (Math.PI * 2);
// Interpolar para encontrar el radio del borde en ese ángulo exacto
const angleRatio = shapeAngle / (Math.PI * 2);
const pointIndex = angleRatio * numPoints;
const p1_idx = Math.floor(pointIndex) % numPoints;
const p2_idx = (p1_idx + 1) % numPoints;
const interpRatio = pointIndex - Math.floor(pointIndex);
const r1 = Math.sqrt((shapePoints[p1_idx].x - centerX)**2 + (shapePoints[p1_idx].y - centerY)**2);
const r2 = Math.sqrt((shapePoints[p2_idx].x - centerX)**2 + (shapePoints[p2_idx].y - centerY)**2);
const edgeRadius = r1 + (r2 - r1) * interpRatio;
// Si la pelota ha pasado el borde
if (distFromCenter + ball.radius > edgeRadius) {
// Encontrar la normal de la superficie en el punto de colisión
const p1_rot_x = centerX + (shapePoints[p1_idx].x - centerX) * Math.cos(rotationAngle) - (shapePoints[p1_idx].y - centerY) * Math.sin(rotationAngle);
const p1_rot_y = centerY + (shapePoints[p1_idx].x - centerX) * Math.sin(rotationAngle) + (shapePoints[p1_idx].y - centerY) * Math.cos(rotationAngle);
const p2_rot_x = centerX + (shapePoints[p2_idx].x - centerX) * Math.cos(rotationAngle) - (shapePoints[p2_idx].y - centerY) * Math.sin(rotationAngle);
const p2_rot_y = centerY + (shapePoints[p2_idx].x - centerX) * Math.sin(rotationAngle) + (shapePoints[p2_idx].y - centerY) * Math.cos(rotationAngle);
const normalX = p2_rot_y - p1_rot_y;
const normalY = -(p2_rot_x - p1_rot_x);
const len = Math.sqrt(normalX**2 + normalY**2);
const nx = normalX / len;
const ny = normalY / len;
// Proyección del vector de velocidad sobre la normal
const dot = ball.vx * nx + ball.vy * ny;
// Reflejar el vector de velocidad
ball.vx = (ball.vx - 2 * dot * nx) * damping;
ball.vy = (ball.vy - 2 * dot * ny) * damping;
// Corregir posición para evitar que se quede pegada
while (Math.sqrt((ball.x - centerX)**2 + (ball.y - centerY)**2) + ball.radius > edgeRadius) {
ball.x -= nx * 0.1;
ball.y -= ny * 0.1;
}
}
// --- DIBUJAR LA PELOTA ---
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
ctx.fillStyle = ball.color;
ctx.fill();
// Solicitar el siguiente fotograma
requestAnimationFrame(animate);
}
// Iniciar la simulación
generateShape();
animate();
</script>
</body>
</html>
Opción 2: Visualización Rápida con Arte ASCII
Esta es una representación muy simplificada para darte una idea del concepto directamente aquí. La rotación y la forma irregular se "simulan" cambiando ligeramente el contenedor en cada fotograma.
Fotograma 1: La pelota empieza a caer.
################
### ###
## ##
# O #
# #
# #
# #
# #
# #
## ##
### ###
#################
Fotograma 2: La pelota acelera por la gravedad.
#################
### ###
## ##
# #
# #
# O #
# #
# #
# #
## ##
#### ###
################
Fotograma 3: A punto de chocar. La forma ha girado un poco.
################
#### ###
## ##
# #
# #
# #
# #
# #
# O #
### ##
#### ###
#################
Fotograma 4: ¡Rebote! La pelota cambia de dirección contra la pared curva.
################
##### ###
## ##
# #
# #
# #
# #
# O #
# #
#### ##
#### ###
################
Fotograma 5: La pelota sube hacia el lado opuesto.
################
###### ###
## ##
# #
# O #
# #
# #
# #
# #
##### ##
#### ###
################
Espero que estas visualizaciones te gusten. La versión en código es, sin duda, la más fiel a tu petición y te permite ver la dinámica de forma fluida. Si quieres ajustar algún parámetro como la gravedad, el color de la pelota, o la velocidad de rotación, ¡solo tienes que cambiar los valores en la sección PARÁMETROS DE LA SIMULACIÓN del código