need help with scaning 2D array

Miscellaneous Forums/General Discussion/need help with scaning 2D array

How do I scan it diagonally? I have it stored as an array [x] [y].



I've tried but my head is not made for solving this, I run into step problem or out of array boundary problem.
So solution would need to be able to take steps that give diagonal scan and also be carefull about geting out of boundary.

Starting from 1,1 scan down to 9,9 going thru [2,2] [3,3] [4,4] etc.
then take the next scan [2,1] [3,2]

I would like to do this with for-loops, anyone here knows how to do it?
If so please show me in pseudo code how to do it.

I'll pay if neccessary, 20$ for solution just help me solve this before my head starts to pulsate :)

I'm sure this is too simple, but at a quick glance...

EDIT - couldn't sleep

.do_again


n=n+1

For i=1 To 9

x=x+1

y=y+n

diag_check= temp_array(x,y)

Next

If n < 9 Then Goto do_again

This works. Its BlitzMax code - you didn't specify what you were using. But whatever, its not hugely different to what its Blitz3D/Blitzplus version would be.

Graphics 800,600

'define a two dimensional array
Global myArray[10,10] 'in blitzmax this creates an array 0-9,0-9.


'start by going up the left hand side as a starting point....
For yPos = 9 To 1 Step -1
	doStuff(1,yPos)
	drawArray()
Next

'.....then across the top
For xpos = 2 To 9 ' already done square 1,1 above.
	doStuff(xPos,1)
	drawArray()
Next


'....functions

Function doStuff(xP,yP)
	Local xMax = 9
	Local yMax = 9
	'reset all array to 0's
	For X = 1 To 9
		For Y = 1 To 9
			myArray[X,Y] = 0
		Next
	Next
	
	'set 1's in diagonal lines
	For N = 0 To 9
		If xP+N <= xMax
			If yP+N <= yMax 'check x/y are within bounds of array
				myArray[xP+N,yP+N] = 1
			EndIf
		EndIf
	Next
End Function

Function drawArray()
	Cls
	For X = 1 To 9
		For Y = 1 To 9
			DrawText myArray[x,y],x*10,y*10
		Next
	Next
	Flip
	Delay 500
End Function


Graphics 640,480,32,1

SetBuffer BackBuffer()

Global CHECKS = 0
Dim ARRAY( 8 , 8 )
	
;populate
For l = 0 To 8
	Steps = 9 - l
	;top row
	For s = 0 To Steps - 1
		CHECK( l+s, s )
	Next
	;left column
	If l > 0
		For s = 0 To Steps - 1
			CHECK( s , l+s )
		Next
	EndIf
Next

;display
For y = 0 To 8
	For x = 0 To 8
		col = ( x  + y ) Mod 2
		If col = 0 
			Color 255,0,0
		Else
			Color 0,0,255
		EndIf
		Text x*30,y*30, ARRAY( x, y )
	Next
Next

Flip
WaitKey

;==================================
;==================================
;==================================

Function CHECK( x, y )

	ARRAY( x, y ) = CHECKS
	CHECKS = CHECKS + 1

End Function		


[EDIT] Similar to the above

You know arrays in BLitz as 0 indexed right?

For Y = 8 To 0 Step -1
	
	Steps = 9-Y
	
	For X = 0 To Steps-1
		Array[X, Y+X] = BLAH
	Next
	
Next	
	
For X = 1 To 8 
	
	Steps = 9-X
	
	For Y = 0 To Steps-1
		Array[X+Y, Y] = BLAH
	Next
	
Next	


I hope those other two guys don't write example code for textbooks. :-)

hehe, thanks guys you are the best :) I just needed the for loops that let me do the scanning :)