Advertisement
nonogamer9

CCDonut: donut.c computercraft port

Jul 19th, 2024 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | Software | 0 0
  1. -- Donut.C Ported to computercraft by nonogamer9
  2. -- Original C Code By Andy Sloane
  3. local A = 0
  4. local B = 0
  5. local z = {}
  6. local b = {}
  7. local screenWidth, screenHeight = term.getSize()
  8.  
  9. local function getChar(N)
  10.     local chars = ".,-~:;=!*#$@"
  11.     return chars:sub(math.floor(math.max(N, 1)), math.floor(math.max(N, 1)))
  12. end
  13.  
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16.  
  17. while true do
  18.     -- Reset buffers
  19.     for i = 1, screenWidth * screenHeight do
  20.         b[i] = ' '
  21.         z[i] = 0
  22.     end
  23.  
  24.     for j = 0, 6.28, 0.07 do
  25.         for i = 0, 6.28, 0.02 do
  26.             local sini = math.sin(i)
  27.             local cosj = math.cos(j)
  28.             local sinA = math.sin(A)
  29.             local sinj = math.sin(j)
  30.             local cosA = math.cos(A)
  31.             local cosj2 = cosj + 2
  32.             local mess = 1 / (sini * cosj2 * sinA + sinj * cosA + 5)
  33.             local cosi = math.cos(i)
  34.             local cosB = math.cos(B)
  35.             local sinB = math.sin(B)
  36.             local t = sini * cosj2 * cosA - sinj * sinA
  37.            
  38.             local x = math.floor(40 + 30 * mess * (cosi * cosj2 * cosB - t * sinB))
  39.             local y = math.floor(12 + 15 * mess * (cosi * cosj2 * sinB + t * cosB))
  40.             local o = x + screenWidth * y
  41.             local N = 8 * ((sinj * sinA - sini * cosj * cosA) * cosB - sini * cosj * sinA - sinj * cosA - cosi * cosj * sinB)
  42.  
  43.             if y > 0 and y < screenHeight and x > 0 and x < screenWidth and mess > z[o] then
  44.                 z[o] = mess
  45.                 b[o] = getChar(N + 1)
  46.             end
  47.         end
  48.     end
  49.  
  50.     term.setCursorPos(1, 1)
  51.     for k = 1, screenWidth * screenHeight do
  52.         term.write(b[k])
  53.         if k % screenWidth == 0 then
  54.             term.setCursorPos(1, k / screenWidth + 1)
  55.         end
  56.     end
  57.  
  58.     A = A + 0.08
  59.     B = B + 0.06
  60.  
  61.     os.sleep(0.03)
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement