Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Gradient paint issue  RSS feed

 
karl nilsson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a simple gradient that will change from a shade of green to transparent, but I'm running into problems on how to represent the transparency
here is the line that needs to be changed:


bg_Color needs to be changed to transparent, but I have no idea how

-Karl Nilsson
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want to use new Color(10, 255, 10, 0),
where 10-255-10 is your shade of green, instead
of new Color(0, 0, 0, 0), unless you want the gradient
to go to a transparent black/grey instead of to green.

The point is that the final 0 means fully transparent.
(A final 255 would mean fully opaque.)
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point, Brian. Constructing a transparent color with line_color's rgb values can be done as follows.
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By chance, I had to do this earlier today, and
I chose to do it this way:

new Color(c.getRed(), c.getGreen(), c.getBlue(), 0);

(I was matching 'c', not 'line_Color'.) I don't
see any reason to prefer this over Albrechtsen's
suggestion, except perhaps that it may be more
self-explanatory to novices.
 
karl nilsson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, it works perfectly now. I was trying to make a simple applet to emulate a radar's sweep, and now it looks a lot better.
Another quick question: is there any easy way to make a gradient that is based on a circle and fades out? (Basically a circle that fades as it approaches its edge)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!