VERSION 5.00
Begin VB.Form frmRGBHSL 
   Caption         =   "RGB-HSL"
   ClientHeight    =   3840
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7350
   ScaleHeight     =   3840
   ScaleWidth      =   7350
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtRGB 
      Alignment       =   1  'Right Justify
      Appearance      =   0  'Flat
      Height          =   285
      Left            =   4560
      TabIndex        =   51
      Text            =   "0"
      Top             =   3270
      Width           =   855
   End
   Begin VB.CommandButton cmdGo 
      Caption         =   "Go"
      Height          =   375
      Left            =   5640
      TabIndex        =   50
      Top             =   3240
      Width           =   1575
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   49
      Left            =   6720
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   49
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   48
      Left            =   6000
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   48
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   47
      Left            =   5280
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   47
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   46
      Left            =   4560
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   46
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   45
      Left            =   3840
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   45
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   44
      Left            =   3120
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   44
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   43
      Left            =   2400
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   43
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   42
      Left            =   1680
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   42
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   41
      Left            =   960
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   41
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   40
      Left            =   240
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   40
      Top             =   2520
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   39
      Left            =   6720
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   39
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   38
      Left            =   6000
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   38
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   37
      Left            =   5280
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   37
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   36
      Left            =   4560
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   36
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   35
      Left            =   3840
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   35
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   34
      Left            =   3120
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   34
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   33
      Left            =   2400
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   33
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   32
      Left            =   1680
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   32
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   31
      Left            =   960
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   31
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   30
      Left            =   240
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   30
      Top             =   1920
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   29
      Left            =   6720
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   29
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   28
      Left            =   6000
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   28
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   27
      Left            =   5280
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   27
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   26
      Left            =   4560
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   26
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   25
      Left            =   3840
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   25
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   24
      Left            =   3120
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   24
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   23
      Left            =   2400
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   23
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   22
      Left            =   1680
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   22
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   21
      Left            =   960
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   21
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   20
      Left            =   240
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   20
      Top             =   1320
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   19
      Left            =   6720
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   19
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   18
      Left            =   6000
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   18
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   17
      Left            =   5280
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   17
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   16
      Left            =   4560
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   16
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   15
      Left            =   3840
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   15
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   14
      Left            =   3120
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   14
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   13
      Left            =   2400
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   13
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   12
      Left            =   1680
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   12
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   11
      Left            =   960
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   11
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   10
      Left            =   240
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   10
      Top             =   720
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   9
      Left            =   6720
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   9
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   8
      Left            =   6000
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   8
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   7
      Left            =   5280
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   7
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   6
      Left            =   4560
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   6
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   5
      Left            =   3840
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   5
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   4
      Left            =   3120
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   4
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   3
      Left            =   2400
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   3
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   2
      Left            =   1680
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   2
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   1
      Left            =   960
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   1
      Top             =   120
      Width           =   495
   End
   Begin VB.PictureBox Picture1 
      Height          =   495
      Index           =   0
      Left            =   240
      ScaleHeight     =   435
      ScaleWidth      =   435
      TabIndex        =   0
      Top             =   120
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "&&H"
      Height          =   255
      Left            =   4245
      TabIndex        =   52
      Top             =   3300
      Width           =   495
   End
End
Attribute VB_Name = "frmRGBHSL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type HSL
    Hue As Long
    Saturation As Long
    Luminance As Long
End Type

Private Function HSLToRGB(ByVal Hue As Long, ByVal Saturation As Long, ByVal Luminance As Long) As Long
Dim R As Long, G As Long, B As Long
Dim lMax As Long, lMid As Long, lMin As Long
Dim Delta As Single
lMax = (Luminance * 255) / 100
lMin = (100 - Saturation) * lMax / 100
Delta = (lMax - lMin) / 60
Select Case Hue
Case 0 To 60
    lMid = (Hue - 0) * Delta + lMin
    R = lMax: G = lMid: B = lMin
Case 60 To 120
    lMid = -(Hue - 120) * Delta + lMin
    R = lMid: G = lMax: B = lMin
Case 120 To 180
    lMid = (Hue - 120) * Delta + lMin
    R = lMin: G = lMax: B = lMid
Case 180 To 240
    lMid = -(Hue - 240) * Delta + lMin
    R = lMin: G = lMid: B = lMax
Case 240 To 300
    lMid = (Hue - 240) * Delta + lMin
    R = lMid: G = lMin: B = lMax
Case 300 To 360
    lMid = -(Hue - 360) * Delta + lMin
    R = lMax: G = lMin: B = lMid
End Select
HSLToRGB = B * &H10000 + G * &H100& + R
End Function

Private Function RGBToHSL(ByVal RGBValue As Long) As HSL
Dim R As Long, G As Long, B As Long
Dim lMax As Long, lMin As Long
Dim Delta As Single
R = RGBValue And &HFF
G = (RGBValue And &HFF00&) \ &H100&
B = (RGBValue And &HFF0000) \ &H10000
If R > G Then
    lMax = R: lMin = G
Else
    lMax = G: lMin = R
End If
If B > lMax Then
    lMax = B
ElseIf B < lMin Then
    lMin = B
End If
RGBToHSL.Luminance = lMax * 100 / 255
If lMax > lMin Then
    RGBToHSL.Saturation = (lMax - lMin) * 100 / lMax
    Delta = 60 / (lMax - lMin)
    Select Case lMax
    Case R
    If B > G Then
        RGBToHSL.Hue = Delta * (G - B) + 360
    Else
        RGBToHSL.Hue = Delta * (G - B)
    End If
    Case G
        RGBToHSL.Hue = Delta * (B - R) + 120
    Case B
        RGBToHSL.Hue = Delta * (R - G) + 240
    End Select
End If
End Function

Private Sub cmdGo_Click()
Dim Color As HSL
Color = RGBToHSL(Val("&H" & txtRGB.Text))
For Color.Hue = 0 To 49
    Picture1(Color.Hue).BackColor = HSLToRGB(Color.Hue, Color.Saturation, Color.Luminance)
Next Color.Hue
End Sub
