FX expression for triangular Gradient

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

FX expression for triangular Gradient

Post by anthony »

It is rare I ask for help of IM users, but here is one case.

Looking back the IM forum had a discussion of creating triangular gradients using programs outside IM. Well with the addition of variable assignments, the amount of complexity that can be encoded into -fx image expressions has increase significatally. As such it should not be able to do this using an FX expression. but I am stuck..

For example here is a gradient based on two points of color and the distance between them...

Code: Select all

   convert  -size 100x100 xc: +size xc:red xc:yellow \
             -fx 'ax=i/w-.8; ay=j/h-.1; ar=sqrt(ax*ax+ay*ay); \
                  bx=i/w-.1; by=j/h-.7; br=sqrt(bx*bx+by*by); \
                  u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \
             gradient_dist_ratio.gif
 
Image

However i want to expand this to three points but I doesn't work. Can you find the problem?

Code: Select all

    convert  -size 100x100 xc: +size xc:red xc:blue xc:green1 \
             -fx 'ax=i/w-.5; ay=j/h-.1; ar=sqrt(ax*ax+ay*ay);
                  bx=i/w-.1; by=j/h-.7; br=sqrt(bx*bx+by*by);
                  cx=i/w-.9; cy=j/h-.9; cr=sqrt(cx*cx+cy*cy);
                  rt=ar+br+cr;  ra=1-ar/rt; rb=1-br/rt; rc=1-cr/rt;
                  zz=br*cr+ar*cr+ar*br;
                  u[1]*br*cr/zz + u[2]*ar*cr/zz + u[3]*ar*br/zz  '  \
             gradient_triangular.gif
Image

This will be used in IM Examples
More Complex DIY Gradients
http://www.cit.gu.edu.au/~anthony/graph ... nt_complex
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Anyone?

I am sure I am missing something very basic in these examples!
Probably will be kicking myself afterward!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply