Pandana

form.lua

Sep 7th, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. f = {}
  2. f[1] = 1
  3. f[2] = 1
  4. f[3] = 1
  5. f[9] = 1
  6. f[4] = 2
  7. f[11] = 2
  8. f[18] = 2
  9. f[19] = 2
  10. f[5] = 3
  11. f[12] = 3
  12. f[6] = 4
  13. f[7] = 4
  14. f[13] = 4
  15. f[14] = 4
  16. f[8] = 5
  17. f[15] = 5
  18. f[16] = 5
  19. f[23] = 5
  20. f[22] = 6
  21. f[29] = 6
  22. f[30] = 6
  23. f[10] = 7
  24. f[17] = 7
  25. f[24] = 7
  26. f[31] = 7
  27. f[25] = 8
  28. f[32] = 8
  29. f[20] = 9
  30. f[26] = 9
  31. f[27] = 9
  32. f[33] = 9
  33. f[21] = 10
  34. f[28] = 10
  35. f[34] = 10
  36. f[35] = 10
  37.  
  38. g = {}
  39.  
  40. g[1] = {colors.red, false}
  41. g[2] = {colors.lime, false}
  42. g[3] = {colors.orange, false}
  43. g[4] = {colors.blue, false}
  44. g[5] = {colors.brown, false}
  45. g[6] = {colors.magenta, false}
  46. g[7] = {colors.pink, false}
  47. g[8] = {colors.lightBlue, false}
  48. g[9] = {colors.green, false}
  49. g[10] = {colors.cyan, false}
  50.  
  51. sol = {false, true, false, false, true, false, false, false, false, true}
  52. sol[1] = false
  53. sol[2] = true
  54. sol[3] = false
  55. sol[4] = false
  56. sol[5] = true
  57. sol[6] = false
  58. sol[7] = false
  59. sol[8] = false
  60. sol[9] = false
  61. sol[10] = true
  62.  
  63. function pixel2coord(pixel)
  64.     pixel = pixel-1
  65.     y = math.floor(pixel / 7)
  66.     x = pixel % 7
  67.     return x+1, y+1
  68. end
  69.  
  70. function coord2pixel(x, y)
  71.     x = x-1
  72.     y = y-1
  73.     pixel = y * 7 + x
  74.     return pixel+1
  75. end
  76.  
  77. function hitAllPoints(pixel)
  78.     for i=1, 35, 1 do
  79.         if f[i] == f[pixel] then
  80.             x,y = pixel2coord(i)
  81.             if g[f[i]][2] then
  82.                 paintutils.drawPixel(x,y,colors.white)
  83.             else
  84.                 paintutils.drawPixel(x,y,g[f[i]][1])
  85.             end
  86.         end
  87.     end
  88.     g[f[pixel]][2] = not g[f[pixel]][2]
  89. end
  90.  
  91. function touched(x, y)
  92.     pixel = coord2pixel(x,y)
  93.     hitAllPoints(pixel)
  94. end
  95.  
  96. function checkSolution()
  97.     return not (g[1][2] or g[3][2] or g[4][2] or g[6][2] or g[7][2] or g[8][2] or g[9][2]) and g[2][2] and g[5][2] and g[10][2]
  98. end
  99.  
  100. term.setBackgroundColor(colors.white)
  101. term.clear()
  102.  
  103. while true do
  104.     local event, side, x, y = os.pullEvent("monitor_touch")
  105.     touched(x, y)
  106.     if checkSolution() then
  107.         redstone.setOutput("back", true)
  108.     else
  109.         redstone.setOutput("back", false)
  110.     end
  111. end
Add Comment
Please, Sign In to add comment