Skip to content

Instantly share code, notes, and snippets.

@MikuAuahDark
Created April 26, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikuAuahDark/46bfde9e9357c5bbc362adba6677aa0f to your computer and use it in GitHub Desktop.
Save MikuAuahDark/46bfde9e9357c5bbc362adba6677aa0f to your computer and use it in GitHub Desktop.
Rainmeter Circle Visualizer
-- Visualizer builder script
-- Copyright (c) 2018 MikuAuahDark
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
-- 3. This notice may not be removed or altered from any source distribution.
-- Modify if necessary
local config = {
FFT_SIZE = 1024,
FFT_ATTACK = 16,
FFT_DECAY = 175,
BANDS = 30,
BAND_BAR_SIZE = 8,
BAND_BAR_LENGTH = 200,
BAND_BAR_MARGIN = -1, -- Both sides
BAND_COLOR = "0,0,0,255"
}
-- Stop editing below this line
local visIni = [[
; Automatically generated by makevis.lua script.
[Rainmeter]
Update=16
SkinWidth=#R
SkinHeight=#R
BackgroundMode=2
SolidColor=0,0,0,1
[Metadata]
Name=CircleVisualizer
Author=MikuAuahDark
Information=Visualizer, but in circle. | This skin is generated by makevis.lua script!
Version=1.0
License=zLib license (skin generator code)
[Variables]
AmountOfBands=${BANDS}
[VisAudioLevelBase]
Measure=Plugin
Plugin=AudioLevel
FFTSize=${FFT_SIZE}
FFTAttack=${FFT_ATTACK}
FFTDecay=${FFT_DECAY}
Bands=${BANDS}
]]
-- ## indicates current loop number(`i`)
local visIniBandCreateTemplate = [[
[VisBand##]
Measure=Plugin
Plugin=AudioLevel
Parent=VisAudioLevelBase
Type=Band
BandIdx=##
[VisBand##Meter]
Meter=Bar
MeasureName=VisBand##
AntiAlias=1
BarColor=${BAND_COLOR}
SolidColor=0,0,0,0
BarOrientation=Horizontal
X=#X
Y=#Y
W=${BAND_BAR_LENGTH}
H=${BAND_BAR_SIZE}
TransformationMatrix=#T
]]
local function mat3id()
return {
1, 0, 0,
0, 1, 0,
0, 0, 1
}
end
local function mat3af(tm)
return {
tm[1], tm[2], tm[5],
tm[3], tm[4], tm[6],
0, 0, 1,
}
end
local function mat3mul(m1, m2)
local mc = {
nil, nil, nil,
nil, nil, nil,
nil, nil, nil
}
for i = 0, 8 do
local x = math.floor(i / 3) * 3
mc[i + 1] = m1[x + 1] * m2[(i % 3) + 1] +
m1[x + 2] * m2[(i % 3) + 4] +
m1[x + 3] * m2[(i % 3) + 7]
end
return mc
end
local function mat3t(x, y)
return {1, 0, x, 0, 1, y, 0, 0, 1}
end
local function mat3r(r)
local x, y = math.cos(r), math.sin(r)
return {x, -y, 0, y, x, 0, 0, 0, 1}
end
local function configReplace(name)
return config[name]
end
-- Calculate the max skin dimensions.
local circleRadius = (config.BANDS * (config.BAND_BAR_SIZE + 2 * config.BAND_BAR_MARGIN)) / (2*math.pi)
local skinRadius = math.floor(circleRadius + config.BAND_BAR_LENGTH)
local skinString = {
(visIni:gsub("#R", skinRadius * 2):gsub("%${([A-Z_]+)}", configReplace):gsub("\r\n", "\n"))
}
-- Create band measure & bar meter
for i = 0, config.BANDS - 1 do
local rot = (i / config.BANDS) * 2*math.pi
local mat = mat3t(skinRadius, skinRadius)
mat = mat3mul(mat, mat3r(rot))
local meterString = visIniBandCreateTemplate
:gsub("\r\n", "\n")
:gsub("##", i)
:gsub("%${([A-Z_]+)}", configReplace)
:gsub("#C", config.BAND_COLOR)
:gsub("#X", circleRadius)
:gsub("#Y", config.BAND_BAR_SIZE * -0.5 - config.BAND_BAR_MARGIN)
:gsub("#T", string.format("%.5f; %.5f; %.5f; %.5f; %.5f; %.5f", mat[1], mat[2], mat[4], mat[5], mat[3], mat[6]))
skinString[#skinString + 1] = meterString
end
-- Write skin file.
local f = io.open("vis.ini", "w")
f:write(table.concat(skinString, "\n"))
f:close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment