How do I get RGB values from a colorvalue?

2 favourites
  • 11 posts
From the Asset Store
HSV RGB Color Picker and Converter for Construct 3
  • Is there a reverse function for the following expressions?

    rgbEx(r, g, b)

    rgbEx255(r, g, b)

    rgba(r, g, b, a)

    rgba255(r, g, b, a)

  • You would have to paste into a Drawing Canvas and get the pixel color SnapshotRedAt(x, y) SnapshotGreenAt(x, y) SnapshotBlueAt(x, y)

    Takes a tick, or two.

  • That's unfortunately clunky. Guess manually setting three variables when using colorvalue to set color is the cleanest way for now.

  • Construct packs the color into a number. The usual standard is to pack the colors into a byte per component. On discord someone said it’s not packed like that but I haven’t looked into it.

    Anyways say for example the number is a 32 bit number then the color could be packed for example RGBA.

    R = int(color/256^3)%256

    G = int(color/256^2)%256

    B = int(color/256)%256

    A = color%256

    The order may be different but I haven’t checked.

    Edit:

    Looked at the manual and some of those expressions take values in the 0-100 range. It’s good to know that in the number it’s always in the 0 to 255 range. So if you want 0 to 100 you’d want to do r/255*100.

  • R0J0hound Is this for rgb expression in C2? I don't think this works in Construct 3.

  • A method I find useful. I like to work with palettes but the rgb expressions don't work well for that, so instead I use the formula R+(G*256)+(B*65536) to store my color data in an array, then just pop the index into the set color.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah. Well looking at the values further it looks like there are 10bits per component instead of 8. They didn’t end up being spaced out every 10 bits but I came up with this.

    Basically if the color is negative you can get the colors back with this. Internally each component can have 1024 values.

    If the color is positive then my previous answer should apply. But only the old rgb() expression should do that.

    R=int(-color/2^38)%1024*255/1023

    G=int(-color/2^26)%1024*255/1023 B=int(-color/2^10)%1024*255/1023 A=(-color)%1024*255/1023

    It doesn’t give the exact value but it should be spot on if you round it. Unless I made a mistake somewhere.

  • Awesome, thanks!

  • R0J0hound

    As per your posts, these seem to work:

    R int((-ColorValue/2^38)%1024*255/1023)

    G int((-ColorValue/2^24)%1024*255/1023)

    B int((-ColorValue/2^10)%1024*255/1023)

    A int((-ColorValue)%1024*255/1023)

    except when the channel value is 255 - the formula rounds it off to 0, instead of 255. Would you know how to resolve this rounding?

  • Probably replace 1024 with 1025 but I haven’t tested it.

  • R0J0hound

    Yes - works perfectly. Thank you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)