Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created August 25, 2024 19:07
Show Gist options
  • Save tonetheman/ee14de15e689df089758d3fdb7b773e0 to your computer and use it in GitHub Desktop.
Save tonetheman/ee14de15e689df089758d3fdb7b773e0 to your computer and use it in GitHub Desktop.
picotron lorenz attrator
local width=480
local height=270
local sigma = 10;
local rho = 28;
local beta = 8.0 / 3.0;
local x=0.1
local y=0
local z=0
local dt=0.01
local pts = {}
local MAX_POINTS=5000
-- lifted from processing
function map(val,istart,istop,ostart,ostop)
return ostart + (ostop-ostart)*((val-istart)/(istop-istart))
end
function _init()
end
function _draw()
if #pts>MAX_POINTS then
print("fin",0,0)
else
cls(0)
for i,v in pairs(pts) do
pset(v.x,v.y,9)
end
end
end
function _update()
if #pts>MAX_POINTS then
return
end
local dx = sigma * (y - x);
local dy = x * (rho - z) - y;
local dz = x * y - beta * z;
x = x + dx*dt
y = y + dy*dt
z = z + dz*dt
mappedX = math.floor(map(x,-20,20,0,width))
mappedY = math.floor(map(y,-30,30,0,height))
add(pts,{x=mappedX,y=mappedY})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment