Results 1 to 4 of 4

Thread: Looking for help to condense this code...

  1. #1

    Thread Starter
    Member mOBSCENE's Avatar
    Join Date
    Mar 2009
    Location
    New Jersey
    Posts
    46

    Looking for help to condense this code...

    I have 4488 lines of SetPixel's because i have a button that i'm making without using a picture. (but this is just for one out of a few pictures)

    I want to condense the lines that are like...

    vb Code:
    1. SetPixel hdc, 0, 0, &HE7EBEE
    2. SetPixel hdc, 1, 0, &HD9DADC
    3. SetPixel hdc, 2, 0, &HCFCFD1
    4. SetPixel hdc, 3, 0, &HCCCCCC
    5. SetPixel hdc, 4, 0, &HCCCCCC
    6. SetPixel hdc, 5, 0, &HCCCCCC
    7. SetPixel hdc, 6, 0, &HCCCCCC
    8. SetPixel hdc, 7, 0, &HCCCCCC
    9. SetPixel hdc, 8, 0, &HCCCCCC
    10. SetPixel hdc, 9, 0, &HCCCCCC
    11. '...and it goes on...
    12. SetPixel hdc, 128, 0, &HCBCBCB
    13. SetPixel hdc, 129, 0, &HCFCFCF
    14. SetPixel hdc, 130, 0, &HD9DADC
    15. SetPixel hdc, 131, 0, &HE6EAEB

    ...and so on. it goes back to other colors at the end, and then new colors start at the next Y coordinate.

    I need the code to make all the lines with the same color like so

    vb Code:
    1. SetPixel hdc, 0, 0, &HE7EBEE
    2. SetPixel hdc, 1, 0, &HD9DADC
    3. SetPixel hdc, 2, 0, &HCFCFD1
    4. DrawLine 3, 0, 127, 0, &HCCCCCC
    5. ' Drawline(X1, Y1, X2, Y2, COLOR)
    6. SetPixel hdc, 128, 0, &HCBCBCB
    7. SetPixel hdc, 129, 0, &HCFCFCF
    8. SetPixel hdc, 130, 0, &HD9DADC
    9. SetPixel hdc, 131, 0, &HE6EAEB

    (this is an example, and i've tried for hours on a way to do it...no methods have worked. i've asked several of my buddies from MSN...theyre stumped as well.

    I'd do it manually if i didnt have so many to do, which is why i need a code maker xD

    Thanks guys
    Last edited by mOBSCENE; Aug 2nd, 2009 at 05:43 PM.

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Looking for help to condense this code...

    Well if you want it at least a little neater, you could always add a module and make a multidimensional array to store the information.
    Then in the control add some code to loop through the array.

    eg. (assuming picture is 500x500)
    Code:
    Public dImage(499,499) As Long
    
    Public Sub InitializeImg ()
    
        Dim i As Long
    
        dImage(0, 0) = &HE7EBEE
        dImage(1, 0) = &HD9DADC
        dImage(2, 0) = &HCFCFD1
    
        dImage(3, 0) = &HCCCCCC
        dImage(4, 0) = &HCCCCCC
        dImage(5, 0) = &HCCCCCC
        dImage(6, 0) = &HCCCCCC
        dImage(7, 0) = &HCCCCCC
    
        '// Instead of doing this you can actually use the following so you would
        '// still have some optimizing...
        
        For i = 3 To 7
            dImage(i, 0) = &HCCCCCC
        Next i
    
        '// etc.
    
    End Sub
    And then for the draw code the following.
    Code:
    Public Sub DrawImage ()
    
        Dim i As Long
        Dim j As Long
    
        For i  = 0 To 499
            For j = 0 To 499
                SetPixel hdc, i, j, dImage(i, j)
            Next j
        Next i
    
    End Sub
    Edit: Sorry misread the question, but this is also a way to get rid of some code ;-)
    Delete it. They just clutter threads anyway.

  3. #3

    Thread Starter
    Member mOBSCENE's Avatar
    Join Date
    Mar 2009
    Location
    New Jersey
    Posts
    46

    Re: Looking for help to condense this code...

    nooo, i have the picture whole. the setpixel things are a string i'm trying to organize and condense :S

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Looking for help to condense this code...

    You just need a basic loop, eg:
    Code:
    Dim lngX as Long
    
      For lngX = 3 to 127
        SetPixel hdc, lngX, 0, &HCCCCCC
      Next lngX


    If you particularly want to use a sub as you implied, it would be like this:
    Code:
    Sub Drawline(hdc as Long, X1 as Long, Y1 as Long, X2 as Long, Y2 as Long, COLOR as Long)
    Dim lngX as Long, lngY as Long
    
      For lngX = X1 to X2
        For lngY = Y1 to Y2
          SetPixel hdc, lngX, lngY, COLOR 
        Next lngY
      Next lngX
    
    End Sub
    example usage:
    Code:
    DrawLine hdc, 3, 0, 127, 0, &HCCCCCC

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