Code: Select all
-- code including much unused
local load_time_start = os.clock()
math.randomseed(os.time()+tonumber(io.popen("date +%N"):read("*all")))
--$ luajit parab.lua | pnmtopng > dsa.png && optipng -o7 -quiet dsa.png
local s = 2^10
local col = 255
local tab = {"P3", s, s, col}
local num = 5
local function info(msg)
os.execute("notify-send '"..msg.."'")
end
local function round(n)
return math.floor(n+0.5)
end
local function gcol(c)
if c == math.huge
or tostring(c) == "-nan" then
c = 0
end
return round(c)%(col+1)
end
local function set(r,g,b)
tab[num] = gcol(r)
tab[num+1] = gcol(g)
tab[num+2] = gcol(b)
num = num+3
end
local sts = {}
local minc, maxc
local function tset(c)
if not minc then
minc = c
maxc = c
end
minc = math.min(c, minc)
maxc = math.max(c, maxc)
table.insert(sts, c)
end
local function geta(b)
return 1/(1-math.exp(-b))
end
local function v(d)
local minb = -1002
local maxb = 30001
local b
--io.write("d = " .. d.."\n")
for i = 0,100 do
b = (minb+maxb)/2
--io.write("b = " .. b.."; ")
local a = geta(b)
--print("a = " .. a)
local col = a*(1-math.exp(-b*d))
--io.write("col = " .. col.."\n")
if math.log(col-0.5)/math.log(10) < -9
or tostring(col) == "nan" then
break
elseif col < 0.5 then
minb = b
else
maxb = b
end
end
return b
end
local function f(x)
return v((x+s/2)/s)*s/100--math.sqrt(math.abs(10000-x*x))
end
local crds = {}
local a,b = -s/2+1, s/2
for x = a,b do
if x == 0 then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 0.5
end
else
local yf = f(x)
if yf > b then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 0
end
elseif yf < a then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 1
end
else
for y = a,math.floor(yf) do
crds[y] = crds[y] or {}
crds[y][x] = 0
end
for y = math.ceil(yf),b do
crds[y] = crds[y] or {}
crds[y][x] = 1
end
local y = math.ceil(yf)
crds[y] = crds[y] or {}
crds[y][x] = math.max(0, math.min(1, y-yf))
end
end
end
-- [[
for y = s/2,-s/2+1,-1 do
for x = 1,s do
x = x-s/2
tset(crds[y][x])
end
end--]]
--[[
for x = 1,s do
x = x-1--s/2
tset(do_ws_func(2, x))
end--]]
--[[
local crn = {x1=0,y1=0, x2=0,y2=0}
local hs = {}
local function seth(x,y)
if not hs[y] then
hs[y] = {}
end
if not hs[y][x] then
hs[y][x] = 1
else
hs[y][x] = hs[y][x]+1
end
crn.x1 = math.min(x, crn.x1)
crn.y1 = math.min(y, crn.y1)
crn.x2 = math.max(x, crn.x2)
crn.y2 = math.max(y, crn.y2)
end
local function geth(x,y)
if not hs[y] then
return 0
end
return hs[y][x] or 0
end
local cx = 0
local cy = 0
local dirs = {
{1,0},
{0,1},
{-1,0},
{0,-1},
}
local dif = maxc-minc
for i = 1,#sts do
local v = sts[i]
v = (v-minc)/dif
sts[i] = v
-- [ [
v = v*255
v = v*math.pi
set(v,v,v)-- ] ]
seth(cx,cy)
--info(round(v*3)+1)
--local dir = (v*300)%1
local dir = (round(v*math.pi*100))%4+1
local ndir = dirs[dir]
cx = cx+ndir[1]
cy = cy+ndir[2]
end
crn.x1 = crn.x1-5
crn.y1 = crn.y1-5
crn.x2 = crn.x2+5
crn.y2 = crn.y2+5
local s = {crn.x2-crn.x1, crn.y2-crn.y1}
tab[2] = s[1]+1
tab[3] = s[2]+1
maxc = 0
for y,xs in pairs(hs) do
for _,h in pairs(xs) do
maxc = math.max(maxc, h)
end
end
for y = crn.y1,crn.y2 do
for x = crn.x1,crn.x2 do
local c = 0
local v = hs[y]
if v then
c = hs[y][x] or 0
end
c = c*255/maxc
--c = c%2*255
set(c,c,c)
end
end--]]
local dif = maxc-minc
for i = 1,#sts do
local v = sts[i]
v = (v-minc)/dif
--sts[i] = v
-- [[
v = v*255
--v = v*math.pi
set(v,v,v)--]]
--[[
seth(cx,cy)
--info(round(v*3)+1)
--local dir = (v*300)%1
local dir = (round(v*math.pi*100))%4+1
local ndir = dirs[dir]
cx = cx+ndir[1]
cy = cy+ndir[2]--]]
end
info("fi")
print(table.concat(tab, " "))
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
info(msg)
end