jarcode-foss / glava

GLava - OpenGL audio spectrum visualizer
GNU General Public License v3.0
1.18k stars 59 forks source link

2 colors at each bar? #222

Closed scorpium959 closed 2 years ago

scorpium959 commented 2 years ago

i changed the color of the bars, from that i had an idea, can i put 2 colors in the bar? Like: Captura de pantalla de 2022-01-04 16-45-56 the part more taller have a color and it changes until reaching the base which will be purple maybe, the thing is to make a gradient transition between the 2 colors.

JacksonWrath commented 2 years ago

You can!

Open ~/.config/glava/bars.glsl and look for these lines:

/* Bar color changes with height */
#define GRADIENT (d / GRADIENT_POWER + 1)
/* Bar color */
#define COLOR (#3366b2 * GRADIENT)

Change them to something like this:

/* Bar color changes with height */
#define GRADIENT (d / AREA_HEIGHT)
/* Bar color */
#define LOW_COLOR #f542ff
#define HIGH_COLOR #33c2ff
#define COLOR mix(LOW_COLOR, HIGH_COLOR, GRADIENT)

mix interpolates between the two colors. The 3rd parameter is a percentage (0.0 - 1.0), so I changed GRADIENT to be a fraction of GLava's window height. You can adjust GRADIENT to tweak how and where it transitions. Increasing/decreasing d by some constant will shift the gradiant up and down, for example.

scorpium959 commented 2 years ago

You can!

Open ~/.config/glava/bars.glsl and look for these lines:

/* Bar color changes with height */
#define GRADIENT (d / GRADIENT_POWER + 1)
/* Bar color */
#define COLOR (#3366b2 * GRADIENT)

Change them to something like this:

/* Bar color changes with height */
#define GRADIENT (d / AREA_HEIGHT)
/* Bar color */
#define LOW_COLOR #f542ff
#define HIGH_COLOR #33c2ff
#define COLOR mix(LOW_COLOR, HIGH_COLOR, GRADIENT)

mix interpolates between the two colors. The 3rd parameter is a percentage (0.0 - 1.0), so I changed GRADIENT to be a fraction of GLava's window height. You can adjust GRADIENT to tweak how and where it transitions. Increasing/decreasing d by some constant will shift the gradiant up and down, for example.

scorpium959 commented 2 years ago

@JacksonWrath i dont know but the code doesnt work what i have to do? i copied the code but the result isnt like i wanted, the only color that is present is the low color but not the high.

scorpium959 commented 2 years ago

Update, i got it work: `/ Bar color changes with height /

define GRADIENT (d / GRADIENT_POWER)

/ Bar color /

define LOW_COLOR #f542ff

define HIGH_COLOR #33c2ff

define COLOR mix(LOW_COLOR, HIGH_COLOR, GRADIENT)`

i had to change the AREA_HEIGHT constant to GRADIENT_POWER and it works now.

@JacksonWrath Thanks for the help :)

JacksonWrath commented 2 years ago

I'm glad you got something working! I think that happened because I forgot that I disabled the setgeometry line in rc.glsl and am just enforcing the window size with KDE. The AREA_HEIGHT might be different than what is actually being drawn or something.

Either way, you got the gist. You're welcome!