Author Topic: 2-Dimensional Array  (Read 2065 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
2-Dimensional Array
« on: October 16, 2015, 10:30:11 AM »
Hello,
An attempt.
Code: [Select]
'Test Array 2-dimension
include "asm.inc"
window 640,480,1

Function ReadArray(sys *array, a, b, c) as sys  'c = 1st dimension. 
   Return array[b*c+a]
End Function

Function WriteArray(sys *array, a,b, c, data) as sys   
   array[b*c+a] = data
End Function

int z
sys Bloc[12]   'array [4][3] = 12 elements

Bloc[0]  = 10  '[0,0] =10   
Bloc[1]  = 11  '[0,1] =11   
Bloc[2]  = 22  '[0,2] =22   
Bloc[3]  = 33  '[1,0] =33   
Bloc[4]  = 44  '[1,1] =44     
Bloc[5]  = 55  '[1,2] =55   
Bloc[6]  = 66  '[2,0] =66   
Bloc[7]  = 77  '[2,1] =77   
Bloc[8]  = 88  '[2,2] =88     
Bloc[9]  = 99  '[3,0] =99   
Bloc[10] = 92  '[3,1] =92   
Bloc[11] = 94  '[3,2] =94   

for j=0 to 2
for i=0 to 3
backcolor 0,0,255
text 10,z*14,12,ReadArray(&bloc,i,j,4)
z +=1
next
next

text 200,100,14,"Press Space Bar"
waitkey
cls 0,0,0
float a

sys field[640*480]

for y=0 to <480
for x=0 to <640
    writeArray(&field, x,y,640, a*256)
    a +=1
    if a=255 then a=1
next
next

for y=0 to <480
for x=0 to <640
    c = ReadArray(&field, x,y, 640)
    PutPixel x,y,c
next
next
color 255,0,0
Text 200,200,40,"BRAVO"

waitkey
winExit



[attachment deleted by admin]

Charles Pegge

  • Guest
Re: 2-Dimensional Array
« Reply #1 on: October 19, 2015, 01:25:12 AM »
Hi Peter,

A macro could be used to replace the ReadArray and WriteArray functions:

Code: OxygenBasic
  1. macro Arrays(array, a, b, c)  array[b*c+a]
  2.  


Peter

  • Guest
Re: 2-Dimensional Array
« Reply #2 on: October 19, 2015, 05:37:14 AM »
But yes! Thank you  Charles.  :)