Home » Modeling » Graphiti » Simple gradient(How to create a simple gradient with two colors for a shape?)
Simple gradient [message #1073134] |
Wed, 24 July 2013 07:43 |
John Cole Messages: 66 Registered: June 2013 |
Member |
|
|
Hello everyone,
I am using a multitude of different looking shapes in my graphiti editor, which are created automaticly based on descriptions I imported to the editor.
So far so good, but some of the shapes don't simply use a foreground color but gradients. So instead of just using the method setBackground I want to create a gradient, like seen in the picture.
The colors of the gradient are also different from case to case and are readed out from the descriptions I mentioned above. So I can't use final class variables for that.
Here's a short example:
// shape, that will get the gradient color
Rectangle rectangleShape;
// two colors for the gradient
Color color1 = gaService.manageColor(targetDiagram, 120, 120, 120);
Color color2 = gaService.manageColor(targetDiagram, 5, 5, 5);
// set the gradient
rectangleShape.setGradient(color1, color2);
Of course there is no method setGradient, but that's just what I thought about.
Is there such a simple solution for my problem?
Thanking you in anticipation!
-
Attachment: gradient.png
(Size: 1.12KB, Downloaded 226 times)
[Updated on: Wed, 24 July 2013 07:44] Report message to a moderator
|
|
| |
Re: Simple gradient [message #1073698 is a reply to message #1073333] |
Thu, 25 July 2013 10:32 |
John Cole Messages: 66 Registered: June 2013 |
Member |
|
|
Hello Michael,
many thanks for the answer.
Tried it out and it works so far. I have only one problem now. I tried to implement a gradient from black to white, like this:
addGradientColoredArea(
gcas,
"000000",
0,
LocationType.LOCATION_TYPE_ABSOLUTE_START,
"FFFFFF",
0,
LocationType.LOCATION_TYPE_ABSOLUTE_END);
It works, but the problem is, that until now I am only able to define a gradient with two colors.
What I'm trying to do is to define a gradient from one color to another and from the middle again to the first one (as you can see in the picture of my first post).
In the example of my first post it would be from black to gray and then again from grey to black, up from the middle.
Is that possible? What should I do?
Many thanks id advance!
|
|
| |
Re: Simple gradient [message #1080746 is a reply to message #1075338] |
Tue, 06 August 2013 10:35 |
John Cole Messages: 66 Registered: June 2013 |
Member |
|
|
Thank you very much Michael! It worked perfectly!
Here's the code, if somebody comes across the same problem:
// gradient from pixel 0 from absolute start to height / 2
addGradientColoredArea(
gcas,
color1,
0,
LocationType.LOCATION_TYPE_ABSOLUTE_START,
color2,
height / 2,
LocationType.LOCATION_TYPE_RELATIVE);
// gradient from height / 2 to pixel 0 from absolute end
addGradientColoredArea(
gcas,
color2,
height / 2,
LocationType.LOCATION_TYPE_RELATIVE,
color1,
0,
LocationType.LOCATION_TYPE_ABSOLUTE_END);
|
|
|
Goto Forum:
Current Time: Thu Apr 25 22:55:24 GMT 2024
Powered by FUDForum. Page generated in 0.03149 seconds
|