Skip to main content

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


console.log(node.fillsl0].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?

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


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.


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.


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