Surface.setSize() error

draw is special -> Adding objects to the canvas fom within the mousePressed() method

you can of course copy several images from within a loop. if you have a method to determine different regions you wanna take from your source image. e.g. you want to copy parts of the image in a grid like manner. making smaller tiles from a larger image… that would either work with incrementing values (like image size and position) or using the loops counter itself.

the classical thing would be (pseudo code):

for i = 0
copy (img, i*50,0, 50,50);

i = 0 -> (img, 0,0,50,50);
i = 1 -> (img, 50,0,50,50);
i = 2 -> (img, 1000,50,50);

so you would copy 50x50 chunks from the left to the right.
if you want to cover the whole image this way, you would have to put a second loop inside the first, so you step through all chunks in the first row, then the second row, then the third…

if your logic does not fit to the regularity of a for loop (maybe you want to select random positions or sizes) you would use some “extra” variable, as you say.

for i = 0
x = random (0,width);
copy (img,x,0, 50,50);
2 Likes