How do i sort colors like this?

I have been trying to sort colors for a grid like color picker, like this:

However I’m stuck on how I’m suppose to sort them. There are 88 colors that have to be sorted, and the columns are 8 colors tall and the rows are 11. wide As you can see, each column is split into two parts; one that goes from white to the base color and the other going from black to the base color. How would I sort it like this?

This should be a straight forward way of achieving something like what’s seen in the image.

local huePerColumn = 30 -- This appears to be how much the hue changes every column in the image

for row = 1, 8 do
	for column = 1, 11 do
		local color

		if column <= 10 then -- Cases for the colored colors
			local hue = (column - 1) * huePerColumn / 360
			local saturation = 1
			local value = 1

			if row < 5 then -- Handle the colors that go white (1, 2, 3, 4)
				saturation = row / 5
			elseif row > 5 then -- Handle the colors that go black (6, 7, 8)
				value = (8 - row + 1) / 4
			end

			color = Color3.fromHSV(hue, saturation, value)
		else -- Cases for the grayscale colors
			color = Color.fromHSV(0, 0, 1 - (row-1) / 7)
		end
	end
end

This should work, tho I haven’t tested it.
I hope that how this works is rather clear, didn’t document the specific math behind finding some values there. If you don’t understand a part, just ask!