Advertisement
nonogamer9

OCDonut: donut.c opencomputers port

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