Advertisement
Guest User

lua

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. local sqrt, sin, cos, min, max = math.sqrt, math.sin, math.cos, math.min, math.max
  2. local pi = math.pi
  3. local r1, r2 =  0          ,  1.0
  4. local g1, g2 = -sqrt( 3 )/2, -0.5
  5. local b1, b2 =  sqrt( 3 )/2, -0.5
  6.  
  7.  
  8. --[[--
  9.   @param h a real number between 0 and 2*pi
  10.   @param s a real number between 0 and 1
  11.   @param v a real number between 0 and 1
  12. ]]
  13. local function HSVToRGB( h, s, v, a )
  14.   h=h+pi/2--because the r vector is up
  15.   local r, g, b = 1, 1, 1
  16.   local h1, h2 = cos( h ), sin( h )
  17.  
  18.   --hue
  19.   r = h1*r1 + h2*r2
  20.   g = h1*g1 + h2*g2
  21.   b = h1*b1 + h2*b2
  22.   --saturation
  23.   r = r + (1-r)*s
  24.   g = g + (1-g)*s
  25.   b = b + (1-b)*s
  26.  
  27.   r,g,b = r*v, g*v, b*v
  28.  
  29.   return r*255, g*255, b*255, (a or 1) * 255
  30. end
  31.  
  32. leds = {"ac6767a7-ef2d-4d70-b75b-67df15ee9df3",
  33. "c42270e2-9c4a-4548-b31f-c52283f01d80",
  34. "7977b69d-eb8e-49fc-b516-d4c27e04503b",
  35. "2e495282-9f8a-4d6f-9a0f-4ce389ec9128",
  36. "0da594b9-9451-4403-ae4d-6280cb9dd554",
  37. "eccdcd3e-1762-49c9-b5b7-90e36379e389",
  38. "6ce9f65d-fcf9-4134-9b9b-aff4144ab756",
  39. "563f48b1-8535-4d40-bb9d-1fdd3e93d3cf",
  40. "819b3b65-6e08-435b-bf20-8553cd17cb10",
  41. "90bf44e6-3db2-46ac-8e33-7892e7ccd4d4",
  42. "9feddb9e-53b9-43de-9971-84e8f376e4ba",
  43. "6b2075a7-ee5d-4d86-9233-1ce475a7c99b",
  44. "87920cea-22ab-47cd-af45-0a29f2b2d740",
  45. "6e34479e-0c3d-4b75-9188-59deddcb622e",
  46. "12752ad0-5416-4a6a-a414-ddb2d8434539",
  47. "9022ba96-2c00-45d8-a243-46d434b894be",
  48. "b967ae48-b773-497b-99f4-419d65b47d63",
  49. "f8c5dea1-53cf-48a8-bbdd-a9e34e572496",
  50. "74459330-612e-4e87-bc8c-16cd23dab458",
  51. "0325ec1b-69dc-4dee-a982-1e70f94d05a2",
  52. "b6ea610f-399d-4fe1-85da-5ed91fdcba18",
  53. "8e09b263-bafa-4ab1-8229-77a829f84c16",
  54. "8b2ba438-396d-4e75-8565-ea8d5da5a5f3",
  55. "1797bd79-6fdc-4d9c-9cb3-9be89b6fca61",
  56. "e1998592-408f-4df0-b267-2ae1a514c9ff",
  57. "6728ff26-238b-4e83-abc9-c5d037bbfa9c",
  58. "870a7c9a-0a8d-4176-9b2a-5643e549810a",
  59. "51cec127-3bad-416d-8e9a-034dea471ff5",
  60. "c0185d2d-fad9-4841-a70d-076626816608",
  61. "3d3a50e8-0550-4225-ad26-726ed59f5a6c",
  62. "17164db8-7d98-43cf-a9c5-295b025da7b5",
  63. "ecb8f1a0-2f3e-46ed-90e7-49ac353fad2e",
  64. "d89797fc-4362-4852-a825-08ff614294ec",
  65. "81075c82-d61b-4dcb-b0d1-c1d74505702b",
  66. "c2d81f51-4b8d-44b2-a4af-d406d78c91dc",
  67. "ea473aaa-0bad-4a50-8b53-ea8b45b1052f",
  68. "857a0213-2f87-4c6a-820c-e36f9957f8a1",
  69. "5369c9e9-c962-46be-9bcd-ea1476cf5eb8",
  70. "14b75fa6-7f2b-4e08-9832-c7d83847d06b",
  71. "baf88cb5-4e77-4be1-a637-87de23bc852d"}
  72.  
  73. local component = require("component")
  74. local bit32 = require("bit32")
  75.  
  76. i = 0
  77. while true do
  78.   i = i + 1
  79.   if i == 320 then
  80.     i = 0
  81.   end
  82.   for b = 1,40 do
  83.     r,g,ba = HSVtoRGB(i + (b-1),1,1)
  84.     r = math.floor(r * 31)
  85.     g = math.floor(g * 31)
  86.     ba = math.floor(b * 31)
  87.     rgb = (bit32.lshift(r,10) + bit32.lshift(g,5) + ba)
  88.     local proxy = component.proxy(leds[b])
  89.     proxy.setLampColor(rgb)
  90.   end
  91.   os.sleep(10);
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement