2 Replies - 611 Views - Last Post: 16 January 2013 - 05:28 PM Rate Topic: -----

#1 ivanov_o  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-January 13

GDI+ complex gradients

Posted 16 January 2013 - 12:54 PM

Hi guys,
I'm new to GDI+ and with the graphics libraries and now I'm facing one serious problem with the gradients. I'm dveloping simple game where you have two or more ellipses that move around, each ellipse have a gradient with black for the surrounding color and transparent for the inner color. How to make the gradients to merge instead of step on each other:
Posted Image

Please to excuse me for the bad explanation but english is not my native language so it's little hard to me to explain the problem better, I hope you understand what I mean, here is the code i wrote, I'm using graphics path for storing the ellipses(I code it in VB .NET):


Public Sub FadeEllipse(e As PaintEventArgs, clrSurround As Color, clrCenter As Color, booToCenter As Boolean, _
                                  intX As Integer, intY As Integer, intW As Integer, intH As Integer)
        Dim pth As New GraphicsPath()
        pth.AddEllipse(intX, intY, intW, intH)
        Dim pgb As New PathGradientBrush(pth)
        Select Case booToCenter
            Case True
                pgb.SurroundColors = New Color() {clrSurround}
                pgb.CenterColor = clrCenter
            Case False
                pgb.SurroundColors = New Color() {clrCenter}
                pgb.CenterColor = clrSurround
        End Select
        e.Graphics.FillRectangle(pgb, intX, intY, intW, intH)
    End Sub



Thank You in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: GDI+ complex gradients

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,176
  • Joined: 02-July 08

Re: GDI+ complex gradients

Posted 16 January 2013 - 03:32 PM

I think your just missing the center point property - it needs to be set(width /2, height /2 for the center). Do you BobPowell?
Was This Post Helpful? 1
  • +
  • -

#3 ivanov_o  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-January 13

Re: GDI+ complex gradients

Posted 16 January 2013 - 05:28 PM

Thanks a lot for the help Hawk, it seems that the key to achieve this is by playing with the focus scales and center point options:
pgb.FocusScales = New PointF(sngX, sngY)
pgb.CenterPoint = New Point(intW, intH)
I'm tired now, but tommorow I'll try and see what will happen. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1