Changing the colour of a graphics object dynamically by RGB at runtime

This sounds like a simple objective but hard to achieve in practise unless I'm missing something.

I can easily place a graphics object on a page, and set its colour to any RGB value, at design time. I can even pre-configure several colour options and use an expression to pick one of them at runtime,

But how can I set an arbitrary colour at runtime?

The use case is simple: I need to show the colour of some lighting. The colour can change at runtime to any RGB combination (with R,G,B each being 8-bit UINTs). How can I show that colour on a graphics page? (Consider a slider each for R, G & B, and a box that shows the colour as the sliders are moved.)

The best I have come up with so far is to create my own ActiveX object to do it, although I'd really prefer not to do it outside Citect and especially not with something like ActiveX (it's 2022!). 

I'm having a discussion with support about it and figured it might be useful to see if anyone else has any clever ideas I haven't thought of!

In case it's relevant I need to show anything up to about 50 different colours on the same page simultaneously, and I need the resulting object to behave like other graphics objects (I need to be able to hide it, or to click on it to trigger a Cicode function, etc).

  • I couldn't help myself - So the plot functions don't seem to have the same limitation - here are 32768 generated colours.  Fair to say I almost lost the plot getting this working.

    FUNCTION lotsacolours()
    INT r,g,b, hAn, hPlot, hCol, nRet
    FOR r = 0 TO 31 DO
    FOR g = 0 TO 31 DO
    FOR b = 0 TO 31 DO
    hAn = DspAnNew(r*3+g*3*31, b*32)
    hCol = MakeCitectColour(r*8,g*8,b*8)
    TraceMsg("r: " + R:# + " g: " +G:# + " B: " + B:# + " = " + HexToStr(HcOL,8))
    hPlot = PlotOpen(hAn, "Display",1)
    //nRet = PlotMarker(hPlot, 7, hCol, 0, 1, 0, 0) //this works too but the markers are too big
    nRet = PlotDraw(hPlot, 3, 0, hCol, 3, hCol, 0, 0, 20, 20)
    PlotClose(hPlot)
    END
    END
    END
    END

  • I couldn't help myself - So the plot functions don't seem to have the same limitation - here are 32768 generated colours.  Fair to say I almost lost the plot getting this working.

    Wow, thanks!

    It does have the feel of a nice little Citect challenge - I've spent way more time on this than is probably justified (and I've had a similar effort from our local support) but neither of us came up with your solution.

    I'll go and experiment!

    I feel bad that you won't have any excuse for more plot puns though! Or maybe you're just happy to draw a line under it...

  • Hmm this whole thing has turned into a bit of a kudzu plot.