Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local width, height = term.getSize()
- local function removePower(n, digits)
- local number = n
- while number > 10^digits do
- number = number/10
- end
- return number
- end
- local curn = math.random()
- local function addNoise(n, amt)
- local dec = removePower(curn, 0)
- amt = (amt + dec)*10
- local number = (math.random(amt*2)-amt)/10
- n = n + number
- curn = math.abs(curn * number)
- return n
- end
- local function getDistance(x1, y1, x2, y2)
- local dist = math.sqrt((math.abs(x1-x2)^2)+(math.abs(y1-y2)^2))
- return math.ceil(dist-0.49)
- end
- local function getClosest(p, points)
- local mind = nil
- local curi = nil
- for i=1,#points do
- local p2 = points[i]
- local dist = getDistance(p[1], p[2], p2[1], p2[2])
- if mind == nil then
- mind = dist
- curi = i
- elseif dist < mind then
- mind = dist
- curi = i
- end
- end
- return curi
- end
- local stuff = {...}
- local cols = 6
- local rows = 4
- local noise = 2
- if stuff[1] ~= nil then noise = tonumber(stuff[1]) end
- if stuff[2] ~= nil then cols = tonumber(stuff[2]) end
- if stuff[3] ~= nil then rows = tonumber(stuff[3]) end
- local points = {}
- local grad = {width/(cols+1), height/(rows+1)}
- for xb=1,cols do
- for yb=1,rows do
- local p = {addNoise(xb*grad[1], noise), addNoise(yb*grad[2], noise)}
- points[#points + 1] = p
- end
- end
- local grid = {}
- grid.width = width
- grid.height = height
- for x=1,width do
- grid[x] = {}
- for y=1,height do
- local i = getClosest({x, y}, points)
- grid[x][y] = i
- end
- end
- local colorMap = {colors.red, colors.blue, colors.yellow, colors.green, colors.lightBlue, colors.lime, colors.pink, colors.white, colors.black}
- local function draw(grid)
- for x=1,grid.width do
- for y=1,grid.height do
- local i = (grid[x][y])%(16)
- local c = 2^i
- term.setBackgroundColor(c)
- term.setCursorPos(x,y)
- term.write(" ")
- end
- end
- end
- draw(grid)
- sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement