CodeItBetter Programming Another VB Programming Blog

How to Mix colors

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'Graphics - How to Mix colors
Option Explicit
 
Private Function MixColors(ParamArray lMix() As Variant) As Long
    Dim lR As Long, lG As Long, lB As Long
    Dim lNewR As Long, lNewG As Long, lNewB As Long
    Dim lColors() As Long
    Dim I As Integer
 
    ReDim lColors(UBound(lMix) + 1)
 
    For I = 0 To UBound(lMix)
        lColors(I) = lMix(I)
    Next I
 
    For I = 0 To UBound(lColors)
        Debug.Print lColors(I)
        lR = lColors(I) And 255
        lG = (lColors(I) And 65280) / 256
        lB = (lColors(I) And 16711680) / 65536
        lNewR = lNewR + lR
        lNewG = lNewG + lG
        lNewB = lNewB + lB
    Next I
 
    MixColors = RGB(lNewR / UBound(lColors) + 1, lNewG / UBound(lColors) + 1, _
        lNewB / UBound(lColors) + 1)
End Function
 
'How to use this function:
'Me.BackColor = MixColors(vbRed, vbYellow) 'produces an orange color
Filed under: Graphics Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.