# Is It Possible To Turn A Matrix Into A Grid Using Parts?

Hi,

I was wondering if it is possible to turn a matrix of 1’s and 0’s into a grid using parts. The 1’s would be blue parts, and the 0’s would be red parts. What I’ve gotten so far is just setting the numbers in a 3 by 3 bitmap, to either 1 or 2.

``````local matrix = {}
local matrixColoumnLength = 3
local matrixRowLength = 3

for row = 1, matrixRowLength do
matrix[row] = {}
for coloumn = 1, matrixColoumnLength do
matrix[row][coloumn] = math.random(1, 2)
end
end

print(matrix)
``````

I have no idea where to start, as I’m not in highschool yet and the most “complicated” thing we’ve done in class was find out the area and perimeter of a trapezoid. I’m also not looking for any scripts, just something to get me started. Yes, if you know how to work a grid then it isnt too different. You can use an array to store data in a grid format or just store where it would be in a grid.

local GridPoints = {}

GridPoints.Insert({Pos1,Pos2,Value)
end

Then from there you just need to go through your points and check for 1 or 0 and their grid position

Thanks, but once I do that do you think I could do somethign like this?

I want find out it’s neighbouring parts and their values.

I want to go through all the parts, findout their neighbours then change their values accordingly.

A sparse matrix would be perfect for that if you are trying to make a snake game. Look into how to represent a 2d array as a singular array and perform arithmatic with it.

or if you dont care for tiny speed boost just multiply the ratio of the current index and it’s respective size then multiply that by the size of one element in 3d (assuming cubes). though you should really look into using sparse matrices as they are faster and are harder to convert after you already have a 2d setup. sparse is O(n) 2d matrix is O(n^2)

1 Like

Thanks so much! I’ll look into it. 