Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Custom colorizer: Sine wave gradient with desaturation on \k event
- VSFilterMod v1.1 lua example
- Ass tag: {\blur5\fs40\hsvgrad(0,1)\t(\hsvgrad(1,0))\kf500}Custom colorizer
- ]]
- require("karalib_color")
- require("drawing")
- function init()
- end
- function hsvgradient(line, rend)
- local x, y
- local cx = line.width / 2
- local cy = line.height / 2
- for x = 0, line.width - 1 do
- for y = 0, line.height - 1 do
- local c
- if(line.layer == 1)then
- local t = math.cos(math.pi * (x / line.width + line.user.time / line.user.length))
- c = color.create_hsv(t,1,1)
- local dist = math.abs(x - line.gran)
- if(x < line.gran)then
- if(dist < 50)then
- c:desaturate(1 - dist / 50)
- end
- else
- c:desaturate(1)
- end
- c = c:get_color()
- else
- c = line.c1
- end
- rend:mix(x, y, c, 0xff)
- end
- end
- end
- -- animable through \t
- function hsvgrad(line,a,b)
- a = tonumber(a)
- b = tonumber(b)
- local r = {}
- r.renderer = "hsvgradient"
- if(line.animate == nul) then
- -- Save start coordinates
- r.user = line.user
- if(r.user == nul) then r.user = {time=line.time, length=line.length} end
- r.user.hsvgrad = { a = a, b = b }
- else
- assert(type(line.user)=="table", "hsvgrad(line,a,b): no valid argument 'line.user'")
- local t = line.animate
- r.user = line.user
- if(r.user.hsvgrad == nul) then r.user.hsvgrad = {a = 0, b = 0 } end
- r.user.hsvgrad.a = a * t + r.user.hsvgrad.a * (1 - t)
- r.user.hsvgrad.b = b * t + r.user.hsvgrad.b * (1 - t)
- end
- return r
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement