IlanZiin

Love2d perlin noise

Jan 25th, 2023
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local grid = {}
  2.  
  3. local function generateNoiseGrid()
  4.     -- Fill each tile in our grid with noise.
  5.     local baseX = 10000 * love.math.random()
  6.     local baseY = 10000 * love.math.random()
  7.     for y = 1, 120 do
  8.         grid[y] = {}
  9.         for x = 1, 124 do
  10.             grid[y][x] = love.math.noise(baseX+.1*x, baseY+.2*y)
  11.         end
  12.     end
  13. end
  14.  
  15. function love.load()
  16.     generateNoiseGrid()
  17. end
  18.  
  19. function love.keypressed()
  20.     generateNoiseGrid()
  21. end
  22.  
  23. function love.draw()
  24.     local tileSize = 8
  25.     for y = 1, #grid do
  26.         for x = 1, #grid[y] do
  27.       if grid[y][x] <= 0.2 then
  28.         love.graphics.setColor(43/255, 57/255, 232/255, 1)
  29.       elseif grid[y][x] > 0.2 and grid[y][x] <= 0.4 then
  30.         love.graphics.setColor(226/255, 243/255, 98/255, 1)
  31.       else
  32.         love.graphics.setColor(55/255, 195/255, 55/255, 1)
  33.       end
  34.       love.graphics.rectangle("fill", x*tileSize, y*tileSize, tileSize-1, tileSize-1)
  35.         end
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment