Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi custom drawing - glowing glass
    primarykey
    data
    text
    <p>I have been experimenting a lot with some glassy images, such as the one below, and I got to thinking there's gotta be a way I can put this into code, so I can color it anything I want. It doesn't need to look 100% precisely like the image below, but I'd like to write some code to draw the oval and the glass effect (gradient with some really fancy calculations). I must note clearly that I am horrible with math, and I know this requires some tricky formulas.</p> <p><strong>Sample of what I'm working on:</strong></p> <p><img src="https://i.stack.imgur.com/OXkNB.png" alt="Sample image drawn with pre-made images"></p> <p>The border of the oval is the easy part, the gradient that goes inside the oval from top to bottom is also fairly easy - but when it comes to making the edges fade to make that glassy look along the top and sides - I have no clue how to go about doing this.</p> <p><strong>Original left edge image:</strong></p> <p><img src="https://i.stack.imgur.com/ANKrN.png" alt="Original left edge image"></p> <p>Whether someone can point me to a good tutorial for this, or if someone wants to demonstrate it, either would be really appreciated. </p> <p>Here's the procedure I use to draw so far:</p> <pre><code>//B = Bitmap to draw to //Col = Color to draw glass image procedure TForm1.DrawOval(const Col: TColor; var B: TBitmap); var C: TCanvas; //Main canvas for drawing easily R: TRect; //Base rect R2: TRect; //Working rect X: Integer; //Main top/bottom gradient loop CR, CG, CB: Byte; //Base RGB color values TR, TG, TB: Byte; //Working RGB color values begin if assigned(B) then begin if B &lt;&gt; nil then begin C:= B.Canvas; R:= C.ClipRect; C.Pen.Style:= psClear; C.Brush.Style:= bsSolid; C.Brush.Color:= B.TransparentColor; C.FillRect(R); C.Pen.Style:= psSolid; C.Pen.Color:= clBlack; C.Pen.Width:= 5; C.Brush.Color:= clBlack; R2:= R; for X:= 1 to 6 do begin R2.Bottom:= R2.Bottom - 1; C.RoundRect(R2.Left, R2.Top, R2.Right, R2.Bottom, Round(R2.Bottom / 1.5), Round(R2.Bottom / 1.5)); end; R2.Left:= R2.Left + 1; R2.Right:= R2.Right - 1; C.Brush.Color:= Col; C.Pen.Width:= 3; C.RoundRect(R2.Left, R2.Top, R2.Right, R2.Bottom, Round(R2.Bottom / 1.5), Round(R2.Bottom / 1.5)); C.Brush.Style:= bsSolid; C.Pen.Style:= psClear; R2:= R; R2.Left:= R2.Left + 13; R2.Right:= R2.Right - 13; R2.Top:= 3; R2.Bottom:= (R2.Bottom div 2) - 18; CR:= GetRValue(Col); CG:= GetGValue(Col); CB:= GetBValue(Col); for X:= 1 to 16 do begin TR:= EnsureRange(CR + (X * 4)+25, 0, 255); TG:= EnsureRange(CG + (X * 4)+25, 0, 255); TB:= EnsureRange(CB + (X * 4)+25, 0, 255); C.Brush.Color:= RGB(TR, TG, TB); C.RoundRect(R2.Left, R2.Top, R2.Right, R2.Bottom, Round(R2.Bottom / 1.5), Round(R2.Bottom / 1.5)); R2.Left:= R2.Left + 2; R2.Right:= R2.Right - 2; R2.Bottom:= R2.Bottom - 1; end; end; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload