Cabbage Logo
Back to Cabbage Site

Changing alpha value on an image with cabbageSet

Would it be possible to change the alpha value of an image using the cabbageSet opcode? I tried it but it crashed my Cabbage. Please see example below and attached files. Thanks!

P.S. - Haven’t tried it yet with an SVG but it’d be super to have this feature across any image file type if it’s at all possible :slight_smile:

form caption("Untitled") size(400, 400), colour(240, 240, 240) guiMode("queue"), pluginId("def1")

image bounds(180, 20, 200, 200) file("circle.png"), alpha(0.5), channel("circle") 


instr 1
    kAlpha2 linseg 0.5, 2, 1
    SCIR sprintfk "alpha(%f)", kAlpha2
    cabbageSet 1, "circle",  SCIR

imageTest.csd (1.1 KB)

Your code works in my Cabbage — it animates the opacity.
Maybe try the sprintfk inline? :man_shrugging:

cabbageSet 1, "sq1",  sprintfk("bounds(%f, %f, 40, 40), alpha(%f)", kPos1, kPos1, kAlpha1)
cabbageSet 1, "sq2",  sprintfk("bounds(%f, %f, 40, 40), alpha(%f)", kPos2, kPos2, kAlpha2)

Edit - oh, the attached .csd and the code you put above are different. Indeed the code above crashes Cabbage!

Try this

cabbageSet metro(10), "circle",  sprintfk("alpha(%f)", kAlpha2)
1 Like

cabbageSet metro(10), “circle”, sprintfk(“alpha(%f)”, kAlpha2)

That worked beautifully!

It works fine for me here, as long as I prevent the cabbageSet opcodes from firing on each k-cycle, and stop printing values on each k-cycle too. You must be using a high powered machine, because this causes my desktop to grind to a halt :rofl:

Doing this works for me:

SCIR sprintfk "alpha(%f)", kAlpha2

cabbageSet metro(10), "sq1",  SSQ1
cabbageSet metro(10), "sq2",  SSQ2
cabbageSet metro(10), "circle",  SCIR
1 Like