Actualmente estoy tomando un curso de introducción a la programación de computadoras. Es un curso en línea y no tiene mucha ayuda cuando estás atascado.
Estoy usando Brackets y p5.js. Desafortunadamente no sé cómo usar la función de mapa, he probado diferentes posibilidades, pero hasta ahora no he podido resolver la siguiente pregunta:
When the mouse button is pressed: - Use the 'random' function to produce random values ranging from 2 to 14. - Assign the output to Secure_vault_key0 When the mouse button is released: - Use the 'random' function to produce random values ranging from 2 to 8. - Assign the output to Secure_vault_key1 When any key is pressed: - Make Secure_vault_key2 equal to the value of 'key' When the mouse button is pressed: - Use the 'map' function to scale mouseX to values ranging from 14 to 77. - Assign the output to Secure_vault_key3 When the mouse button is pressed: - Use the 'map' function to scale mouseY to values ranging from 22 to 76. - Assign the output to Secure_vault_key4 Whilst the mouse is being dragged: - Use the 'map' function to scale mouseX to values ranging from 14 to 80. - Assign the output to Secure_vault_key5 This time you'll need to create the relevant event handlers yourself. There are many possible ways of investigating this case, but you should use ONLY the following commands: - The assignment operator aka. the equals sign ! - mouseX, mouseY - key, keyCode - random - map */ //declare the variables var Secure_vault_key0; var Secure_vault_key1; var Secure_vault_key2; var Secure_vault_key3; var Secure_vault_key4; var Secure_vault_key5; function preload() { //IMAGES WILL BE LOADED HERE } function setup() { createCanvas(512,512); //initialise the variables Secure_vault_key0 = 0; Secure_vault_key1 = ""; Secure_vault_key2 = ""; Secure_vault_key3 = 0; Secure_vault_key4 = 0; Secure_vault_key5 = 0; } ///////////////////EVENT HANDLERS/////////////////// //Create event handlers here to open the safe ... function mouseDragged() { console.log("mouseDragged", mouseX, mouseY); Secure_vault_key5 = map(mouseX, 14, 80); } function mousePressed() { console.log("mousePressed"); Secure_vault_key0 = random(2,14); Secure_vault_key3 = map(mouseX, 14, 76); } function keyPressed() { console.log("keyPressed"); Secure_vault_key2 = key; } function mouseRealesed() { console.log("mouseReleased"); Secure_vault_key1 = random(2,8); } ///////////////DO NOT CHANGE CODE BELOW THIS POINT///////////////////Consulte la página de referencia de p5.js para map(): https://p5js.org/reference/#/p5/map
Parece que solo está usando tres parámetros en sus funciones de mapa, y requiere cinco (con un sexto parámetro opcional). Los cinco parámetros necesarios son los siguientes (en este orden):
Puede parecer tonto o redundante que necesite especificar el máximo y el mínimo actual de una variable integrada como mouseX, pero es solo una de esas cosas de programación en las que la computadora exige la mayor cantidad de instrucciones explícitas posible para ejecutar correctamente sus instrucciones .
Mire el segundo ejemplo en la página de referencia enlazada arriba para ver un buen ejemplo del uso de la función map() con mouseX. Y si va a trabajar en p5.js más allá de este proyecto, ¡estas páginas de referencia son un excelente lugar para buscar respuestas a todo tipo de preguntas!