[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Gradient Algorithm
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Gradient Algorithm
- From: Brain Murphy <brianomorchoe@xxxxxxxxxxx>
- Date: Sat, 5 Aug 2006 23:03:49 +0100 (BST)
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 05 Aug 2006 18:03:58 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.uk; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=z58y7mLTlkKs0XAT86XgmVBLvGgkddeTlnvaKqanhmTAmY1jqC7cEBuHDB9ATmMdXSM/qZMQTgaKgPec5TzrOfunUoSirhwmN6t4LFL+e68D15mAXELx7/WmdMmodvzNYV1Scj5fu9T3RPrqLQ3A/1n+ketI9z8pA0X1SuCsCwo= ;
- In-reply-to: <44D50DD5.5070001@xepher.net>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Thats cool I thought it was not possible.
Thank you I will try to use this.
Brian
Kris Schnee <kschnee@xxxxxxxxxx> wrote:
Here is some code I built for my interface system (Driftwood),
specifically for filling a rectangular area with a vertical gradient.
That is, it starts with one color at the top and smoothly blends to a
second color at the bottom. You can use this code if you want.
Kris
Code follows, where "self.image" is a surface and "drawing_area" is a
Rect showing the area to fill. "self.background_color" and "_gradient"
are two color tuples, eg. (0,255,255) for cyan.
x1 = self.drawing_area[0]
x2 = x1 + self.drawing_area[2]
a, b = self.background_color, self.background_gradient
y1 = self.drawing_area[1]
y2 = y1 + self.drawing_area[3]
h = y2-y1
rate
= (float((b[0]-a[0])/h),
(float(b[1]-a[1])/h),
(float(b[2]-a[2])/h)
)
for line in range(y1,y2):
color = (min(max(a[0]+(rate[0]*line),0),255),
min(max(a[1]+(rate[1]*line),0),255),
min(max(a[2]+(rate[2]*line),0),255)
)
pygame.draw.line(self.image,color,(x1,line),(x2,line))
Try the all-new Yahoo! Mail . "The New Version is radically easier to use" ? The Wall Street Journal