Library code snippets
Creating color degradations with any two colors
By Jose Pablo Ramirez Vargas, published on 07 Sep 2002
Page 2 of 2
- The Calculation
- Example of Use
Example of Use
Add a form to your project, called form1, then add a menu Item called mnDraw, with caption "Draw effect", then add a common dialog control called CommonDialog1, then add the following code, along with the functions in the previous page.
You could alter this to make the effect vertical, or starting from the center of the form, or alter the CalculateGradient function to introduce a weight factor to increase the gradient exponencially, or quadratic, or whatever... you name it!
Private Sub mnDraw_Click()
Dim fColor As Integer
Dim arrColors() As Long
Dim steps As Variant
Dim color1 As Long
Dim color2 As Long
Dim posY As Long
'Get color choices from user
With CommonDialog1
.Flags = cdlCCRGBInit
.CancelError = True
On Error Resume Next
.ShowColor
If (Err.Number <> 0) Then
Exit Sub
End If
On Error GoTo 0
color1 = .color
On Error Resume Next
.ShowColor
If (Err.Number <> 0) Then
Exit Sub
End If
On Error GoTo 0
color2 = .color
End With
'Get amount of steps from user
steps = InputBox("Number of steps:", , 32)
If (steps = "") Then
Exit Sub
End If
steps = CLng(steps)
'Calculate gradient; display error message if applicable
If Not (CalculateGradient(color1, color2, steps, arrColors)) Then
MsgBox "An error occured while calculating the gradient!", vbExclamation
Exit Sub
End If
'Get the form ready to paint horizontal lines.
'The easiest way to do it is to use a user scalemode.
Me.ScaleHeight = steps
'Set starting position
posY = Me.ScaleTop
'Now draw boxes
For fColor = LBound(arrColors) To UBound(arrColors)
Me.Line (Me.ScaleLeft, posY)-(Me.ScaleWidth + Me.ScaleLeft, posY + 1), arrColors(fColor), BF
posY = posY + 1
Next fColor
End Sub
You could alter this to make the effect vertical, or starting from the center of the form, or alter the CalculateGradient function to introduce a weight factor to increase the gradient exponencially, or quadratic, or whatever... you name it!
Related articles
Related discussion
-
Regarding Visual Basic Programme
by manjunathsl2007 (0 replies)
-
how do you hide all in VB6
by CapnJack (1 replies)
-
Problem with Input File
by novavb6 (3 replies)
-
How to produce a txt file with a table??
by novavb6 (1 replies)
-
VB6 compatability from XP to Vista
by bronx (1 replies)
This thread is for discussions of Creating color degradations with any two colors.