Lupino

torus.lua

Jun 13th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.26 KB | None | 0 0
  1. local robot = require("robot")
  2. local slot = 1
  3.  
  4. image1 = {
  5.     "00000000000000000000000000000000",
  6.     "00000000000000000000000000000000",
  7.     "00000000000000000000000000000000",
  8.     "00000000000000000000000000000000",
  9.     "00000000000011111111000000000000",
  10.     "00000000001111111111110000000000",
  11.     "00000000111111111111111100000000",
  12.     "00000001111111111111111110000000",
  13.     "00000011111111000011111111000000",
  14.     "00000011111100000000111111000000",
  15.     "00000111111000000000011111100000",
  16.     "00000111110000000000001111100000",
  17.     "00001111100000000000000111110000",
  18.     "00001111100000000000000111110000",
  19.     "00001111000000000000000011110000",
  20.     "00001111000000000000000011110000",
  21.     "00001111000000000000000011110000",
  22.     "00001111000000000000000011110000",
  23.     "00001111100000000000000111110000",
  24.     "00001111100000000000000111110000",
  25.     "00000111110000000000001111100000",
  26.     "00000111111000000000011111100000",
  27.     "00000011111100000000111111000000",
  28.     "00000011111111000011111111000000",
  29.     "00000001111111111111111110000000",
  30.     "00000000111111111111111100000000",
  31.     "00000000001111111111110000000000",
  32.     "00000000000011111111000000000000",
  33.     "00000000000000000000000000000000",
  34.     "00000000000000000000000000000000",
  35.     "00000000000000000000000000000000",
  36.     "00000000000000000000000000000000"
  37. }
  38.  
  39. image2 = {
  40.     "00000000000000000000000000000000",
  41.     "00000000000000000000000000000000",
  42.     "00000000000011111111000000000000",
  43.     "00000000001111111111110000000000",
  44.     "00000000111100000000111100000000",
  45.     "00000001110000000000001110000000",
  46.     "00000011000000000000000011000000",
  47.     "00000110000000000000000001100000",
  48.     "00001100000000111100000000110000",
  49.     "00001100000011111111000000110000",
  50.     "00011000000111000011100000011000",
  51.     "00011000001100000000110000011000",
  52.     "00110000011000000000011000001100",
  53.     "00110000011000000000011000001100",
  54.     "00110000110000000000001100001100",
  55.     "00110000110000000000001100001100",
  56.     "00110000110000000000001100001100",
  57.     "00110000110000000000001100001100",
  58.     "00110000011000000000011000001100",
  59.     "00110000011000000000011000001100",
  60.     "00011000001100000000110000011000",
  61.     "00011000000111000011100000011000",
  62.     "00001100000011111111000000110000",
  63.     "00001100000000111100000000110000",
  64.     "00000110000000000000000001100000",
  65.     "00000011000000000000000011000000",
  66.     "00000001110000000000001110000000",
  67.     "00000000111100000000111100000000",
  68.     "00000000001111111111110000000000",
  69.     "00000000000011111111000000000000",
  70.     "00000000000000000000000000000000",
  71.     "00000000000000000000000000000000"
  72. }
  73.  
  74. image3 = {
  75.     "00000000000000000000000000000000",
  76.     "00000000000001111110000000000000",
  77.     "00000000001110000001110000000000",
  78.     "00000000110000000000001100000000",
  79.     "00000001000000000000000010000000",
  80.     "00000110000000000000000001100000",
  81.     "00000100000000000000000000100000",
  82.     "00001000000000000000000000010000",
  83.     "00010000000000000000000000001000",
  84.     "00010000000000000000000000001000",
  85.     "00100000000000111100000000000100",
  86.     "00100000000011000011000000000100",
  87.     "00100000000100000000100000000100",
  88.     "01000000000100000000100000000010",
  89.     "01000000001000000000010000000010",
  90.     "01000000001000000000010000000010",
  91.     "01000000001000000000010000000010",
  92.     "01000000001000000000010000000010",
  93.     "01000000000100000000100000000010",
  94.     "00100000000100000000100000000100",
  95.     "00100000000011000011000000000100",
  96.     "00100000000000111100000000000100",
  97.     "00010000000000000000000000001000",
  98.     "00010000000000000000000000001000",
  99.     "00001000000000000000000000010000",
  100.     "00000100000000000000000000100000",
  101.     "00000110000000000000000001100000",
  102.     "00000001000000000000000010000000",
  103.     "00000000110000000000001100000000",
  104.     "00000000001110000001110000000000",
  105.     "00000000000001111110000000000000",
  106.     "00000000000000000000000000000000"
  107. }
  108.  
  109. image4 = {
  110.     "00000000000000000000000000000000",
  111.     "00000000000111111111100000000000",
  112.     "00000000011000000000011000000000",
  113.     "00000001100000000000000110000000",
  114.     "00000010000000000000000001000000",
  115.     "00000100000000000000000000100000",
  116.     "00001000000000000000000000010000",
  117.     "00010000000000000000000000001000",
  118.     "00010000000000000000000000001000",
  119.     "00100000000000000000000000000100",
  120.     "00100000000000011000000000000100",
  121.     "01000000000001100110000000000010",
  122.     "01000000000010000001000000000010",
  123.     "01000000000100000000100000000010",
  124.     "01000000000100000000100000000010",
  125.     "01000000001000000000010000000010",
  126.     "01000000001000000000010000000010",
  127.     "01000000000100000000100000000010",
  128.     "01000000000100000000100000000010",
  129.     "01000000000010000001000000000010",
  130.     "01000000000001100110000000000010",
  131.     "00100000000000011000000000000100",
  132.     "00100000000000000000000000000100",
  133.     "00010000000000000000000000001000",
  134.     "00010000000000000000000000001000",
  135.     "00001000000000000000000000010000",
  136.     "00000100000000000000000000100000",
  137.     "00000010000000000000000001000000",
  138.     "00000001100000000000000110000000",
  139.     "00000000011000000000011000000000",
  140.     "00000000000111111111100000000000",
  141.     "00000000000000000000000000000000"
  142. }
  143.  
  144. image5 = {
  145.     "00000000000001111110000000000000",
  146.     "00000000001110000001110000000000",
  147.     "00000000110000000000001100000000",
  148.     "00000011000000000000000011000000",
  149.     "00000100000000000000000000100000",
  150.     "00001000000000000000000000010000",
  151.     "00010000000000000000000000001000",
  152.     "00010000000000000000000000001000",
  153.     "00100000000000000000000000000100",
  154.     "00100000000000000000000000000100",
  155.     "01000000000000000000000000000010",
  156.     "01000000000000111100000000000010",
  157.     "01000000000001000010000000000010",
  158.     "10000000000010000001000000000001",
  159.     "10000000000100000000100000000001",
  160.     "10000000000100000000100000000001",
  161.     "10000000000100000000100000000001",
  162.     "10000000000100000000100000000001",
  163.     "10000000000010000001000000000001",
  164.     "01000000000001000010000000000010",
  165.     "01000000000000111100000000000010",
  166.     "01000000000000000000000000000010",
  167.     "00100000000000000000000000000100",
  168.     "00100000000000000000000000000100",
  169.     "00010000000000000000000000001000",
  170.     "00010000000000000000000000001000",
  171.     "00001000000000000000000000010000",
  172.     "00000100000000000000000000100000",
  173.     "00000011000000000000000011000000",
  174.     "00000000110000000000001100000000",
  175.     "00000000001110000001110000000000",
  176.     "00000000000001111110000000000000"
  177. }
  178.  
  179. image6 = {
  180.     "00000000000011111111000000000000",
  181.     "00000000011100000000111000000000",
  182.     "00000001100000000000000110000000",
  183.     "00000010000000000000000001000000",
  184.     "00000100000000000000000000100000",
  185.     "00001000000000000000000000010000",
  186.     "00010000000000000000000000001000",
  187.     "00100000000000000000000000000100",
  188.     "00100000000000000000000000000100",
  189.     "01000000000000000000000000000010",
  190.     "01000000000000000000000000000010",
  191.     "01000000000000111100000000000010",
  192.     "10000000000001000010000000000001",
  193.     "10000000000010000001000000000001",
  194.     "10000000000100000000100000000001",
  195.     "10000000000100000000100000000001",
  196.     "10000000000100000000100000000001",
  197.     "10000000000100000000100000000001",
  198.     "10000000000010000001000000000001",
  199.     "10000000000001000010000000000001",
  200.     "01000000000000111100000000000010",
  201.     "01000000000000000000000000000010",
  202.     "01000000000000000000000000000010",
  203.     "00100000000000000000000000000100",
  204.     "00100000000000000000000000000100",
  205.     "00010000000000000000000000001000",
  206.     "00001000000000000000000000010000",
  207.     "00000100000000000000000000100000",
  208.     "00000010000000000000000001000000",
  209.     "00000001100000000000000110000000",
  210.     "00000000011100000000111000000000",
  211.     "00000000000011111111000000000000"
  212. }
  213.  
  214. local torus = {image1, image2, image3, image4, image5, image6, image6, image5, image4, image3, image2, image1}
  215.  
  216. function up()
  217.     local can, type = robot.detectUp()
  218.     if (can)
  219.     then
  220.         robot.swingUp()
  221.     end
  222.     robot.up()
  223. end
  224.  
  225. function forward()
  226.     local can, type = robot.detect()
  227.     if (can)
  228.     then
  229.         robot.swing()
  230.     end
  231.     robot.forward()
  232. end
  233.  
  234. function checkSlot()
  235.     local count = robot.count(slot)
  236.     if (count == 0) then
  237.         slot = slot + 1
  238.         checkSlot()
  239.     end
  240.     robot.select(slot)
  241. end
  242.  
  243. function placeDown()
  244.     local can, type = robot.detectDown()
  245.     if (can)
  246.     then
  247.         robot.swingDown()
  248.     end
  249.     checkSlot()
  250.     robot.placeDown()
  251. end
  252.  
  253. function placeLayer (layer)
  254.     for i = 1,32,1 do
  255.         line = layer[i]
  256.         for j = 1,32,1 do
  257.             forward()
  258.             byte = string.byte(line, j)
  259.             if (byte == 49) then
  260.                 placeDown()
  261.             end
  262.         end
  263.         forward()
  264.         if (i % 2 == 0) then
  265.             robot.turnRight()
  266.         else
  267.             robot.turnLeft()
  268.         end
  269.         forward()
  270.         if (i % 2 == 0) then
  271.             robot.turnRight()
  272.         else
  273.             robot.turnLeft()
  274.         end
  275.     end
  276.     robot.turnRight()
  277.     for i = 1, 32, 1 do
  278.         forward()
  279.     end
  280.     robot.turnLeft()
  281. end
  282.  
  283. for i = 1, 12, 1 do
  284.     local layer = torus[i]
  285.     placeLayer(layer)
  286.     up()
  287. end
Advertisement
Add Comment
Please, Sign In to add comment