Random Colour
#1
Is there any way to have the skinning engine just select a random colour? This would be preferably from a list of colour names, or within a certain saturation/brightness level. These would be applied to items without artwork (overlaid with a transparent png), but would be random for each item; thereby simulating what Emby does in their player. I'm sure I could do it with a random image script that picks 8x8 PNGs of those colours, but I'd prefer to do it without going this route and just using kodi's built-in colour definitions.
Reply
#2
Not really possible using just core. The only approach I can think of is to use a variable pointing to different color definitions, and then use conditions matching certain library count values (e.g. if movies count value ends with a 1 set to blue, if it ends with 2 set to green etc.) or to certain dates. There's nothing that really generates a random value though.

Your 8x8 PNG idea is similar to something I did in Aura with colorbox. I used colorbox to cycle through highlight colors, but the basic approach is the same:
Set a multiimage control to randomize and point it to a folder filled with PNG color swatches, then use colorbox to grab colors from the multiimage control.

A better approach would be to write a simple python script which generates a random color as a window property.
Reply
#3
Actually, thinking about this more, it might be possible using a fadelabel control set to randomize.
https://kodi.wiki/view/Skinning_Manual#F...el_Control

Feed all the color names to the fade label control and then get the current label with $INFO[Control.GetLabel(ID)]
Reply
#4
Clever workaround if it randomized every time the label is called. I’ll give it a try and see how it works.

I’ll also post a random colour function as a feature request, so workarounds aren’t needed.
Reply
#5
So, I went away and tried a few things, and have realized that I don't want it to be completely random. I forgot one of the main tenets of randomness; that it's clumpy. I was visually ending up with groupings of similar or identical colours, where I want more a rainbow. That said, I decided a different approach might get me what I wanted and created 10 8x8 PNG files, labeled col0.png-col9.png and created the following variable: 
<variable name="ColourPic">
         <value condition="String.EndsWith(Container.CurrentItem,0)">special://skin/randomcolours/col0.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,1)">special://skin/randomcolours/col1.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,2)">special://skin/randomcolours/col2.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,3)">special://skin/randomcolours/col3.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,4)">special://skin/randomcolours/col4.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,5)">special://skin/randomcolours/col5.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,6)">special://skin/randomcolours/col6.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,7)">special://skin/randomcolours/col7.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,8)">special://skin/randomcolours/col8.png</value>
         <value condition="String.EndsWith(Container.CurrentItem,9)">special://skin/randomcolours/col9.png</value>
    </variable>
And inserted the following into my itemlayout and focusedlayout of my View_50_List.xml:
            <control type="image">
                            <top>5</top>
                            <left>10</left>
                            <width>110</width>
                            <height>110</height>
                            <texture background="true">$VAR[ColourPic]</texture>
                        </control>
 A fairly straightforward approach that I assumed would quickly garner the results I wanted. Item 38 in the list should display col8.png, item 304 should display col4.png, etc. But things got weird, I got clumping and colours changing every time they lose visibility and return to visibility and focus colours being different than unfocused: 

Image
Image
Image
Image

All these were taken with no change to the code. As far as I'm aware, Container.CurrentItem numbers are static and sequential once a list is generated, no? So either I'm completely wrong about what String.EndsWith() does or it's doing really weird things it shouldn't (like reading the string all at once instead of left-right or right-left) and getting confused about the numbers, or something else is giving the boolean a different number than what's expected. 

Am I wrong here? Or is this result unexpected?
Reply
#6
Not at my computer, so I can't test.

Two issues with your approach that I noticed though - you can only reference listitem info labels inside item/focused layout. Kodi doesn't like container or window property references inside list items.

Second is that container.currentitem is going to be the current focused item in the container, so will be the same value for *all* items based upon where ever focus is in the list.

You need to use something from a listitem. For instance, for songs listitem.tracknumber would work. I've done something similar before with listitem.dbid - but it will only work for library items.
Reply
#7
I ended up going your route and used the last digit of the dbid to select a colour. That said, it’d be really nice if Kodi could handle nth-functions on textures (as simple as multiple textures per image control with a condition=“nth”) to support things like alternating row colours or what I did above.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Random Colour00