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

120
Views
¿Cómo puedo controlar el RGB de mi lienzo para que la parte roja y verde del degradado sea la posición de mi mouse dividida por dos?

Mi instrucción HW requiere específicamente esto: RGB donde el rojo es 0, el verde es la coordenada x dividida por 2 y el azul es la coordenada y dividida por dos. Hasta ahora, los colores de mi gran lienzo están controlados por las funciones addColorStop, pero no estoy seguro de cómo cambiar los colores y cómo debería cambiar. Se agradece cualquier ayuda ya que he estado atascado en esto durante 2 días. Gracias.

 <!DOCTYPE html> <html> <body> <canvas id="big" onclick="myFiller(event);"; width="512" height="512"style="border: solid #000000;"></canvas> <canvas id="small" width="100" height="100" style="background-color: #FF0000"></canvas> <p id="para"></p> <script> // add eventListener var c = document.getElementById("big"); var ctx = c.getContext("2d"); var rgbCanvas = ctx.createLinearGradient(c.width, c.height, 120,120); rgbCanvas.addColorStop(0, "red"); rgbCanvas.addColorStop(0.5 ,"green"); rgbCanvas.addColorStop(1, "blue"); ctx.fillStyle = rgbCanvas; ctx.fillRect(0,0, 512, 512); var s = document.getElementById("small"); var stx = s.getContext("2d"); function myFiller(event) { console.log("running"); // document.getElementById("big").innerHTML = style // console.log(cData); var x = event.offsetX; var y = event.offsetY; var pixelContainer = ctx.getImageData(x, y, 1, 1).data; //pixelContainer grabs the context of "big" canvas but only one pixel worth console.log(pixelContainer); //just to see if pixelContainer is working console.log(pixelContainer[0],pixelContainer[1],pixelContainer[2],pixelContainer[3]) //understand what this is later document.getElementById("big").innerHTML = "(" + pixelContainer[0] + " " + ")"; var red = (pixelContainer[0]).toString(16); var green = (pixelContainer[1]).toString(16); var blue = (pixelContainer[2]).toString(16); document.getElementById("para").innerHTML = "#"+ red+green+blue; } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esta es una forma sencilla de hacer que el color de fondo del lienzo cambie al mover el mousemove

rif: movimiento del ratón MDN

 document.querySelector('canvas').addEventListener('mousemove', evt => evt.target.style.backgroundColor = `rgb(0, ${evt.offsetX / 2}, ${evt.offsetY / 2})` )
 <!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <canvas width="512" height="512"></canvas> </body> </html>

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