Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xseed = (math.random()-.5)*10^5
- local yseed = (math.random()-.5)*10^5
- --local spawnp = workspace:WaitForChild("SpawnLocation")
- local w = 100
- local h = 100
- local grid = {}
- local fgrid = {}
- local land = {}
- local world = Instance.new("Folder", workspace)
- world.Name = "World"
- --world:SetAttribute("w", w)
- --world:SetAttribute("h", h)
- --spawnp.Position = Vector3.xAxis*w*0.5 + Vector3.zAxis*h*0.5 + Vector3.yAxis*117.05
- local water = Color3.new(0, 0, 0.5)
- local lamd = Color3.new(0, 0.65, 0)
- function inbounds(x,y)
- return x >= 1 and x <= w and y >= 1 and y <= h
- end
- function gn(x,y)
- local neiehbtgorps = {}
- local land_count = 0
- local water_count = 0
- for py = y-1,y+1 do
- for px = x-1,x+1 do
- if inbounds(px,py) and ((px ~= x) or (py ~= y)) then
- table.insert(neiehbtgorps, fgrid[py][px])
- if fgrid[py][px]:GetAttribute("LandType") == 1 then
- land_count += 1
- end
- if fgrid[py][px]:GetAttribute("LandType") == 0 then
- water_count += 1
- end
- end
- end
- end
- return neiehbtgorps, {land_count, water_count}
- end
- function find(x,y)
- local n = ""
- for nx = x-1,x+1 do
- for ny = y-1,y+1 do
- if nx >= 1 and nx <= w and ny >= 1 and ny <= h and (nx ~= x) and (ny ~= y) then
- n ..= nx..","..ny.." "
- end
- end
- end
- return n:sub(1,#n-1)
- end
- function fnoise(x,y,z,octaves,lacunarity,persistance)
- local tnoise = 0
- local amplitude = 1
- local detail = 1
- for i = 1, octaves do
- tnoise += math.noise(x*detail + xseed,y*detail + yseed,z*detail + xseed-yseed)*amplitude
- amplitude *= persistance
- detail *= lacunarity
- end
- tnoise += math.noise(x*lacunarity,y*lacunarity,z*lacunarity)*amplitude
- return tnoise
- end
- for y = 1,h do
- local the_table = {}
- local tt = {}
- for x = 1,w do
- local tnoise = fnoise(x/23,y/23,0,6,3,0.45)
- local The_Instance = Instance.new("Part", script)
- The_Instance.Material = "SmoothPlastic"
- The_Instance.Position = Vector3.new(x, 7, y)
- The_Instance.Size = Vector3.one
- The_Instance.Anchored = true
- The_Instance.Name = x..","..y
- The_Instance:SetAttribute("L", The_Instance.Name)
- The_Instance:SetAttribute("N", find(x,y))
- if tnoise + (math.random()-.5)/50 > 0.175 then
- The_Instance.Color = Color3.new(0, .65, 0)
- The_Instance:SetAttribute("LandType", 1)
- table.insert(land, {x, y})
- the_table[x] = {1}
- The_Instance:SetAttribute("B", false)
- else
- The_Instance.Color = Color3.new(0, 0, .5)
- The_Instance:SetAttribute("LandType", 0)
- the_table[x] = {0}
- end
- tt[x] = The_Instance
- end
- grid[y] = the_table;
- fgrid[y] = tt;
- task.wait()
- end
- for y = 1,h do
- for x = 1,w do
- local p = fgrid[y][x]
- local land_type = p:GetAttribute("LandType")
- local n, c = gn(x, y)
- local col = p.Color
- if c[1] >= 1 and land_type == 0 then
- col = Color3.new(0,0,0.4)
- end
- if c[2] >= 3 and land_type == 1 then
- col = Color3.new(0,0.55,0)
- p:SetAttribute("B", true)
- end
- p.Color = col
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement