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?
5 posts
• Page 1 of 1
create shape with graphicpath linear gradient ruby?
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
Can someone tell Me how to add a linear gradient to that?
TIA
-
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?
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...
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.
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!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: create shape with graphicpath linear gradient ruby?
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?
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!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: create shape with graphicpath linear gradient ruby?
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.
Thanks to you both, these are useful tips.
-
wlangfor@uoguelph.ca - Posts: 912
- Joined: Tue Apr 03, 2018 5:50 pm
- Location: North Bay, Ontario, Canada
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 81 guests