Results 1 to 10 of 10

Thread: VB - Gradient Circle

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    Someplace 'ore the rainbow
    Posts
    392

    VB - Gradient Circle

    This code will create a gradient circle using the color, position, and radius that you want. (Currently only works on a VB form!!)

    Code:
    VB Code:
    1. Public Function gradCircle(x, Y, circleRadius, colorRed, colorGreen, colorBlue, deForm As Form)
    2.  
    3. 'Define some variables
    4. Dim cirStop As Integer
    5. cirStop = 50
    6.  
    7. 'If function works fine, result is 0
    8. gradCircle = 0
    9.  
    10. 'Get color numbers (0-255)
    11. redColor = colorRed
    12. blueColor = colorBlue
    13. greenColor = colorGreen
    14.  
    15.  
    16. 'Get current AutoRedraw property
    17. defaultAutoRedraw = deForm.AutoRedraw
    18. 'Set AuroRedraw so circle can be created
    19. deForm.AutoRedraw = True
    20.  
    21.  
    22. 'Check for illegal numbers
    23. If redColor > 255 Or redColor < 0 Or blueColor > 255 Or blueColor < 0 Or greenColor > 256 Or greenColor < 0 Then
    24.  gradCircle = 1
    25.  Exit Function
    26. End If
    27.  
    28. If redColor >= blueColor And redColor >= greenColor Then topCol = redCol
    29. If blueColor >= redColor And blueColor >= greenColor Then topCol = blueCol
    30. If greenColor >= redColor And greenColor >= blueColor Then topCol = greenCol
    31. If topCol = 0 Then topCol = 255
    32.  
    33. 'Obtain proper subtraction number for gradient
    34. If cirStop = 0 Then
    35.  subBy = topCol / circleRadius
    36.  Else
    37.   subBy = cirStop / circleRadius
    38. End If
    39.  
    40.  
    41.  'Draw circle
    42.  
    43.  For i = 1 To circleRadius
    44.  deForm.Circle (x, Y), i, RGB(redColor, greenColor, blueColor)
    45.  
    46.  'Check if red has reached the stop number
    47.  If redColor > cirStop Then
    48.   redColor = redColor - subBy
    49.   Else
    50.    redDone = "yes"
    51.  End If
    52.  
    53.   'Check if blue has reached the stop number
    54.  If blueColor > cirStop Then
    55.   blueColor = blueColor - subBy
    56.   Else
    57.    blueDone = "yes"
    58.  End If
    59.  
    60.   'Check if green has reached the stop number
    61.  If greenColor > cirStop Then
    62.   greenColor = greenColor - subBy
    63.   Else
    64.    greenDone = "yes"
    65.  End If
    66.  
    67.   'If all colors have reached the stop number, exit loop
    68.  If redDone = "yes" And blueDone = "yes" And greenDone = "yes" Then Exit For
    69. Next i
    70.  
    71.  
    72. 'Reset the AutoRedraw property to normal
    73. deForm.AutoRedraw = defaultAutoRedraw
    74. End Function

    Usage:
    VB Code:
    1. Call gradCircle(xPosition, yPosition, Radius, RedRGB, GreenRGB, BlueRGB, theVBFormName)

    This function will return '0' for a succesfull drawing and a '1' for a non-succesfull one.

    If you modify this code please email me the new code at [email protected]

    Cjqp
    Last edited by cjqp; Jun 24th, 2003 at 06:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width