Advertisement
teplofizik

colorizer_hsgd.lua

Aug 22nd, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. --[[
  2. Custom colorizer: Sine wave gradient with desaturation on \k event
  3. VSFilterMod v1.1 lua example
  4.  
  5. Ass tag: {\blur5\fs40\hsvgrad(0,1)\t(\hsvgrad(1,0))\kf500}Custom colorizer
  6. ]]
  7. require("karalib_color")
  8. require("drawing")
  9.  
  10. function init()
  11.  
  12. end
  13.  
  14. function hsvgradient(line, rend)
  15. local x, y
  16. local cx = line.width / 2
  17. local cy = line.height / 2
  18.  
  19. for x = 0, line.width - 1 do
  20. for y = 0, line.height - 1 do
  21. local c
  22. if(line.layer == 1)then
  23. local t = math.cos(math.pi * (x / line.width + line.user.time / line.user.length))
  24. c = color.create_hsv(t,1,1)
  25.  
  26. local dist = math.abs(x - line.gran)
  27.  
  28. if(x < line.gran)then
  29. if(dist < 50)then
  30. c:desaturate(1 - dist / 50)
  31. end
  32. else
  33. c:desaturate(1)
  34. end
  35.  
  36.  
  37. c = c:get_color()
  38. else
  39. c = line.c1
  40. end
  41.  
  42. rend:mix(x, y, c, 0xff)
  43. end
  44. end
  45. end
  46.  
  47. -- animable through \t
  48. function hsvgrad(line,a,b)
  49. a = tonumber(a)
  50. b = tonumber(b)
  51. local r = {}
  52. r.renderer = "hsvgradient"
  53. if(line.animate == nul) then
  54. -- Save start coordinates
  55. r.user = line.user
  56. if(r.user == nul) then r.user = {time=line.time, length=line.length} end
  57. r.user.hsvgrad = { a = a, b = b }
  58. else
  59. assert(type(line.user)=="table", "hsvgrad(line,a,b): no valid argument 'line.user'")
  60. local t = line.animate
  61.  
  62. r.user = line.user
  63. if(r.user.hsvgrad == nul) then r.user.hsvgrad = {a = 0, b = 0 } end
  64.  
  65. r.user.hsvgrad.a = a * t + r.user.hsvgrad.a * (1 - t)
  66. r.user.hsvgrad.b = b * t + r.user.hsvgrad.b * (1 - t)
  67. end
  68.  
  69. return r
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement