Is Voronoi Noise possible in Roblox Studios?

Hello!
I am currently making a 2D pixel art game and have achieved biomes with perlin noise.
Examples of what perlin noise looks like:



This is great and all, but I’d love to have similar biomes to Dont Starve Together where the biomes appear more in a voronoi noise.
This is what voronoi noise would look like:

image
Does anyone know if Voronoi noise is possible and how I would go about scripting it?

I guess you want something like this?

local function distance(x1, y1, x2, y2)
	return math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
end

local function generateVoronoiNoise(width, height, numPoints)
	local points = {}
	for i = 1, numPoints do
		points[i] = {
			x = math.random(1, width),
			y = math.random(1, height),
			color = Color3.new(math.random(), math.random(), math.random())
		}
	end

	local noise = {}
	for x = 1, width do
		noise[x] = {}
		for y = 1, height do
			local minDist = math.huge
			local closestPoint
			for _, point in ipairs(points) do
				local dist = distance(x, y, point.x, point.y)
				if dist < minDist then
					minDist = dist
					closestPoint = point
				end
			end
			noise[x][y] = closestPoint.color
		end
	end

	return noise
end

local function visualizeVoronoiNoise(noise)
	local width = #noise
	local height = #noise[1]

	local model = Instance.new("Model")
	model.Name = "VoronoiNoise"
	model.Parent = workspace

	for x = 1, width do
		for y = 1, height do
			local part = Instance.new("Part")
			part.Size = Vector3.new(1, 1, 0.1)
			part.Position = Vector3.new(x, y, 0)
			part.Color = noise[x][y]
			part.Anchored = true
			part.CanCollide = false
			part.Parent = model
		end
	end
end

local width, height = 50, 50 
local numPoints = 20

local noise = generateVoronoiNoise(width, height, numPoints)
visualizeVoronoiNoise(noise)

4 Likes

Yes! Thank you for helping, this works well. Is there a way to make it slightly more organic though? Sorry I am a bit new to scripting… lol

You can increase the amount of cells in the noise. The variables are on the bottom.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.