Circular brush painting system with grid

How I would create a painting system like this (in 3D obviously)

I can use a fixed size brush and the painting “pixel” would be the same size, but I want to make a circular brush system with a grid (like the one above) that perfectly fits but I don’t know how I would start :confused:

1 Like

If you want the center of the brush circle to be at the center of the grid cell, this might work.

local CELL_WIDTH = 4

local function paintGridCellsInCircle(mousePos, radius, paintFunct)
	local mouseX, mouseZ = mousePos.X, mousePos.Z
	local mouseGridX, mouseGridZ = mouseX - mouseX % CELL_WIDTH, mouseZ - mouseZ % CELL_WIDTH

	for x = 1, radius * math.sin(math.pi/4) do
		for z = x+1, math.sqrt(radius^2 - x^2) do
			for xm = -1, 1, 2 do
				for zm = -1, 1, 2 do
					local xOFfset, zOFfset = x * xm, z * zm
					paintFunct(mouseGridX + xOFfset, mouseGridZ + zOFfset)
					paintFunct(mouseGridX + zOFfset, mouseGridZ + xOFfset)
				end
			end
		end
		for xm = -1, 1, 2 do
			for zm = -1, 1, 2 do
				paintFunct(mouseGridX + x * xm, mouseGridZ + x * zm)
			end
		end
	end
	for gridX = mouseGridX - radius, mouseGridX + radius do
		paintFunct(gridX, mouseGridZ)
	end
	for gridZ = mouseGridZ - radius, mouseGridZ - 1 do
		paintFunct(mouseGridX, gridZ)
	end
	for gridZ = mouseGridZ + 1, mouseGridZ + radius do
		paintFunct(mouseGridX, gridZ)
	end
end

Edit: I noticed that it didn’t work, but I’ve fixed it now.

2 Likes