Coding Discussion: Changing Background Colors

Started by Senkusha, August 01, 2023, 03:43:13 PM

Previous topic - Next topic

Senkusha

Not sure where I should put this, but I'd like to eventually make a mod that changes the background of Board color using the Light Spectrum based on popularity of the topics within it.  So like a low view count would turn a background color red, slightly higher view count would turn the board color orange, a very very very high view count would turn the background color violet.  But, I'm not just looking to have a bunch of hard coded thresholds.

I'm looking for a mathematical way that based on the view count would start at red (say #FF0000) and as the view count increased it would end towards (#FF00FF) or something.  Like I'm curious even how I would make a function do what I'm seeing in my head.

One thing to keep in mind too, is that the text color may have to change so like a yellow background would need a black text color, but a red or blue background might need a white text or a grey text color.  Just some ideas.
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Kindred

using view count for ANYTHING is a poor idea and mostly pointless -- since every visit by a spider or bot counts as a view....   heck, I could write a script that sends a call for the topic page 25 million times in a day and thus artificially increase the view count of my topic.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Diego Andrés

Changing the entire background sounds a bit aggressive to the eyes, perhaps a progress bar?

SMF Tricks - Free & Premium Responsive Themes for SMF.

Senkusha

Good point about the view count.  Post count would be better.

Not the entire background.  But on the board index, the background for that particular board on the index would be the only thing to change.  I'm seeing something very colorful in my mind.
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Antechinus

It's an interesting concept, from a technical perspective, and offhand I don't think it would be particularly hard to code. The hard part will be coming up with a progression of colours that doesn't put users off. :)

Sesquipedalian

You could use the integrate_getboardtree hook (which you can find in ./Sources/Subs-BoardIndex.php) to walk through the list of boards, calculate your custom colour value for each one, and then use the addInlineCss() function to add some custom CSS to set the background colour for each board's div in the board index.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: