Re: How to draw a rectangle with gradient?



Daniel Mark wrote:

Hello all:

I am using PIL to draw a rectangle filled with color blue.

Is there anyway I could set the fill pattern so that the drawn
rectangle could be filled with
gradient blue?


Thank you
-Daniel

I don't think there is a built-in gradient function, but you could do
something like this:

import Image
import ImageDraw
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
for l in xrange(100):
.... colour = (0, 0, 255 * l / 100)
.... draw.line((0, l, 100, l), fill=colour)
....
im.show()

You have to adjust for the size and colours you want of course, and change
the loop so that the gradient is in the right direction.

// Pontus



------------ And now a word from our sponsor ----------------------
For a quality mail server, try SurgeMail, easy to install,
fast, efficient and reliable. Run a million users on a standard
PC running NT or Unix without running out of power, use the best!
---- See http://netwinsite.com/sponsor/sponsor_surgemail.htm ----
.



Relevant Pages

  • How to draw a rectangle with gradient?
    ... I am using PIL to draw a rectangle filled with color blue. ... Is there anyway I could set the fill pattern so that the drawn ...
    (comp.lang.python)
  • Re: Problem with Themes -- drawing a rebar
    ... Passing this solution along after dialoging with Mr. Wheatley offline. ... Rebar, they'll paint mostly ... So, to get the actual Rebars background gradient to draw, you'd do ... Now just be careful because the gradient you draw in themes like Luna ...
    (microsoft.public.win32.programmer.ui)
  • Re: Drawing a circular gradient
    ... linear gradient, changing the start and end color a bit each time. ... Animated vector graphics system ... > I want to draw a gradient, much like the gradient drawn by a linear ... > to be able to specify 2 colors and have the gradient drawn like in the ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Applying color to Toolbars
    ... "Tonny" wrote in message ... > I'm trying to draw an gradient on a Toolbar. ... > GradientToolbar, which inherrits from Toolbar. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Applying color to Toolbars
    ... Now I'm able to draw a gradient "backcolor". ... > GradientToolbar, which inherrits from Toolbar. ... >> protected override void OnPaint ...
    (microsoft.public.dotnet.framework.drawing)