Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
¿Cómo puedo hacer rebotar la pelota en un rectángulo de centro a centro de los lados del rectángulo haciendo clic en el botón?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> #myCanvas{ border-top : 1px solid black; border-bottom : 1px solid red; border-left : 1px solid green; border-right : 1px solid yellow; } </style> <script> window.onload = function(){ var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); var x = canvas.width/2; console.log(canvas) console.log(canvas.id) console.log(x) var y =5; console.log(y) var dx = 2; var dy = -2; draw(); function draw(){ //Refresh the canvas ctx.clearRect(0,0,canvas.width, canvas.height); ctx.beginPath(); //Here we create our green circle using the arc ctx.arc(x,y,10,0,Math.PI*2); ctx.fillStyle = "tomato"; ctx.fill(); //fill it // console.log(canvas.style.x) ctx.closePath(); //Here is the wall colliding conditions //Here if the value is greater than 800 that is the length of the canvas-reverse the ball if(x+dx>800){ dx = -dx; } if(x+dx<0){ dx = -dx } if(y+dy>600){ dy = -dy } if(y+dy<0){ dy = -dy } //To update the value x += dx; y += dy } setInterval(draw,10); } </script> <body bgcolor="lightblue"> <canvas id="myCanvas" width="800" height="600"> </canvas> <button type="button" class="clicks" value = "start" onclick="clickMe()"> Click Me </button> </body> </html>

*Cree un rectángulo de ancho: 800 px y alto 600 px y un borde rojo sólido de 1 px. Dibuja un cuadrado verde que tenga un lado de 60 px dentro del rectángulo. Haga que el rectángulo pequeño se mueva desde el centro de un lado al otro dentro del rectángulo exterior en sentido contrario a las agujas del reloj con solo hacer clic en un botón. Vea la imagen de abajo como referencia. (Use javascript) * Esta bola debe moverse de centro a centro al lado del rectángulo

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!