HighTechTalks DotNet Forums  

Neon Lines

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Neon Lines in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
kpg
 
Posts: n/a

Default Neon Lines - 04-07-2010 , 04:33 PM






Hi all,

I've hacked my way through doing some pretty impressive (to me at least)
things with the .net drawing functions, but this one has me stumped.

I want to draw neon lines. Now I can draw a straight line with a gradient
to simulate a neon effect, but I'm having trouble with curves and
arbitrarily complex polygons.

To achieve a basic neon effect a gradient of dark-light-dark is used, with
the light color in the center and dark on the edges. I need to be able to
draw a line of s specified with this gradient following a path.

Any ides, sites, examples or other input is appreciated.

kpg

Reply With Quote
  #2  
Old   
James Hahn
 
Posts: n/a

Default Re: Neon Lines - 04-10-2010 , 10:03 PM






It can be done for an arc using this procedure:

Create a pie region with a radius that corresponds to what will become the
outer edge of the arc (the example below uses, X, Y, width, height, start
and end angles). Create a path gradient brush with the two colors you want
to use, and set the FS point half way between the inner and outer edges of
the arc. Adjust the centre point to the start of the path. Set the siga
bell shape to the style you want. For instance, an arced neon looks better
with this slightly offset from the half-way point. Create a pen from the
brush using the original rectangle. Draw the pen into the region of the
original rectangle.

Shorter is the size for drawing into, Centre is the central point for the
arcs. t2 is the starting angle and rot is the amount to rotate.

Dim P0 As Single = Shorter * Math.Abs(myOuterEdge)
Dim P1 As Single = Shorter * Math.Abs(myInnerEdge)
t0 = Center - Center * Math.Abs(myInnerEdge)
t1 = Center - Center * Math.Abs(myOuterEdge)

Dim PA As GraphicsPath = New GraphicsPath
PA.AddPie(t1, t1, P0, P0, t2, Rot)
Dim GradBrush As New PathGradientBrush(PA)
Dim colors() As Color
Dim FS As Single
Dim PointerAntiColor As Color = Color.FromArgb(myPointerColor.A,
(myPointerColor.R + 128) Mod 256, (myPointerColor.G + 128) Mod 256,
(myPointerColor.B + 128) Mod 256)
colors = New Color() {PointerAntiColor}
GradBrush.CenterPoint = PA.PathPoints(0)
GradBrush.CenterColor = PointerColor
FS = (myOuterEdge - myInnerEdge) / 2.0! + myInnerEdge
GradBrush.FocusScales = New PointF(FS, FS)
GradBrush.SurroundColors = colors
GradBrush.SetSigmaBellShape(4) 'THIS NEEDS EXPERIMENTING
Dim GPPen As Pen = New Pen(GradBrush, (t0 - t1) * 2)
GPPen.Alignment = PenAlignment.Center
G.DrawArc(GPPen, t1, t1, P0, P0, t2, Rot)

"kpg" <ipost@thereforeiam> wrote

Quote:
Hi all,

I've hacked my way through doing some pretty impressive (to me at least)
things with the .net drawing functions, but this one has me stumped.

I want to draw neon lines. Now I can draw a straight line with a gradient
to simulate a neon effect, but I'm having trouble with curves and
arbitrarily complex polygons.

To achieve a basic neon effect a gradient of dark-light-dark is used, with
the light color in the center and dark on the edges. I need to be able to
draw a line of s specified with this gradient following a path.

Any ides, sites, examples or other input is appreciated.

kpg

Reply With Quote
  #3  
Old   
kpg
 
Posts: n/a

Default Re: Neon Lines - 04-12-2010 , 04:42 PM



Interesting...

I had some success with creating a path then drawing a line or curve
connection the points on the path. To get the neon effect, I first draw a
wide line in my outer color, then repeat with smaller and smaller line
widths and lighter colors along the same path.

So for a line 20 wide, I make 20 passes, each time decrementing the line
width and lighting the color. The result is very close to what I had
envisioned, but seems like more work than should be required.


r = ClientRectangle
g.FillRectangle(Brushes.White, r)

Dim points(5) As PointF
points(0) = New Point(100, 100)
points(1) = New Point(150, 100)
points(2) = New Point(125, 200)
points(3) = New Point(225, 200)
points(4) = New Point(200, 100)
points(5) = New Point(250, 100)

Dim path As New GraphicsPath

path.AddCurve(points)

Dim p As Pen
Dim c(20) As Color

'this routine builds an array of smooth color change from source to dest
CalculateGradient(Color.Blue, Color.LightBlue, c)

For i As Int16 = 20 To 1 Step -1
p = New Pen(c(20 - i), i)
g.DrawPath(p, path)
Next


kpg

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.