Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local WorldGenerator = {}
- points={}
- points2={}
- function WorldGenerator.prnt(text)
- print("hello")
- load()
- run()
- points2 = copy(points)
- load()
- math.randomseed(os.time()+24)
- run()
- dat = love.image.newImageData( 512, 512 )
- dat:mapPixel(pixelFunc)
- print(mx)
- return dat
- end
- function pixelFunc(x,y,r,g,b,a)
- --print(points2[x])
- if points2[x] ~= nil then
- --print("not",x)
- mx=points2[x]..points[x]
- end
- if x > 0 and y > 0 then
- g = math.ceil(math.abs((points2[x]+points2[y])))
- --if g < 0 then g=1 end
- --print(math.abs((points2[x]+points2[y])/5))
- end
- return 41,g,41,255
- end
- function load()
- smoothness = 10
- iterations = 9
- points = {0,0}
- math.randomseed(os.time())
- end
- function draw()
- love.graphics.print("smoothness = "..smoothness ,10,10)
- for i = 1, #points - 1 do
- love.graphics.line(i, math.floor(points[i]+0.5)+250, i+1, math.floor(points[i+1]+0.5)+250)
- end
- end
- function keypressed(key)
- if key == "down" and smoothness > 1 then
- smoothness = smoothness - 1
- run()
- elseif key == "up" then
- smoothness = smoothness + 1
- run()
- end
- end
- function run()
- beginratio = math.floor((9^2-1)/(smoothness / 10))
- points = {0,0}
- for i = 1, iterations do
- routine()
- beginratio = beginratio/2
- end
- end
- function routine()
- add = 0
- for point = 1, #points do
- point = point+add
- if point >= #points then return end
- point1 = points[point]
- point2 = points[point+1]
- point3 = (point1+point2)/2+math.random(-beginratio,beginratio)
- table.insert(points, point+1, point3)
- add = add+1
- end
- end
- function copy(obj, seen)
- if type(obj) ~= 'table' then return obj end
- if seen and seen[obj] then return seen[obj] end
- local s = seen or {}
- local res = setmetatable({}, getmetatable(obj))
- s[obj] = res
- for k, v in pairs(obj) do res[copy(k, s)] = copy(v, s) end
- return res
- end
- return WorldGenerator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement