If you just want to change the Pacman function image in the example Processing sketch there are just two steps:
- You can download a zip file with the code from here.
- Unzip the file, run the sketch and check that the background loads. Now you can adapt the function (or variables) to draw and label your own Pacman and show him/her in your sketch. For example here are two different versions of the function call.
//This draws a large yellow pacman using the built in label //and X and Y positions. drawPacman(centreX,centreY,pacSize, yellow, label); //This draws a smaller blue pacman and customises the label //and X and Y positions. drawPacman(centreX/3,centreY/2,50, blue, "Lisa");
To load your own image and use it as background in the Processing sketch there are six steps you need to follow:
- Start your own sketch, you can download the code from here.
- Choose an image (we used this one) and copy it into your sketch’s data folder.
- Create a Processing Image variable with the statement:
This code should be placed right at the beginning of the sketch with the other global variables.
- In void setup() you should ensure that the window is the same size as your image. In our example, the image is 500*359 pixels, and so we use this for the size() of the Processing sketch window as well:
size(500,359);//draw window the same size as your image
- Also in void setup(), your program needs to load the image information from an image file (which you should have saved in your data folder in step 2, remember). If you want to change the image that you load you should change the filename to be the same as your new image. VERY IMPORTANT. Loading the image takes a while. Never, never use this code in your draw() function.
bg = loadImage("bg.png");
- At last we are ready to display the image! In void draw(), set the image as the background to your sketch with this code: