Learn creative coding writing simple programs

49. Show part of a loaded image using copy()

Second episode that deals with loading images. We review how to use loadImage() and then use image() to show a full image in the screen. Then we learn about copy(), which allows us to show only one part of a loaded image, and at the same time stretch or resize that part. copy() takes 9 parameters, our record :) The first parameter is the variable that holds the loaded image. Then there are two series of 4 parameters which are similar to the ones used when drawing a rectangle: x, y, width and height. The first 4 parameters refer to the loaded image: which part of that image do you want to display? The second 4 parameters refer to the display: in which area do you want to show the image area selected by the first 4 parameters?
All parameteres can be animated. Just replace a fixed value by a variable, and change that variable over time.

Tags: copy, image, loadimage

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```