From 97c4e91d3a3c1c378f678f28cca5c063d118e47b Mon Sep 17 00:00:00 2001 From: orwell96 Date: Wed, 19 Dec 2018 22:29:07 +0100 Subject: Color lines according to depth, add bounds --- main.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index 6b7323d..a99fe7c 100644 --- a/main.lua +++ b/main.lua @@ -5,13 +5,24 @@ local maxc = 5000 -- embed an image called "world.png" -local wimg = true +local wimg = false -- image file resolution (not world resolution!) local wimresx = 3000 local wimresy = 3000 -- one pixel is ... nodes local wimscale = 4 +-- y ranges and line colors +-- Minimum y level drawn +local drminy = -30 +-- Color of min y level +local colminy = {r=0, g=0, b=255} +-- Maximum y level drawn +local drmaxy = 70 +-- Color of max y level +local colmaxy = {r=255, g=0, b=0} + + datapath = (arg[1] or "").."/" @@ -111,7 +122,7 @@ svgfile:write('viewBox="'..(-maxc)..' '..(-maxc)..' '..(2*maxc)..' '..(2*maxc).. svgfile:write([[ - + ]]) if wimg then @@ -183,16 +194,58 @@ end plcnt = 0 + +local function hexcolor(clr) + return "#"..advtrains.hex(clr.r)..advtrains.hex(clr.g)..advtrains.hex(clr.b) +end + +local function cfactor(ry) + local y = ry - (ry%4) + + local fac = (y-drminy)/(drmaxy-drminy) + return fac +end + +local function pl_header(fac) + + local color = { + r = colminy.r + (colmaxy.r-colminy.r)*fac, + g = colminy.g + (colmaxy.g-colminy.g)*fac, + b = colminy.b + (colmaxy.b-colminy.b)*fac, + } + + local c = hexcolor(color) + return '= 0 then + -- insert final point + -- Note that we mirror y, so positive z is up + table.insert(str, e.x .. "," .. -(e.z) .. " ") + table.insert(str, '" />\n') + plcnt = plcnt + 1 + end + if cf <= 1 and cf >= 0 then + table.insert(str, pl_header(cf)) + end + end + if cf <= 1 and cf >= 0 then + -- Note that we mirror y, so positive z is up + table.insert(str, e.x .. "," .. -(e.z) .. " ") + end + lastcf = cf end table.insert(str, '" />\n') -- cgit v1.2.3