Skip to content

Instantly share code, notes, and snippets.

@boq
Created November 19, 2013 22:08
Show Gist options
  • Save boq/7553447 to your computer and use it in GitHub Desktop.
Save boq/7553447 to your computer and use it in GitHub Desktop.
args = table.concat({...}, " ")
print("f(x,y) = " .. args)
f = loadstring('return ' .. args)
env = {}
setmetatable(env, {["__index"] = math})
setfenv(f, env)
p = peripheral.wrap("right") --hardcoded :P
p.clearMap()
p.appendLayer()
p.appendLayer()
p.setMapInfo({
['layers'] = {
[0] = 128,
[1] = 255
}
})
x_min = -1
x_max = 1
y_min = -1
y_max = 1
h_min = -1
h_max = 1
scale = 64.0 / (h_max - h_min)
h_zero = (0 - h_min) * scale
render_zero = h_max > 0 and h_min < 0
step_x = (x_max - x_min) / 64.0
step_y = (y_max - y_min) / 64.0
x = x_min
for row = 0,63 do
y = y_min
for column = 0,63 do
if render_zero then
p.setPoint(row, column, 0, h_zero, 1)
end
env.x = x
env.y = y
value, color = f()
if value >= h_min and value <= h_max then
h = (value - h_min) * scale
p.setPoint(row, column, 1, h, color or 4)
end
y = y + step_y
end
x = x + step_x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment