Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help on arrays
#1
HI

I need to create an array of these elements:

- Coordinates of chessboard squares like:
a1x a1y ; a2x a2y ... h8x h8y
and then assign coordinates to them
plus array from a1 to h8

so this code would work:

a1 = pixel(a1x a1y w10)
...
h8 = pixel(h8x h8y w10)

I`ve never worked with arrays before so i don`t really know how to do it.
Any1 could help?
#2
This example uses an user-defined type to store all data into single array. This array has two dimensions. Indices in each dimension are from 0 to 7.

Code:
Copy      Help
type XYANDCOLOR x y color

int w10 ;;window handle
int sqwidth=30 ;;square width and height
int xoffset=50 ;;first square x offset relative to window
int yoffset=150 ;;first square y offset relative to window

ARRAY(XYANDCOLOR) a.create(8 8) ;;create 8x8 array

;fill coordinates and colors (colors also can be filled later similarly)
int row col
for row 0 8
,for col 0 8
,,XYANDCOLOR& sq=a[row col] ;;using sq instead a[row col] will be shorter and faster
,,sq.x=col*sqwidth+xoffset
,,sq.y=row*sqwidth+yoffset
,,sq.color=pixel(sq.x sq.y w10)


Forum Jump:


Users browsing this thread: 1 Guest(s)