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

359
Visualizações
Rotation animation in JavaScript

I Have this Html file with doge doggo where he bouncess off the edge when he hits it(kinda like dvd save screen) and i want to make him slowly infinitly rotate but dont know where to put the script because everywhere i put the rotation script the whole page wents white.

let speed = 20;
let scale = 0.10; // Image scale (I work on 1080p monitor)
let canvas;
let ctx;

let doge = {
    x: 100,
    y: 200,
    xspeed: 5,
    yspeed: 5,
    img: new Image()
};

(function main(){
    canvas = document.getElementById("whole-screen");
    ctx = canvas.getContext("2d");
    doge.img.src = 'doge.png';

    //Draw the Background
    canvas.width  = window.innerWidth;
    canvas.height = window.innerHeight;

    update();
})();

function update() {
    setTimeout(() => {
        //Draw the canvas background
        ctx.fillStyle = '#69001c';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        //Draw Doge and his background
        ctx.fillRect(doge.x, doge.y, doge.img.width*scale, doge.img.height*scale);
        ctx.drawImage(doge.img, doge.x, doge.y, doge.img.width*scale, doge.img.height*scale);
        //Move the logo
        doge.x+=doge.xspeed;
        doge.y+=doge.yspeed;
        //Check for collision  
        checkHitBox();
        update(); 
    }, speed)
}


//Check for border collision
function checkHitBox(){
    if(doge.x+doge.img.width*scale >= canvas.width || doge.x <= 0){
        doge.xspeed *= -1;
    }
        
    if(doge.y+doge.img.height*scale >= canvas.height || doge.y <= 0){
        doge.yspeed *= -1;
    }    
}
<html>
    <head>
        <title>Bouncing Doge</title>
        <style>
            * {margin:0; padding: 0; color:red;}
        </style>
    </head>

    <body>
        <canvas id="whole-screen"></canvas>
        <script src="js/app.js"></script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza
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