diff --git a/demo/main.lua b/demo/main.lua index aa5bb6b..4650c02 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -1,9 +1,11 @@ -- Update the package path because noise.lua is in the parent directory: -package.path = package.path .. ";../noise.lua" -local Noise = require "noise" +package.path = package.path .. ";../hill_noise.lua" +local Noise = require "hill_noise" local Histogram = require 'histogram' local DRAW_RES = love.window.toPixels(4) local SCALE = 100 +local DRAW_HISTOGRAMS = false +local DRAW_GRADIENTS = false local decay = function(x) return .15^x end local n1,g1 = Noise.make1d{resolution=5, distribution=decay, seed=1} @@ -37,7 +39,7 @@ function love.mousereleased() end function love.draw() - if love.keyboard.isDown('h') then + if DRAW_HISTOGRAMS then lg.setColor(0,100,0) histogram1:draw() lg.setColor(0,0,150) @@ -125,17 +127,17 @@ function love.draw() ]] local shader - shader = love.keyboard.isDown('g') and s1g or s1 + shader = DRAW_GRADIENTS and s1g or s1 lg.setShader(shader) shader:send("range_min", xOffset) shader:send("range_max", xOffset+2*cw/SCALE) lg.draw(canv,W-cw,0) - shader = love.keyboard.isDown('g') and s2g or s2 + shader = DRAW_GRADIENTS and s2g or s2 lg.setShader(shader) shader:send("range_min", {xOffset,yOffset}) shader:send("range_max", {xOffset+2*cw/SCALE,yOffset+2*ch/SCALE}) lg.draw(canv,W-cw,ch) - shader = love.keyboard.isDown('g') and s3g or s3 + shader = DRAW_GRADIENTS and s3g or s3 lg.setShader(shader) shader:send("range_min", {xOffset,yOffset}) shader:send("range_max", {xOffset+2*cw/SCALE,yOffset+2*ch/SCALE}) @@ -143,7 +145,7 @@ function love.draw() lg.draw(canv,W-cw,2*ch) lg.setShader(nil) - lg.setColor(0,0,0,150) + lg.setColor(0,0,0,175) lg.rectangle('fill',0,0,W,font:getHeight()+love.window.toPixels(5)) lg.rectangle('fill',0,H/3,W,font:getHeight()+love.window.toPixels(5)) lg.rectangle('fill',0,2*H/3,W,font:getHeight()+love.window.toPixels(5)) @@ -157,7 +159,7 @@ function love.draw() lg.printf("3D_Noise_Shader(x,y,time)", 0,5+2*H/3, W-5, 'right') lg.setColor(20,200,20) - lg.printf("hold 'h' for histograms, 'g' for gradients", 5,5, W-5, 'center') + lg.printf("'h': toggle histograms, 'g': toggle gradients", 5,5, W-5, 'center') end function love.update(dt) @@ -171,19 +173,25 @@ end function love.keypressed(key) if key == 'escape' then love.event.quit() end if key == 'r' then love.load() end - if key == 'h' and not histogram1 then - local data1,data2,data3 = {},{},{} - for i=1,100000 do - local x = math.random()*100000 - local y = math.random()*100000 - local z = math.random()*100000 - table.insert(data1, n1(x)) - table.insert(data2, n2(x,y)) - table.insert(data3, n3(x,y,z)) + if key == 'g' then + DRAW_GRADIENTS = not DRAW_GRADIENTS + end + if key == 'h' then + DRAW_HISTOGRAMS = not DRAW_HISTOGRAMS + if DRAW_HISTOGRAMS and not histogram1 then + local data1,data2,data3 = {},{},{} + for i=1,100000 do + local x = math.random()*100000 + local y = math.random()*100000 + local z = math.random()*100000 + table.insert(data1, n1(x)) + table.insert(data2, n2(x,y)) + table.insert(data3, n3(x,y,z)) + end + histogram1 = Histogram:fromList(data1,{pos={x=0,y=0},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) + histogram2 = Histogram:fromList(data2,{pos={x=0,y=H/3},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) + histogram3 = Histogram:fromList(data3,{pos={x=0,y=2*H/3},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) end - histogram1 = Histogram:fromList(data1,{pos={x=0,y=0},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) - histogram2 = Histogram:fromList(data2,{pos={x=0,y=H/3},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) - histogram3 = Histogram:fromList(data3,{pos={x=0,y=2*H/3},size={x=W/4,y=H/3},xmin=0,xmax=1,numBuckets=30}) end end diff --git a/noise.lua b/hill_noise.lua similarity index 100% rename from noise.lua rename to hill_noise.lua