I need some help with a for/next loop problem?

Blitz3D Forums/Blitz3D Beginners Area/I need some help with a for/next loop problem?

Newbie31(Posted 2014) [#1]
Hello, I'm having a problem with for\next and would be much appreciative if someone could offer some advice on what I'm doing wrong.

I'm trying to make a program that opens an image a breaks it into 16 pieces and then shuffles them(I'm not very far along yet). Anyway the problem is I have 2 bits of code that I think should do the same thing.

The first one works as I want but will be harder to call later on.


The second one just repeatedly grabs the one imagegrab.



Should these bits of code do the same thing?


Complete Code:



Midimaster(Posted 2014) [#2]
Your inner FOR/NEXT loop runs 16*4*4 times! And each z runs 16 times. The corresponding gfxgrab[z] image always gets the screenshot of the last
x,y-pair: 3/3.

It is it enought to run only 4x4 times and calculate z from x and y:
For x = 0 To 3
	For y = 0 To 3
		z%=y*4+x
		GrabImage gfxgrab[z],x*(ImageWidth(gfx_bg)/4),y*(ImageHeight(gfx_bg)/4)
	Next
Next


or calculate x,y from z:

For z=0 to 15
	x%=z mod 4
	y%=z/4
	GrabImage gfxgrab[z],x*(ImageWidth(gfx_bg)/4),y*(ImageHeight(gfx_bg)/4)
Next



Newbie31(Posted 2014) [#3]
It didn't even occur to me to try and calculate z from x/y. But that was exactly what I was aiming for. Thanks for you help.