
Const ColorPureMax = 1785
Private DelerTwip As Double

Private Rood As Integer
Private Groen As Integer
Private Blauw As Integer
Private Kleur As Long

Private ColorPure As Long
Private RoodPure As Integer
Private GroenPure As Integer
Private BlauwPure As Integer

Private Aangeklikt As Boolean




Private Sub ChangeColorLeftUp()

    If Rood < False Then
        Rood = False
    End If
    If Rood > 255 Then
        Rood = 255
    End If
    
    If Groen < False Then
        Groen = False
    End If
    If Groen > 255 Then
        Groen = 255
    End If
    
    If Blauw < False Then
        Blauw = False
    End If
    If Blauw > 255 Then
        Blauw = 255
    End If
    
    HScrollRood.Value = Rood
    HScrollGroen.Value = Groen
    HScrollBlauw.Value = Blauw
        
    Kleur = RGB(Rood, Groen, Blauw)
    
    Picture1.BackColor = Kleur
    
    Ro& = RGB(Rood, 0, 0)
    Picture2.BackColor = Ro&
    
    Gr& = RGB(0, Groen, 0)
    Picture3.BackColor = Gr&
    
    Bl& = RGB(0, 0, Blauw)
    Picture4.BackColor = Bl&
        
    Label1(False).Caption = "Kleur: " & Hex$(Kleur)
    Label1(1).Caption = "Rood: " & Hex$(Rood)
    Label1(2).Caption = "Groen: " & Hex$(Groen)
    Label1(3).Caption = "Blauw: " & Hex$(Blauw)
       
End Sub

Private Sub cmdStop_Click()
    
    End
    
End Sub

Private Sub Form_Activate()
    
    Form_Load
    
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    
    Select Case Chr$(KeyAscii)
        Case Chr$(27)
            Stop
        Case "R"
            Rood = Rood + 1
        Case "r"
            Rood = Rood - 1
        Case "G"
            Groen = Groen + 1
        Case "g"
            Groen = Groen - 1
        Case "B"
            Blauw = Blauw + 1
        Case "b"
            Blauw = Blauw - 1
        Case Else
            Beep
            Exit Sub
    End Select
    
    ChangeColorLeftUp
    
End Sub

Private Sub Form_Load()

    'Maak eerst linksboven actief.
    
    Rood = 255
    Groen = 255
    Blauw = 255
    
    HScrollRood.Value = Rood
    HScrollGroen.Value = Groen
    HScrollBlauw.Value = Blauw
    
    ChangeColorLeftUp
    
        
    'DelerTwip = 1 / PictureStandaard.Width / PictureStandaard.ScaleWidth
    'DelerTwip = PictureStandaard.Width / PictureStandaard.ScaleWidth
    DelerTwip = 1 '  PictureStandaard.ScaleWidth / PictureStandaard.Width
        
   br# = DelerTwip * (PictureStandaard.Width / (ColorPureMax - 255))
   
    For ColorPure = 255 To ColorPureMax
        MakeColorPure
        kl& = RGB(RoodPure, GroenPure, BlauwPure)
        'PictureStandaard.BackColor = kl&
        xbegin# = (ColorPure - 255) * br#
        xeind# = (ColorPure - 255 + 1) * br#
        
        PictureStandaard.Line (xbegin#, 0)-(xeind#, 615), kl&, BF
    Next
    
    
    ColorPure = 255
    HScrollColor.Value = 255
    HScrollColor.Min = 255
    HScrollColor.Max = ColorPureMax
        
    picKleurNaarWitSub
    picKleurNaarZwartSub
    
    MakeColorPure
    LoadPictureboxesSub
    
    HScrollKleurNaarZwart_Scroll
    HScrollKleurNaarWit_Scroll
    
End Sub

Private Sub HScrollBlauw_Change()
    If Blauw <> HScrollBlauw.Value Then
        Blauw = HScrollBlauw.Value
            ChangeColorLeftUp
    End If
    
End Sub


Private Sub HScrollBlauw_Scroll()
    HScrollBlauw_Change
End Sub

Private Sub HScrollColor_Change()
    
    If ColorPure = HScrollColor.Value Then
        Exit Sub
    End If
    
    ColorPure = HScrollColor.Value
    
    MakeColorPure
    LoadPictureboxesSub
    lblGeklikteKleur.Caption = "Geklikte kleur:"
    
End Sub

Private Sub MakeColorPure()

    Select Case ColorPure
        Case 1 * 255 To 2 * 255
            ' rood: 255
            'groen: false => 255
            'blauw: false
            
            RoodPure = 255
            GroenPure = ColorPure - 255
            BlauwPure = False
            
        Case 2 * 255 + 1 To 3 * 255
            ' rood:  255 => false
            'groen:  255
            'Blauw:  False
            RoodPure = 3 * 255 - ColorPure
            GroenPure = 255
            BlauwPure = False
                        
        Case 3 * 255 + 1 To 4 * 255
            ' rood:  false
            'groen:  255
            'Blauw:  false => 255
            RoodPure = False
            GroenPure = 255
            BlauwPure = ColorPure - 3 * 255
                         
        Case 4 * 255 + 1 To 5 * 255
            ' rood:  false
            'groen: 255 => false
            'Blauw: 255
            RoodPure = False
            GroenPure = 5 * 255 - ColorPure
            BlauwPure = 255
                        
        Case 5 * 255 + 1 To 6 * 255
            ' rood:  false => 255
            'groen:  false
            'blauw:  255
            RoodPure = ColorPure - 5 * 255
            GroenPure = False
            BlauwPure = 255
                        
        Case 6 * 255 + 1 To 7 * 255
            ' rood:  255
            'groen:  false
            'blauw: 255 => false
            RoodPure = 255
            GroenPure = False
            BlauwPure = 7 * 255 - ColorPure
                        
    End Select
       
    
End Sub

Private Sub HScrollColor_Scroll()
    HScrollColor_Change
End Sub

Private Sub HScrollGroen_Change()
    If Groen <> HScrollGroen.Value Then
        Groen = HScrollGroen.Value
            ChangeColorLeftUp
    End If
    
End Sub

Private Sub HScrollGroen_Scroll()
    HScrollGroen_Change
End Sub

Private Sub HScrollKleurNaarWit_Change()
    'Geef de geklikte kleur aan
    HScrollKleurNaarWit_Scroll
End Sub

Private Sub HScrollKleurNaarWit_Scroll()
    'Geef de geklikte kleur aan.
         
    If Aangeklikt Then
        Aangeklikt = False
        Exit Sub
    End If
    
    drood# = (255 - RoodPure) / 255
    dgroen# = (255 - GroenPure) / 255
    dblauw# = (255 - BlauwPure) / 255
            
    dx = HScrollKleurNaarWit.Value
    kl& = RGB(RoodPure + dx * drood#, GroenPure + dx * dgroen#, BlauwPure + dx * dblauw#)
    picKleurWit.BackColor = kl&
    
    lblLichterGemaakteKleur.Caption = "Lichter gemaakte kleur : " & Hex$(Int(kl&))
    Aangeklikt = False
    
End Sub

Private Sub HScrollKleurNaarZwart_Change()
        HScrollKleurNaarZwart_Scroll
End Sub

Private Sub HScrollKleurNaarZwart_Scroll()
    'Geef de geklikte kleur aan.
   
    If Aangeklikt Then
        Aangeklikt = False
        Exit Sub
    End If
    
    drood# = RoodPure / 255
    dgroen# = GroenPure / 255
    dblauw# = BlauwPure / 255
        
    dx = 255 - HScrollKleurNaarZwart.Value
    kl& = RGB(dx * drood#, dx * dgroen#, dx * dblauw#)
    picKleurZwart.BackColor = kl&
    
    lblDonkerderGemaakteKleur.Caption = "Donkerder gemaakte kleur : " & Hex$(Int(kl&))
    Aangeklikt = False
        
End Sub





Private Sub HScrollRood_Change()
    
    If Rood <> HScrollRood.Value Then
        Rood = HScrollRood.Value
            ChangeColorLeftUp
    End If
    
End Sub


Private Sub HScrollRood_Scroll()
    HScrollRood_Change
End Sub


Private Sub picKleurNaarWit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   'Geef de geklikte kleur aan.
   
   picKleurWit.BackColor = picKleurNaarWit.Point(X, Y)
    xpos# = X
    dv# = xpos# / picKleurNaarWit.Width
    dw# = dv# / (picKleurNaarWit.ScaleWidth / picKleurNaarWit.Width)
    w# = 255 * dw#
    HScrollKleurNaarWit.Value = w#
    lblLichterGemaakteKleur.Caption = "Lichter gemaakte kleur : " & Hex$(Int(picKleurNaarWit.Point(X, Y)))
    Aangeklikt = True
    
End Sub

Private Sub picKleurNaarZwart_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Geef de geklikte kleur aan.
      
    picKleurZwart.BackColor = picKleurNaarZwart.Point(X, Y)
    xpos# = X
    dv# = xpos# / picKleurNaarZwart.Width
    dw# = dv# / (picKleurNaarZwart.ScaleWidth / picKleurNaarZwart.Width)
    w# = 255 * dw#
    HScrollKleurNaarZwart.Value = w#
    lblDonkerderGemaakteKleur.Caption = "Donkerder gemaakte kleur : " & Hex$(Int(picKleurNaarZwart.Point(X, Y)))
    Aangeklikt = True
    
End Sub

Private Sub PictureStandaard_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
                
    kleurblokken# = PictureStandaard.Width / DelerTwip
    kleuren# = (ColorPureMax - 255)
    
    'br# = 1.108 * (PictureStandaard.Width \ (ColorPureMax - 255))
    
    xpos# = X
    ColorPure = 255 + ((xpos#) / kleurblokken#) * kleuren#
    
    If ColorPure < 255 Then
        ColorPure = 255
    End If
    
    If ColorPure > ColorPureMax Then
        ColorPure = ColorPureMax
    End If
    
    lblGeklikteKleur.Caption = "Geklikte kleur: " & Hex$(PictureStandaard.Point(X, Y))
    
    HScrollColor.Value = ColorPure
    MakeColorPure
    LoadPictureboxesSub
    
End Sub



Private Sub picKleurNaarZwartSub()
    'Maak de schaal van  kleur naar zwart.
          
    drood# = RoodPure / 255
    dgroen# = GroenPure / 255
    dblauw# = BlauwPure / 255
    
    br# = picKleurNaarZwart.Width / 256
    
    For i = 255 To False Step -1
        kl& = RGB(i * drood#, i * dgroen#, i * dblauw#)
        w = 255 - i
        picKleurNaarZwart.Line (w * br#, 0)-((w + 1) * br#, picKleurNaarZwart.Height), kl&, BF
    Next
    
    
End Sub

Private Sub picKleurNaarWitSub()
    'Maak de schaal van kleur naar wit.
    
    drood# = (255 - RoodPure) / 255
    dgroen# = (255 - GroenPure) / 255
    dblauw# = (255 - BlauwPure) / 255
    
    br# = picKleurNaarWit.Width / 256
    
    For i = False To 255
        kl& = RGB(RoodPure + i * drood#, GroenPure + i * dgroen#, BlauwPure + i * dblauw#)
        picKleurNaarWit.Line (i * br#, 0)-((i + 1) * br#, picKleurNaarWit.Height), kl&, BF
    Next
    
End Sub

Private Sub LoadPictureboxesSub()
    'Laad de pcture boxen met de juiste kleuren.
    
    picKleurNaarWitSub
    picKleurNaarZwartSub
     
    kl& = RGB(RoodPure, GroenPure, BlauwPure)
    
    PictureColor.BackColor = kl&
    picKleurWit.BackColor = kl&
    picKleurZwart.BackColor = kl&
    
    HScrollKleurNaarWit.Value = False
    HScrollKleurNaarZwart.Value = False
         
    
    lblColor(0).Caption = "      Color: " & Hex$(kl&)
    lblColor(1).Caption = " Rood Color: " & Hex$(RoodPure)
    lblColor(2).Caption = "Groen Color: " & Hex$(GroenPure)
    lblColor(3).Caption = "Blauw Color: " & Hex$(BlauwPure)
    
    lblLichterGemaakteKleur.Caption = "Lichter gemaakte kleur : " & Hex(kl&)
    lblDonkerderGemaakteKleur.Caption = "Donkerder Gemaakte kleur : " & Hex$(kl&)
    
End Sub
