Advertisement
Guest User

Untitled

a guest
Aug 5th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1.  
  2. local gpu = require("component").gpu
  3.  
  4. local str = "123456"
  5. local strLen = nil --если str содержит русские символы написать длину сюда
  6.  
  7. local x, y = 1, 1
  8. local leng = strLen or string.len(str)
  9. local isRight, isUp = false, false
  10. local w, h = gpu.getResolution()
  11.  
  12. local function moveToXY()
  13.   repeat
  14.     gpu.fill(1, 1, w, h, " ")
  15.     gpu.set(x, y, str)
  16.     x, y = x + 1, y + 1
  17.     if y == h + 1 then
  18.       x = x - 1
  19.       y = h
  20.       isUp = false
  21.       if isRight then
  22.         return 3
  23.       else
  24.         return 4
  25.       end
  26.     end
  27.     os.sleep(0.05)
  28.   until x >= w - leng - 1
  29.   isRight = true
  30.   if isUp then
  31.     return 2
  32.   else
  33.     return 3
  34.   end
  35. end
  36.  
  37. local function moveToMXY()
  38.   repeat
  39.     gpu.fill(1, 1, w, h, " ")
  40.     gpu.set(x, y, str)
  41.     x, y = x - 1, y + 1
  42.     if y == h + 1 then
  43.       x = x + 1
  44.       y = h
  45.       isUp = false
  46.       if isRight then
  47.         return 3
  48.       else
  49.         return 4
  50.       end
  51.     end
  52.     os.sleep(0.05)
  53.   until x <= 1
  54.   isRight = false
  55.   if isUp then
  56.     return 1
  57.   else
  58.     return 4
  59.   end
  60. end
  61.  
  62. local function moveToXMY()
  63.     repeat
  64.     gpu.fill(1, 1, w, h, " ")
  65.     gpu.set(x, y, str)
  66.     x, y = x + 1, y - 1
  67.     if y == 0 then
  68.       x = x - 1
  69.       y = 1
  70.       isUp = true
  71.       if isRight then
  72.         return 2
  73.       else
  74.         return 1
  75.       end
  76.     end
  77.     os.sleep(0.05)
  78.   until x >= w - leng  - 1
  79.   isRight = true
  80.   if isUp then
  81.     return 2
  82.   else
  83.     return 3
  84.   end
  85. end
  86.  
  87. local function moveToMXMY()
  88.   repeat
  89.     gpu.fill(1, 1, w, h, " ")
  90.     gpu.set(x, y, str)
  91.     x, y = x - 1, y - 1
  92.     if y == 0 then
  93.       x = x + 1
  94.       y = 1
  95.       isUp = true
  96.       if isRight then
  97.         return 2
  98.       else
  99.         return 1
  100.       end
  101.     end
  102.     os.sleep(0.05)
  103.   until x <= 1
  104.   isRight = false
  105.   return 4
  106. end
  107.  
  108. local fun = {
  109. [1] = moveToXY,
  110. [2] = moveToMXY,
  111. [3] = moveToMXMY,
  112. [4] = moveToXMY
  113. }
  114.  
  115. gpu.fill(1, 1, w, h, " ")
  116. local result = moveToXY()
  117. while true do
  118.   result = fun[result]()
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement