Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Array fill
#1
Hi, i was wondering if any1 could help me on these two.

1.

I have an image of a chessboard and each sguare has a coordinate. I`d like to make user click on desired square and the macro to fill an array with coordinates of given square.

For example:

There is a msg box click a1 square, user clicks that a1 square and program saves it`s coordinates. Then anather msg box is displayed : click a2 square.... and so on, untill all squares are finished. And then procced with following code but still refering to that array.

2.

How to make +/- adjustments to coordinates.

Let`s say i recognize squares by its coordinates but i would like to assume that coordinates are not allways 100% accurate. So if program is given let`s say co: x 100 and y 200 and they belong to a1 square he recognize it is a1 square. However i wolud like it to recognize a1 square even if x or y was +/- 5.
Any idea how to do it the decent way?

Thanks
#2
Something similar:

http://www.quickmacros.com/forum/showthread.php?tid=468
#3
Well there`s not much similar in that one... i still dont know how to make a "user interface" to that so the coordinates are filled by a user Sad
#4
To get square coordinates in this way, the user would have to precisely click two times for each square - top-left corner and bottom-right corner. On a single mistake all must be repeated. Or, precisely click single corner, if the macro knows square size. Is this OK? But why you want to get each coordinate manually when you can get all automatically?
#5
Can you use the "scan" function to search for an image of each square? Or "pix" to search for a color? I use those 2 a lot.
Matt B
Matt B
#6
hmm, i think you misunderstood me. By square coordinates i ment a coordinate of one pixel in that square...
#7
Code:
Copy      Help
ARRAY(POINT) a.create(8 8) ;;create 8x8 array

int i j
for i 0 8
,for j 0 8
,,mes- "Click %c%i" "" "OC" 'A'+i j+1 ;;message box
,,wait 0 ML ;;wait for mouse click
,,xm a[i j] ;;get the coordinates into the array

;display what is in the array
for i 0 8
,for j 0 8
,,out "%c%i: x=%i y=%i" 'A'+i j+1 a[i j].x a[i j].y
#8
Thanks Gintaras this works great!

How can i modify this so it remembers this array after macro is ended?
So it creates a code for this array with coordinates already filled.

Thanks
#9
Code:
Copy      Help
ARRAY(POINT)+ g_chess_array
int+ g_chess_array_filled

if(!g_chess_array_filled)
,ARRAY(POINT)& a=g_chess_array
,a.create(8 8) ;;create 8x8 array
,
,int i j
,for i 0 8
,,for j 0 8
,,,mes- "Click %c%i" "" "OC" 'A'+i j+1 ;;message box
,,,wait 0 ML ;;wait for mouse click
,,,xm a[i j] ;;get the coordinates into the array
,
,;display what is in the array
,;for i 0 8
,,;for j 0 8
,,,;out "%c%i: x=%i y=%i" 'A'+i j+1 a[i j].x a[i j].y
,g_chess_array_filled=1

;...
#10
It`s amazing how easy you can do all that...

But i wanted this macro to create a separate macro-code with coordinates given. Is that possible?

So i need a macro that uses this array with those coordinates but without need to enter those coordinates by user every time. So it would be a totally unconected to the MAIN macro i have written.
Since i have many different chessboards.
But the main macro still remains the same, the only thing that changes is the square`s coordinates that are different for each chessboard.
And i don`t want to change it every time new chessboard ocures.

Therefore this "coordinate taking macro" would help me to run the MAIN macro on different chessboards without putting much effort in checking the coordinates.

I hope it`s understandable.
#11
De_chopin Wrote:It`s amazing how easy you can do all that...

If Quick Macros were the Matrix and us lowly users were the oblivious denizens within it, Gintaras is the Architect. The uber overlord. That explains his fludity. Smile
#12
How many chessboards you have?
#13
five chessboards. but i use only one at a time.
#14
The macro can call a function which first time creates the specified array and saves to a file, and later just retrieves the specified array from the file. Is it what you need?
#15
Exactly!
#16
Create new function, name it, for example, GetChessboardArray, and paste this code:

Code:
Copy      Help
;/
function ARRAY(POINT)&a arrayId [recreate]

;Records chessboard square coordinates to an array. Saves the array to a file. If the array is already created previously, retrieves it from the file instead.
;Use arrayId to identify different arrays. It can be any numeric value. It is appended to the filename.
;If recreate is used and nonzero, creates the array again, instead of getting from file.



a.create(8 8)

str s filename
int al=64*sizeof(POINT)

filename.from("$my qm$\chess" arrayId ".arr")
if(!recreate) s.getfile(filename); err

if(s.len==al)
,memcpy(&a[0 0] s al)
else
,int i j
,for i 0 8
,,for j 0 8
,,,mes- "Click %c%i" "" "OC" 'A'+i j+1 ;;message box
,,,wait 0 ML ;;wait for mouse click
,,,xm a[i j] ;;get the coordinates into the array
,
,s.all(al 2)
,memcpy(s &a[0 0] al)
,s.setfile(filename)


Call the function from the main macro. Example:
Code:
Copy      Help
ARRAY(POINT) a
GetChessboardArray a 1

;display what is in the array
int i j
for i 0 8
,for j 0 8
,,out "%c%i: x=%i y=%i" 'A'+i j+1 a[i j].x a[i j].y

;...


Forum Jump:


Users browsing this thread: 1 Guest(s)