Results 1 to 13 of 13

Thread: Gradient's**(Resolved)**

  1. #1

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362

    Gradient's**(Resolved)**

    OK, I've searched on this forum and PSC and I can't find the code to do this.

    I know it can be done, but I just don't know how...

    How do you make a label have a 3 way gradient?

    e.g. start as one color go to another color and back again (RED, BLUE, RED) for instance.

    I have seen it done with 2, 4, 6, and even made to look like a color chooser box with all the color in the rainbow.

    I just want to know how to make it go from one to another and back. I don't even care what colors are used.

    I've included a pic of sorta what I need it to look like
    Attached Images Attached Images  
    Last edited by New to VB 6; May 18th, 2004 at 02:01 AM.
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  2. #2

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    A little help please?
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Well, a gradient is merely iterating through colors.

    VB Code:
    1. 'color iteration = (dest color - start color) / length
    2. ri = (r2 - r1) / length
    3. gi = (g2 - g1) / length
    4. bi = (b2 - b1) / length
    5. For x = 1 to length
    6.  'dest color = start color + color iter
    7.  dr = r1 + ri
    8.  dg = g1 + gi
    9.  db = b1 + bi
    10. Next

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Here is a quick sample.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim r As Integer
    3. Dim g As Integer
    4. Dim b As Integer
    5. Dim intCenter As Integer
    6. Dim intWidth As Integer
    7. Dim i As Integer
    8.  
    9.     intCenter = Picture1.ScaleWidth / 2
    10.    
    11.     For i = 0 To 255
    12.         ' Draw the left side
    13.         r = 255 - i
    14.         g = 0
    15.         b = i
    16.         intWidth = ((255 - i) / 255) * intCenter
    17.         Picture1.Line (0, 0)-(intWidth, Picture1.ScaleHeight), RGB(r, g, b), BF
    18.        
    19.         ' Draw the Right side
    20.         r = i
    21.         g = 0
    22.         b = 255 - i
    23.         intWidth = (((255 - i) / 255) * intCenter) + intCenter
    24.         Picture1.Line (intCenter, 0)-(intWidth, Picture1.ScaleHeight), RGB(r, g, b), BF
    25.     Next i
    26.    
    27. End Sub

  5. #5

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    How do I change colors?
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  6. #6
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    just another piece of code, hope you'll like it

    it doesnt produce exactly what you want,
    but guess you'll find it interesting.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim x As Integer, i As Integer, j As Integer
    5.  
    6.     'all you need is:
    7.     '-make a new form
    8.     '-put a label in it
    9.     'set index property of the label to 0
    10.    
    11.     'here initializing some values
    12.     Label1(0).Height = 255
    13.     Label1(0).Width = 255
    14.     Label1(0).Caption = ""
    15.     x = Label1(0).Width
    16.  
    17.     'this loads 9*9 label1(x) array into positions
    18.         Label1(i).Left = x
    19.         Label1(i).Top = x
    20.     For i = 1 To 80
    21.         Load Label1(i)
    22.         Label1(i).Left = (i Mod 9 + 1) * x
    23.         Label1(i).Top = (i \ 9 + 1) * x
    24.         Label1(i).Visible = True
    25.     Next i
    26.    
    27.     'this is just a matter of mathematical formulae
    28.     'customize the color pattern with it
    29.     For i = 0 To 256 Step 32
    30.     For j = 0 To 256 Step 32
    31.         Label1(i / 32 + j * 9 / 32).BackColor = RGB(i, j, 0)
    32.     Next j
    33.     Next i
    34.    
    35. End Sub
    Last edited by ZaidGS; May 15th, 2004 at 04:02 AM.

  7. #7

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    MarkT came the closest to what I'm looking for.

    but how do I change the colors?

    192,0,192
    255,255,255
    192,0,192
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  8. #8
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    You must mean something like this:

    Attached Images Attached Images  

  9. #9
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    play with these values to get what u want
    (from MarkT's code)

    VB Code:
    1. r = 255 - i
    2.         g = 0
    3.         b = i

    try:
    VB Code:
    1. r = 255 - i
    2.         g = i
    3.         b = 0

    dont forget to change the right hand side to be a reflection
    of left side.

  10. #10

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    Originally posted by DiGiTaIErRoR
    You must mean something like this:

    yes but on a picbox
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  11. #11
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    So you'll have to change:

    Form1.ForeColor
    and
    Form1.Line

    to:

    Picture1.ForeColor
    and
    Picture1.Line

    You could also add another param to the Gradient sub to pass a control to it.

  12. #12

    Thread Starter
    Hyperactive Member New to VB 6's Avatar
    Join Date
    Apr 2002
    Posts
    362
    could you please post the croped of code

    I assume that it goes something like

    VB Code:
    1. ,ByVal Sg As Long, ByVal Sb As Long, ByVal Fr As Long, ByVal Fg As Long, ByVal Fb As Long, ByVal x As Single)
    [VBCODE]
    Option Explicit
    Dim XXX As Porn
    Dim Wife As Nag

    Private Sub *****_Resize()
    On Error Resume Next
    Get Viagra
    End Sub
    [/VBCODE]

  13. #13
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    VB Code:
    1. ,ByVal Sg As Long, ByVal Sb As Long, ByVal Fr As Long, ByVal Fg As Long, ByVal Fb As Long)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width