Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local computer = require("computer")
- local width, height = gpu.getResolution()
- local bufferIndex = gpu.allocateBuffer(width, height)
- local colorMap = {}
- local chars = " .:-=+*#%@"
- for i = 0, 255 do
- local value = (i / 255) * 2 - 1
- local index = math.floor((value + 1) * (#chars - 1) / 2) + 1
- colorMap[i] = chars:sub(index, index)
- end
- local function plasma(x, y, t)
- local value = math.sin(x * 0.1 + t) + math.sin(y * 0.1 + t) +
- math.sin((x + y) * 0.1 + t) + math.sin(math.sqrt(x * x + y * y) * 0.1 + t)
- return math.floor((value / 4 + 1) * 127.5)
- end
- local t = 0
- local lastTime = computer.uptime()
- local frameCount = 0
- while true do
- gpu.setActiveBuffer(bufferIndex)
- for y = 1, height do
- for x = 1, width do
- local value = plasma(x, y, t)
- gpu.set(x, y, colorMap[value])
- end
- end
- gpu.setActiveBuffer(0)
- gpu.bitblt(0, 1, 1, width, height, bufferIndex)
- t = t + 0.1
- frameCount = frameCount + 1
- local currentTime = computer.uptime()
- if currentTime - lastTime >= 1 then
- local fps = frameCount / (currentTime - lastTime)
- gpu.set(1, 1, string.format("FPS: %.2f", fps))
- frameCount = 0
- lastTime = currentTime
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement