Skip to main content
Question

Trying to make sense of the rgb values returned by node.fills

  • November 26, 2021
  • 4 replies
  • 2997 views

Parad0x

I’m getting the rgb values in float format when I use :

console.log(node.fills[0].color)

this is the object which is returned :

{
    r: 0.09583333134651184,
    g: 0.09583333134651184, 
    b: 0.09583333134651184,
}

I’m trying to use the selected node’s hex or rgba color in the plugin’s UI.
But I have no idea how to use these values as this is the first time I’ve seen rgb values which are not “0-255” (I really hope I’m making sense).

Can this be converted in more “traditional” RGB format (each color values ranging between 0-255)? or is there any other way of getting the accurate HEX color of a rectangle node?

This topic has been closed for comments

4 replies

Gleb
  • Power Member
  • 4706 replies
  • November 27, 2021

These values are in [0, 1] range. A very simple mathematical operation can turn it into [0, 255] in case you need it.


Parad0x
  • Author
  • 1 reply
  • November 27, 2021

Multiplying these values by 255 seems to give accurate RGB values in 0-255 range. I need confirmation if this is the right way to do it thought.


Gleb
  • Power Member
  • 4706 replies
  • November 27, 2021

Yes, this is the right way. The simple mathematical operation I hinted at is exactly that.

Also check out this library GitHub - figma-plugin-helper-functions/figma-plugin-helpers: A collection of useful helper functions to import to your Figma plugin project — you can find lots of useful functions here for working with colors.


  • 0 replies
  • December 27, 2021

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings