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

117
Views
is there any way to move an image diagonally to a desired location in javascript p5.js or any way to show image and hide it at a desired locationp5.js

how to perform the movement of third image diagonally till the intersection of the two images

var pic1;
var pic2;
var pic3;

let posX=0
let posY=0
const rightwall=350;

function preload(){
  pic1=loadImage("5.png")
  pic2=loadImage("iron.jpg")
  pic3=loadImage("slagmetal.jpg")
  
}
function setup() {
  createCanvas(600, 600);
}

function draw() {
  background(220);
  text(mouseX + "," + mouseY, 20, 20);

 
  img1=image(pic1, 300, 0, 150, 200)
  img2=image(pic2, posX, 50, 100, 100)
  img3=image(pic3, 0, 400, 200, 150)
  

  posX=constrain(posX+1,0,rightwall-50)
  posY+=1;
}

how can i move the third image vertically upwards at the point where the wall is

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well you could apply something like this for the collision:

this is how you could do it in your case:

let images = [pic1, pic2, pic3 ... ]
for(let img of images){ // of   is a bit weird but it basically just loops thru an array by itself and throws back the array item,
// so for(let i = 0; i < array.length; i ++)
//        array[i] = "yes" // array of i equals yes (i think)
// or for(let someString of array)
//        someString = "yes" // someString equals yes
  if (x < img.x + img.width &&
      x + w > img.x &&
      y < img.y + img.height &&
      y + h > img.y) { 
    // cool when collided stuff yeah! ... 
  }
} // this is slightly changed, but still from the mdn page (rect w rect collision)


// also: 
// since img(pic1, pic2 ... ) is an object/class it has a .width and a .height variable, same with canvases ...

class p6Image{
  constructor(){
    this.width = "Yeah!"
    this.height = "idk"
    this.pixels = ["r ed", "g reen", "b lue", ":( (a lpha)"]
    // and some other stuff like this.pixelDensity ...
  }
}

function loadp6Image(path){
  // path stuff & blob stuff & so on
  return new p6Image()
}

let cat = loadp6Image("_catzzzzzzzz/cats/cat.png")
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!