Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

create shape with graphicpath linear gradient ruby?

For general discussion related FlowStone

create shape with graphicpath linear gradient ruby?

Postby wlangfor@uoguelph.ca » Wed Dec 18, 2019 12:29 am

Hi all I've been using the addlines method in graphics path.

Can someone tell Me how to add a linear gradient to that?

TIA
My youtube channel: DSPplug
My Websites: www.dspplug.com KVRaudio flowstone products
User avatar
wlangfor@uoguelph.ca
 
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada

Re: create shape with graphicpath linear gradient ruby?

Postby trogluddite » Wed Dec 18, 2019 2:30 am

The gradient will come from the brush that you draw the path with. Instead of a normal Ruby Brush object, you use a LinearGradientBrush or a PathGradientBrush (User Guide: 'Advanced Brushes', p.173)

The tricky thing is that a gradient brush isn't "attached" to the shape like it would be in most graphics applications. If you move or resize the path, you also have to move or resize the gradient. For a path, the easiest way usually is to call the getBounds method of the path; this returns a rectangular area which exactly fits the path...
Code: Select all
@path = GraphicsPath.new
# Fill the path with lines, curves, etc. here, making sure that its closed.

# Get the area of the path.
area = @path.getBounds

# Other gradient arguments
color1 = Color.new(255, 0, 0)
color2 = Color.new(0, 255, 0)
angle = 45  # clockwise in degrees.
scaleTransform = false # for angled gradients, use true if it looks better!

@gradient = LinearGradientBrush.new(area, color1, color2, angle, scaleTransform)

# Then, in your drawing routine
view.drawPath(@gradient, @path)

The area doesn't have to fit the path like this; if it's bigger, the path acts as a "window" that you see part of the gradient through.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: create shape with graphicpath linear gradient ruby?

Postby tulamide » Wed Dec 18, 2019 4:52 am

trogluddite wrote:The tricky thing is that a gradient brush isn't "attached" to the shape like it would be in most graphics applications. If you move or resize the path, you also have to move or resize the gradient.

That's the most important part. I had quite a few headaches before I realized it. Your image of a window is quite good. I myself imagine it as it probably is technically realized: An area is completely filled with a gradient, but an alpha mask reveals it only where you actually draw.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: create shape with graphicpath linear gradient ruby?

Postby trogluddite » Wed Dec 18, 2019 6:06 pm

tulamide wrote:Your image of a window is quite good. I myself imagine it as it probably is technically realized...

Thanks. The 'scaleTransform' argument beat me, though - I understand it conceptually in geometrical terms, but I had to give up on trying to put it into non-technical language (as did DSPr to judge by the User Guide!)
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: create shape with graphicpath linear gradient ruby?

Postby wlangfor@uoguelph.ca » Sun Jan 12, 2020 7:04 pm

Yes, the scale transform is strange to say the least. In fact I had tried quite a few different methods but likely these are the only ones which I can employ. Thanks to both of you. Sorry for the late reply but I had been a way attending to something.

Thanks to you both, these are useful tips.
My youtube channel: DSPplug
My Websites: www.dspplug.com KVRaudio flowstone products
User avatar
wlangfor@uoguelph.ca
 
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada


Return to General

Who is online

Users browsing this forum: No registered users and 81 guests