nonogamer9

Cube Demo with Affine Texture Mapping for OpenComputers

May 7th, 2026 (edited)
140
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.68 KB | Source Code | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local event = require("event")
  4. local unicode = require("unicode")
  5. local internet = require("internet")
  6. local bit32 = require("bit32")
  7. local computer = require("computer")
  8.  
  9. -- --- GPU BUFFER INITIALIZATION ---
  10. local screenW, screenH = gpu.getResolution()
  11. local backBuffer = gpu.allocateBuffer(screenW, screenH)
  12. if not backBuffer then
  13.   error("Not enough GPU memory for double buffering!")
  14. end
  15.  
  16. -- --- LOCALIZATION & PRE-COMPUTATION ---
  17. local vW, vH = screenW * 2, screenH * 4
  18. local scale = 35
  19. local floor, ceil, max, min = math.floor, math.ceil, math.max, math.min
  20. local bOr = bit32.bor
  21. local uChar = unicode.char
  22. local gSet, gSetFG = gpu.set, gpu.setForeground
  23. local tConcat = table.concat
  24. local math_cos, math_sin = math.cos, math.sin
  25.  
  26. local rowOffsets, rowOffBase = {}, {}
  27. for y = 0, vH do
  28.   rowOffsets[y] = floor(y * 0.25) * screenW
  29.   rowOffBase[y] = (y % 4) * 2
  30. end
  31.  
  32. local xModMap, halfXFloor = {}, {}
  33. for x = 0, vW do
  34.   xModMap[x] = (x % 2) + 1
  35.   halfXFloor[x] = floor(x * 0.5)
  36. end
  37.  
  38. -- --- BMP LOADING ---
  39. local function loadBMP(url)
  40.   local handle = internet.request(url)
  41.   if not handle then return nil end
  42.   local chunks = {}
  43.   for chunk in handle do chunks[#chunks+1] = chunk end
  44.   local data = tConcat(chunks)
  45.   local dataOffset = data:byte(11) + data:byte(12)*256
  46.   local w, h = data:byte(19) + data:byte(20)*256, data:byte(23) + data:byte(24)*256
  47.   local pixels, colors = {}, {}
  48.   local rowSize = floor((24 * w + 31) / 32) * 4
  49.   for y = 0, h - 1 do
  50.     local rowStart = dataOffset + (h - 1 - y) * rowSize + 1
  51.     local yOffset = y * w
  52.     for x = 0, w - 1 do
  53.       local p = rowStart + x * 3
  54.       local b, g, r = data:byte(p), data:byte(p+1), data:byte(p+2)
  55.       local idx = yOffset + x + 1
  56.       pixels[idx] = ((r + g + b) / 3) > 100
  57.       colors[idx] = (r * 65536 + g * 256 + b)
  58.     end
  59.   end
  60.   return {w = w, h = h, p = pixels, c = colors}
  61. end
  62.  
  63. local tex = loadBMP("https://file.garden/agSJPgzKlhVH5Zyw/stone.bmp")
  64. local charCache = {}
  65. for i = 0, 255 do charCache[i] = uChar(0x2800 + i) end
  66.  
  67. local totalPixels = screenW * screenH
  68. local dotBuf, colBuf, dirtyGen = {}, {}, {}
  69. local dirtyIdx = {}
  70. local dirtyCount = 0
  71. local globalDirtyGen = 1
  72.  
  73. for i = 1, totalPixels do
  74.   dotBuf[i], colBuf[i], dirtyGen[i] = 0, 0, 0
  75. end
  76.  
  77. local tw, th, tp, tc = tex.w, tex.h, tex.p, tex.c
  78. local tw_v, th_v = tw - 1, th - 1
  79. local dotMap = {0x1, 0x8, 0x2, 0x10, 0x4, 0x20, 0x40, 0x80}
  80. local pX, pY, pU, pV = {}, {}, {}, {}
  81.  
  82. -- --- GPU BATCHING ---
  83. local gBX, gBY, gBT = {}, {}, {}
  84. local bSize, bFG = 0, -1
  85.  
  86. local function flushBatch()
  87.   if bSize > 0 then
  88.     if bFG ~= -1 then gSetFG(bFG) end
  89.     for i = 1, bSize do gSet(gBX[i], gBY[i], gBT[i]) end
  90.     bSize, bFG = 0, -1
  91.   end
  92. end
  93.  
  94. local function addToBatch(x, y, text, fg)
  95.   if fg and fg ~= bFG then flushBatch(); bFG = fg end
  96.   bSize = bSize + 1
  97.   gBX[bSize], gBY[bSize], gBT[bSize] = x, y, text
  98. end
  99.  
  100. local function fillTriangle(i1, i2, i3)
  101.   local y1, y2, y3 = pY[i1], pY[i2], pY[i3]
  102.   if y1 > y2 then i1, i2 = i2, i1; y1, y2 = pY[i1], pY[i2] end
  103.   if y1 > y3 then i1, i3 = i3, i1; y1, y3 = pY[i1], pY[i3] end
  104.   if y2 > y3 then i2, i3 = i3, i2; y2, y3 = pY[i2], pY[i3] end
  105.   local dy13 = y3 - y1
  106.   if dy13 <= 0 then return end
  107.   local invDy13 = 1 / dy13
  108.   for y = max(0, ceil(y1)), min(vH - 1, floor(y3)) do
  109.     local t = (y - y1) * invDy13
  110.     local xA, uA, vA = pX[i1]+(pX[i3]-pX[i1])*t, pU[i1]+(pU[i3]-pU[i1])*t, pV[i1]+(pV[i3]-pV[i1])*t
  111.     local xB, uB, vB
  112.     if y < y2 then
  113.       local d = y2 - y1
  114.       local t2 = d > 0 and (y - y1) / d or 0
  115.       xB, uB, vB = pX[i1]+(pX[i2]-pX[i1])*t2, pU[i1]+(pU[i2]-pU[i1])*t2, pV[i1]+(pV[i2]-pV[i1])*t2
  116.     else
  117.       local d = y3 - y2
  118.       local t2 = d > 0 and (y - y2) / d or 0
  119.       xB, uB, vB = pX[i2]+(pX[i3]-pX[i2])*t2, pU[i2]+(pU[i3]-pU[i2])*t2, pV[i2]+(pV[i3]-pV[i2])*t2
  120.     end
  121.     if xA > xB then xA, xB, uA, uB, vA, vB = xB, xA, uB, uA, vB, vA end
  122.     local sX, eX = max(0, ceil(xA)), min(vW - 1, floor(xB))
  123.     local dx = xB - xA
  124.     if dx > 0 then
  125.       local invDx = 1 / dx
  126.       local du, dv = (uB - uA) * invDx, (vB - vA) * invDx
  127.       local cu, cv = uA + (sX - xA) * du, vA + (sX - xA) * dv
  128.       local sYOff = rowOffsets[y]
  129.       local rBase = rowOffBase[y]
  130.       for x = sX, eX do
  131.         local tx = floor(max(0, min(1, cu)) * tw_v)
  132.         local ty = floor(max(0, min(1, cv)) * th_v)
  133.         local tIdx = ty * tw + tx + 1
  134.         if tp[tIdx] then
  135.           local idx = sYOff + halfXFloor[x] + 1
  136.           if dirtyGen[idx] ~= globalDirtyGen then
  137.             dirtyGen[idx] = globalDirtyGen
  138.             dirtyCount = dirtyCount + 1
  139.             dirtyIdx[dirtyCount] = idx
  140.           end
  141.           dotBuf[idx] = bOr(dotBuf[idx], dotMap[rBase + xModMap[x]])
  142.           colBuf[idx] = tc[tIdx]
  143.         end
  144.         cu, cv = cu + du, cv + dv
  145.       end
  146.     end
  147.   end
  148. end
  149.  
  150. -- --- MESH DATA ---
  151. local vertices = {{-1,-1,1},{1,-1,1},{1,1,1},{-1,1,1},{-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1}}
  152. local faces = {
  153.   {{1,0,0},{2,1,0},{3,1,1},{4,0,1}},{{6,0,0},{5,1,0},{8,1,1},{7,0,1}},
  154.   {{5,0,0},{6,1,0},{2,1,1},{1,0,1}},{{3,0,0},{7,1,0},{8,1,1},{4,0,1}},
  155.   {{5,0,0},{1,1,0},{4,1,1},{8,0,1}},{{2,0,0},{6,1,0},{7,1,1},{3,0,1}}
  156. }
  157. local rotated = {}
  158. for i = 1, 8 do rotated[i] = {0, 0} end
  159.  
  160. -- --- MAIN RENDER LOGIC ---
  161. local function main()
  162.   local aX, aY = 0, 0
  163.   local runBuf = {}
  164.   local lastTime = computer.uptime()
  165.   local fps = 0
  166.  
  167.   while true do
  168.     if event.pull(0) == "interrupted" then break end
  169.    
  170.     local startTime = computer.uptime()
  171.     fps = floor(1 / (startTime - lastTime))
  172.     lastTime = startTime
  173.  
  174.     gpu.setActiveBuffer(backBuffer)
  175.     gpu.setBackground(0x000000)
  176.     gpu.fill(1, 1, screenW, screenH, " ")
  177.    
  178.     local cX, sX, cY, sY = math_cos(aX), math_sin(aX), math_cos(aY), math_sin(aY)
  179.     for i = 1, 8 do
  180.       local v = vertices[i]
  181.       local y1, z1 = v[2]*cX - v[3]*sX, v[2]*sX + v[3]*cX
  182.       local x1 = v[1]*cY + z1*sY
  183.       rotated[i][1], rotated[i][2] = (x1*scale)+(vW/2), (y1*scale)+(vH/2)
  184.     end
  185.    
  186.     for i = 1, 6 do
  187.       local f = faces[i]
  188.       for j = 1, 4 do
  189.         local rV = rotated[f[j][1]]
  190.         pX[j], pY[j], pU[j], pV[j] = rV[1], rV[2], f[j][2], f[j][3]
  191.       end
  192.       if ((pX[2]-pX[1])*(pY[3]-pY[1]) - (pY[2]-pY[1])*(pX[3]-pX[1])) > 0 then
  193.         fillTriangle(1, 2, 3)
  194.         fillTriangle(1, 3, 4)
  195.       end
  196.     end
  197.    
  198.     for y = 0, screenH - 1 do
  199.       local lineIdx, x = y * screenW, 0
  200.       while x < screenW do
  201.         local idx = lineIdx + x + 1
  202.         if dotBuf[idx] ~= 0 then
  203.           local c, len = colBuf[idx], 0
  204.           while x < screenW and dotBuf[lineIdx+x+1] ~= 0 and colBuf[lineIdx+x+1] == c do
  205.             len = len + 1
  206.             runBuf[len] = charCache[dotBuf[lineIdx+x+1]]
  207.             x = x + 1
  208.           end
  209.           addToBatch(x-len+1, y+1, tConcat(runBuf, "", 1, len), c)
  210.         else
  211.           x = x + 1
  212.         end
  213.       end
  214.     end
  215.    
  216.     -- Draw FPS Counter at Bottom-Left
  217.     flushBatch()
  218.     gSetFG(0x00FF00)
  219.     gSet(1, screenH, "FPS: " .. fps .. "  ")
  220.    
  221.     gpu.bitblt(0, 1, 1, screenW, screenH, backBuffer, 1, 1)
  222.    
  223.     for i = 1, dirtyCount do dotBuf[dirtyIdx[i]] = 0 end
  224.     dirtyCount = 0
  225.     globalDirtyGen = (globalDirtyGen + 1) % 65535
  226.     aX, aY = aX + 0.12, aY + 0.08
  227.   end
  228. end
  229.  
  230. -- --- EXECUTION WRAPPER ---
  231. local status, err = xpcall(main, debug.traceback)
  232.  
  233. -- Cleanup: Always restore screen and free GPU memory
  234. gpu.setActiveBuffer(0)
  235. gpu.freeBuffer(backBuffer)
  236. gpu.setBackground(0x000000)
  237. gpu.setForeground(0xFFFFFF)
  238. gpu.fill(1, 1, screenW, screenH, " ")
  239.  
  240. if not status and err ~= "interrupted" then
  241.   print("Error: " .. tostring(err))
  242. end
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • Locimdo
    15 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=vpkhbfllig
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment