Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
¿Cómo trazar un gráfico circular usando matemáticas aleatorias?

Estoy usando javascript para hacer una animación brillante con css.

 <div class="r1"> <img src="star.png"> </div>

cada punto

 .dotter{ width: 4px; height: 4px; background: blue; border-radius: 50px; position: absolute; bottom: 50%; left: 50%; transform: translate(0,0); }

JavaScript

 const block = document.querySelector('.r1'); const css = document.createElement('style'); function creator(){ var newKey = new String; for(i=0;i<=100;i++){ var dot = document.createElement('div'); dot.classList.add('dotter'); dot.style.animation = `fadeOut${i} 1s linear infinite`; var keyframes = `@keyframes fadeOut${i} {from {transform: translate(0,0) scale(1);opacity: 1;}to {transform: translate(${newRandom()[0]}%,${newRandom()[1]}%) scale(0.1);opacity: 0;}}`; block.appendChild(dot); newKey += keyframes; } css.innerText = newKey; document.getElementsByTagName('body')[0].appendChild(css); }; creator(); function newRandom(){ const n1p1 = Math.random()*900; const n1p2 = Math.random()*(-900); const n2p1 = Math.random()*(-900); const n2p2 = Math.random()*900; const n1 = Math.random() < 0.5 ? n1p1 : n1p2; const n2 = Math.random() < 0.5 ? n2p1 : n2p2; const m1 = Math.abs(n1); const m2 = Math.abs(n2); if( m1>=850 || m2>850 ){ if((m1 + m2) >= 900){ return [n2,n1]; }else{ return newRandom(); } }else{ return newRandom(); } };

Ahora el problema es que cuando ejecuto el código, los destellos terminan formando un cuadrado fuera de la imagen, necesito una solución numérica de cómo hacer que los destellos terminen formando un círculo. ingrese la descripción de la imagen aquí

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Cambié tu función NewRandom() para lograr esto, si ayuda

 const blocks = document.querySelectorAll('.r'); const css = document.createElement('style'); function creator() { var newKey = new String; blocks.forEach(function(block) { for (i = 0; i <= 100; i++) { var dot = document.createElement('div'); dot.classList.add('dotter'); dot.style.animation = `fadeOut${i} 1s linear infinite`; var keyframes = `@keyframes fadeOut${i} {from {transform: translate(0,0) scale(1);opacity: 1;}to {transform: translate(${newRandom()[0]}%,${newRandom()[1]}%) scale(0.1);opacity: 0;}}`; block.appendChild(dot); newKey += keyframes; } }); css.innerText = newKey; document.getElementsByTagName('body')[0].appendChild(css); }; creator(); function newRandom() { const angle = Math.random() * 360; const dist = Math.random() * 2000; const x = Math.cos(angle) * dist; const y = Math.sin(angle) * dist; return [x, y]; };
 .dotter { width: 4px; height: 4px; background: blue; border-radius: 50px; position: absolute; transform: translate(0, 0); }
 <div class="r"> <img src="star.png"> </div> <br><br><br><br><br> <div class="r"> <img src="star.png"> </div>

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda