Scripting Panel Gradients?

Joe Kaplan's icon

Is there a way to script or otherwise modify the bgfillcolor attribute of a panel that's in gradient mode?

I'm aware of the "grad1" "grad2" and "angle" messages that you can send to panels. This is helpful. But limited relative to the actual customization that's possible with gradients. I noticed that if you make any manual changes to the angle in the inspector, the "angle" message to that panel no longer works. Particularly if you move the two end-dots. This is frustrating. Also, I don't see any way of modifying the blend point via messages.

If I set up the gradient the way I want it then "create a message box with this attribute's current values" it just says "bgfillcolor dictionary"

Is there any way to actually view that dictionry, or store it, or modulate it with other dictionaries, say using [pattrstorage]?

I'm curious to explore the possibilities of animating my background panels to create visual effects. Every other attribute in Max can be modified via messages, but what I've been able to achieve so far with bgfillcolor gradients has been pretty limited.

I'm wondering if there's a secret technique that I'm missing. Any help is much appreciated. Thanks!

Source Audio's icon

Best bet to get hidden max attributes for objects is to store
one in a patch and read it as plain text.
That unveils proportion as float 0. - 1. for blend.
value 1 behaves a bit weird, jumps in the middle again.
I did not notice any problem moving angle.

Max Patch
Copy patch and select New From Clipboard in Max.

Only annoying thing is that not all things get stored, only ones which deviate from default...
{
                "box" :                 {
                    "angle" : 270.0,
                    "grad1" : [ 0.568627450980392, 0.105882352941176, 0.105882352941176, 1.0 ],
                    "grad2" : [ 0.101960784313725, 0.196078431372549, 0.901960784313726, 1.0 ],
                    "id" : "obj-1",
                    "maxclass" : "panel",
                    "mode" : 1,
                    "numinlets" : 1,
                    "numoutlets" : 0,
                    "patching_rect" : [ 242.0, 180.0, 128.0, 128.0 ],
                    "proportion" : 0.225028058361392
                }

after changing border and shape :

{
                "box" :                 {
                    "angle" : 240.0,
                    "border" : 2,
                    "bordercolor" : [ 0.905882352941176, 0.898039215686275, 0.803921568627451, 1.0 ],
                    "grad1" : [ 0.568627450980392, 0.105882352941176, 0.105882352941176, 1.0 ],
                    "grad2" : [ 0.101960784313725, 0.196078431372549, 0.901960784313726, 1.0 ],
                    "id" : "obj-1",
                    "maxclass" : "panel",
                    "mode" : 1,
                    "numinlets" : 1,
                    "numoutlets" : 0,
                    "patching_rect" : [ 45.0, 177.0, 128.0, 128.0 ],
                    "proportion" : 0.59,
                    "shape" : 1
                }

Joe Kaplan's icon

This is beautiful. I love that there's always a solution in Max, and if you can't figure it out from the documentation, this forum is generous and forthcoming with answers. Thank you!

I found that if I limit the [flonum]to 0. and .9999, I get very clean behavior from "proportion $1"

As far as the "angle" message breaking when it's been manually modified via inspector, I've attached a patch. This is already super helpful, but figuring out these edges would set my little mind at ease.

Max Patch
Copy patch and select New From Clipboard in Max.



Joe Kaplan's icon

I used the technique you suggested to figure out the "pt1 $1 $2" and "pt2 $1 $2" messages. But it looks like as soon as the pt1 and pt2 attributes are changed from the default (either via a message, or manual manipulation in the inspector), the panel is no longer responsive to "angle $1" messages.

Max Patch
Copy patch and select New From Clipboard in Max.

Joe Kaplan's icon

Okay... i guess "angle" is just a composite of "pt1" and "pt2." So anything you can achieve with "angle" can be achieved by adjusting the points.

So that's somewhat sensible that if you're going to manipulate the more specific attributes, the more general one is no longer active.

Anyway, looks like I have complete scripting control over the panel now. WOOHOO!! Thanks!

Joe Kaplan's icon

Will drop this here for fun. Yay Max!

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

It is a bit pitty that it has to be done with such effort, but at the end the result counts.
it was very frustrating for me when many objects got borders removed.
I used changes in background color, border color and size etc a lot in
for example text buttons, to indicate the state of functions they control.
That is all gone now, buttons can't even send 1 or 0 if not toggled.
One has to make a patch with ubutton, panel and a lot of messaging to get the same
behaviour back.
Can't call that improvement.