4.2 – Loading Images


  • Download last week’s HW here and review the concepts from Tuesday’s class
  • Debugging tips!
  • Use a println(button) to tell when a button is being triggered. That way you can deduce where there might be a problem.
  • Create separate variables for each one of your objects. Need a “speed” variable for each shape, otherwise when you freeze one you freeze them all.

Loading Images

  • Go to Sketch –> Add file to add an external image to your sketch
  • This will create a “data” folder in your sketch path
  • Be mindful of your file size- try to use images that are close to the dimensions of your sketch
  • Create a new variable for the image called a PImage
  • Load the image in setup, not draw. Loading it in draw will load the image over and over again and will slow down your program.
  • Draw the image with the image function, include x, y, w, and h arguments.
  • You can call tint(r,g,b,a) to apply a “filter” to the image
PImage myImage;

void setup(){
  myImage = loadImage("photo.jpg"); 

void draw(){
  image(myImage, mouseX, mouseY, 300, 200); 

Leave a Reply

Your email address will not be published. Required fields are marked *