Contoh penerapan yaitu seperti gambar di samping ini membuat warna tampilan Form dan PictureBox. Sebagai latihan buat satu project dan tempatkan 2 buah komponen PictureBox, 1 buah kompunen timer dan 3 buah komponen label. dan masukan source kode di bawah ini.
Berikut contoh source code Membuat Gradien:
Option Explicit
Dim Red, Green, Blue, sred, ered, sgreen, sblue, egreen, eblue, difr, difg, difb, fora
Public Enum enumOrientation
Orientation_Horizontal = 0
Orientation_Vertical = 1
End Enum
Public Function Gradient(Frm As Object, Orientation As enumOrientation, SClr As ColorConstants, EClr As ColorConstants)
Dim Yi
Frm.AutoRedraw = True: Frm.ScaleMode = 3 '2 is interesting,too
Analyze (SClr): sred = Red: sgreen = Green: sblue = Blue
Analyze (EClr): ered = Red: egreen = Green: eblue = Blue
difr = ered - sred: difg = egreen - sgreen: difb = eblue - sblue
Select Case Orientation
Case Is = 0: fora = Frm.ScaleHeight
Case Is = 1: fora = Frm.ScaleWidth
End Select
For Yi = 0 To fora
sred = sred + (difr / fora): If sred < 0 Then sred = 0
sgreen = sgreen + (difg / fora): If sgreen < 0 Then sgreen = 0
sblue = sblue + (difb / fora): If sblue < 0 Then sblue = 0
Select Case Orientation
Case Is = 0: Frm.Line (0, Yi)-(Frm.ScaleWidth, Yi), RGB(sred, sgreen, sblue), B
Case Is = 1: Frm.Line (Yi, 0)-(Yi, Frm.ScaleHeight), RGB(sred, sgreen, sblue), B
End Select
Next
End Function
Public Function Analyze(CConst As ColorConstants)
Dim rr, gr, br As Long
rr = 1: gr = 256: br = 65536
Dim rest As Long
rest = CConst \ br
Blue = rest
CConst = CConst Mod br
If Blue < 0 Then Blue = 0
rest = CConst \ gr
Green = rest
CConst = CConst Mod gr
If Green < 0 Then Green = 0
rest = CConst \ rr
Red = rest
CConst = CConst Mod rr
If Red < 0 Then Red = 0
End Function
Private Sub Form_Resize()
Gradient Picture1, 0, vbCyan, vbYellow
Gradient Picture2, 0, vbRed, vbCyan
Gradient Me, 1, vbGreen, vbRed
Label1.Caption = "Gradiant Picture"
End Sub
Private Sub Timer1_Timer()
Label4.Caption = Time
Label5.Caption = Format(Date, "Long date")
End Sub
Dim Red, Green, Blue, sred, ered, sgreen, sblue, egreen, eblue, difr, difg, difb, fora
Public Enum enumOrientation
Orientation_Horizontal = 0
Orientation_Vertical = 1
End Enum
Public Function Gradient(Frm As Object, Orientation As enumOrientation, SClr As ColorConstants, EClr As ColorConstants)
Dim Yi
Frm.AutoRedraw = True: Frm.ScaleMode = 3 '2 is interesting,too
Analyze (SClr): sred = Red: sgreen = Green: sblue = Blue
Analyze (EClr): ered = Red: egreen = Green: eblue = Blue
difr = ered - sred: difg = egreen - sgreen: difb = eblue - sblue
Select Case Orientation
Case Is = 0: fora = Frm.ScaleHeight
Case Is = 1: fora = Frm.ScaleWidth
End Select
For Yi = 0 To fora
sred = sred + (difr / fora): If sred < 0 Then sred = 0
sgreen = sgreen + (difg / fora): If sgreen < 0 Then sgreen = 0
sblue = sblue + (difb / fora): If sblue < 0 Then sblue = 0
Select Case Orientation
Case Is = 0: Frm.Line (0, Yi)-(Frm.ScaleWidth, Yi), RGB(sred, sgreen, sblue), B
Case Is = 1: Frm.Line (Yi, 0)-(Yi, Frm.ScaleHeight), RGB(sred, sgreen, sblue), B
End Select
Next
End Function
Public Function Analyze(CConst As ColorConstants)
Dim rr, gr, br As Long
rr = 1: gr = 256: br = 65536
Dim rest As Long
rest = CConst \ br
Blue = rest
CConst = CConst Mod br
If Blue < 0 Then Blue = 0
rest = CConst \ gr
Green = rest
CConst = CConst Mod gr
If Green < 0 Then Green = 0
rest = CConst \ rr
Red = rest
CConst = CConst Mod rr
If Red < 0 Then Red = 0
End Function
Private Sub Form_Resize()
Gradient Picture1, 0, vbCyan, vbYellow
Gradient Picture2, 0, vbRed, vbCyan
Gradient Me, 1, vbGreen, vbRed
Label1.Caption = "Gradiant Picture"
End Sub
Private Sub Timer1_Timer()
Label4.Caption = Time
Label5.Caption = Format(Date, "Long date")
End Sub
Silakan Download disini
0 komentar:
Komentar Anda
Berikan komentar..