Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
how can I make balls resize automatically using .arc

I'm trying to make a ball made by .arc function grow with time, and i want to be able to specify the duration. this is where I'm stuck:

      function start(){
        var ball1,ball2,ball3,ball4;
        var ball=document.getElementById("MyCanvas");
        ball1=ball.getContext("2d");
        ball1.fillStyle="yellow";
        ball1.beginPath();
        ball1.arc(95,50,40,0,2*Math.PI);
        ball1.fill();
        scaling(ball1);
      }
      function scaling(ball){
        ball.beginPath();
        ball.arc(95,50,100,0,2*Math.PI);
      }
      window.addEventListener("load",start,false);
body{background-color:white;}
 <canvas id="MyCanvas" width="1000" height="500" style="border:black 1px solid"></canvas>

so is there a way to do it with .arc? and if not, any other way to do it? (like border-radius:50%).

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Really, ball should contain all the data for... a ball. Instead you set it equal to the canvas:

var ball = document.getElementById("MyCanvas");

...and use ball1 for the context

ball1 = ball.getContext("2d");

Firstly, you should rename those variables to something else.

var canvas, context;
var ball;
function start(){
  canvas = document.getElementById("MyCanvas");
  context = canvas.getContext("2d");
}
window.addEventListener("load",start,false);

and then you need to think about an animation loop and all sorts of other things...

Perhaps instead you should think about something much simpler like using pure CSS.

.circle{
  width: 50px;
  height: 50px;
  transition: all 1s;
  background: yellow;
  border-radius: 50%;
  cursor: pointer;
}

.circle:hover{
  width: 100px;
  height: 100px;
}
<div class="circle"></div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda