[Re-posting with corrected subject line - lj]
Say I want to draw a color gradiant (shade of colors) from RGB(255,127,0) to RGB(0,127,255)
Here's a method that extends Graphics to fill a gradient that smoothly varies from TopColor to BottomColor within the specified rectangle (defaulting to the entire Graphics object). It draws horizontal lines, adjusting the color for each line as it goes, so it is appropriate for visual effects that simulate a light source from above. It restores all affected properties of the graphics object before returning. Example that fills a canvas with a gradient that is white at the top and black at the bottom: Canvas1.Graphics.FillGradientTopToBottom &cffffff, &c000000 I'm sure there are faster ways to do this using Declares or plugins, but so far this has met my needs. lj /////////////////////////////////// Sub FillGradientTopToBottom(extends g as Graphics, TopColor as Color, BottomColor as Color, x as integer = 0, y as integer = 0, w as integer = - 1, h as integer = - 1) // Fills a rectangle whose color varies from top to bottom. // If the specified width/height is -1, then the fill will // extend from x,y to the right/bottom of the graphics object, // respectively. if w = -1 then w = g.Width - x if h = -1 then h = g.Height - y dim oldForeColor as Color = g.ForeColor dim oldUseOldRenderer as boolean = g.UseOldRenderer dim oldPenHeight as integer = g.PenHeight g.UseOldRenderer = true g.PenHeight = 1 dim ratio, endratio as Double for i as integer = 0 to h-1 // draw a series of horizontal lines // Determine the current line's color. ratio = (i/h) endratio = ((h-i)/h) g.ForeColor = RGB( _ TopColor.Red * endratio + BottomColor.Red * ratio, _ TopColor.Green * endratio + BottomColor.Green * ratio, _ TopColor.Blue * endratio + BottomColor.Blue * ratio) // Draw the current line. g.DrawLine x, y+i, x+w-g.PenWidth, y+i next i finally g.ForeColor = oldForeColor g.UseOldRenderer = oldUseOldRenderer g.PenHeight = oldPenHeight End Sub /////////////////////////////////// _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives of this list here: <http://support.realsoftware.com/listarchives/lists.html>
