|
-
Aug 2nd, 2009, 05:40 PM
#1
Thread Starter
Member
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:
SetPixel hdc, 0, 0, &HE7EBEE SetPixel hdc, 1, 0, &HD9DADC SetPixel hdc, 2, 0, &HCFCFD1 SetPixel hdc, 3, 0, &HCCCCCC SetPixel hdc, 4, 0, &HCCCCCC SetPixel hdc, 5, 0, &HCCCCCC SetPixel hdc, 6, 0, &HCCCCCC SetPixel hdc, 7, 0, &HCCCCCC SetPixel hdc, 8, 0, &HCCCCCC SetPixel hdc, 9, 0, &HCCCCCC '...and it goes on... SetPixel hdc, 128, 0, &HCBCBCB SetPixel hdc, 129, 0, &HCFCFCF SetPixel hdc, 130, 0, &HD9DADC 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:
SetPixel hdc, 0, 0, &HE7EBEE SetPixel hdc, 1, 0, &HD9DADC SetPixel hdc, 2, 0, &HCFCFD1 DrawLine 3, 0, 127, 0, &HCCCCCC ' Drawline(X1, Y1, X2, Y2, COLOR) SetPixel hdc, 128, 0, &HCBCBCB SetPixel hdc, 129, 0, &HCFCFCF SetPixel hdc, 130, 0, &HD9DADC 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.
-
Aug 2nd, 2009, 06:04 PM
#2
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.
-
Aug 2nd, 2009, 07:01 PM
#3
Thread Starter
Member
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
-
Aug 3rd, 2009, 05:22 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|