Doubt in Gradient

I just want to know, is it possible to apply gradient along the stroked Path…

The ColourGradient Should be applied from the Stroked Left to Stroked Right along the path…

For Example,
If i have a Colourgradient with Colour red on Both ends and Blue at the middle…
Giving the stroked path of the Rectangle should make the Rectangle look like drawn with three outline colour…

Hope you understand…

Once you have created your ColourGradient (eg. newGradient) and set the colours accordingly you need to create a GradientBrush (eg. newBrush) using your ColourGradient as the argument to the constructor http://www.rawmaterialsoftware.com/juce/api/classGradientBrush.html#ac2d14d0f7932b027c817f8c605bd382

Then you have to set the graphics object to use this brush eg. “g.setBrush(newBrush);” then you can draw your rect as you normally would.

You will need to set the co-ordinates of the ColourGradient when you create it so that it coincides with your rect.

Hope that makes some sense.

I think i didn’t explain properly…

I stroke a vertical line path of thickness 20.0.
I create c Colourgradient, when i say apply gradient on the path means…

Now the path is 20 pixels, you should consider only the gradient colours and proportions and not the x1,y1,x2 and y2, …

x1,y1,x2 and y2 is depend on the path…And it is not constant through out the path… The gradient should be applied perpendicular to the path vertex…

Sorry if am not clear

If I understand you right, then no - gradients are fixed relative to the origin, and not relative to any part of the path that you’re filling. You’d need to do a bit of maths and create special gradients for each different area that you’re trying to draw.

Yes correct…

But i have a small doubt, for the path connecting using straight lines i can do…
But for the curves, i have no idea…
Is it possible to do radial gradient other than round shape…
Like Ellipse… If it is possible it’ll help somehow…

Well, you can do non-circular gradients, but not quadratic ones! The only way you could sensibly do it would be by flattening the path and making sure all the line sements join up neatly… definitely not a trivial problem!

Can you tell me how to make non circular gradient…

Regards
Noorul

If you’re trying to make a gradient fit a cubic spline path then you’re probably wasting your time, but the GradientBrush lets you apply an affine transform.