Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. require "/tech/doubletap.lua"
  2.  
  3. function init()
  4.   storage.rainbowCounter = 0
  5.   self.color1 = 0x95d14f
  6.   self.color2 = 0x50b754
  7.   self.color3 = 0x00a192
  8. end
  9.  
  10. function transition(color1, color2, position)
  11.         local r1 = color1 / 65536
  12.         r1 = r1 - r1 % 1
  13.         local g1 = (color1 - r1 * 65536) / 256
  14.         g1 = g1 - g1 % 1
  15.         local b1 = color1 - r1 * 65536 - g1 * 256
  16.  
  17.         local r2 = color2 / 65536
  18.         r2 = r2 - r2 % 1
  19.         local g2 = (color2 - r2 * 65536) / 256
  20.         g2 = g2 - g2 % 1
  21.  
  22.         local r, g, b =
  23.           r1 + (r2 - r1) * position,
  24.           g1 + (g2 - g1) * position,
  25.           b1 + (color2 - r2 * 65536 - g2 * 256 - b1) * position
  26.  
  27.         return
  28.           (r - r % 1) * 65536 +
  29.           (g - g % 1) * 256 +
  30.           (b - b % 1)
  31.       end
  32.  
  33. function uninit()  
  34.   tech.setParentDirectives()
  35. end
  36.  
  37. function update(args)
  38.   storage.rainbowCounter = storage.rainbowCounter + 1
  39.   if storage.rainbowCounter >= 300 then
  40.     storage.rainbowCounter = 0
  41.   end
  42.  
  43.   if storage.rainbowCounter <= 100 then
  44.     tech.setParentDirectives(string.format("?setcolor=%x", transition(color1,color2,(storage.rainbowCounter)/100)) .. "ff")
  45.   elseif storage.rainbowCounter <= 200 then
  46.     tech.setParentDirectives(string.format("?setcolor=%x", transition(color2,color3,(storage.rainbowCounter-200)/100)) .. "ff")
  47.   elseif storage.rainbowCounter <=300 then
  48.     tech.setParentDirectives(string.format("?setcolor=%x", transition(color3,color1,(storage.rainbowCounter-300)/100)) .. "ff")
  49.   end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement