VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertica

by Matt Beighton (3 Submissions)
Category: Graphics
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 1st August 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertical, horizontal or circle gradients. Improved

Rate Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertica



'This module creates a gradient effect over a form or picture box.
'At the moment it is a little bit slow, but i hope to improve that soon
'and it also gets removed if the form looses focus.  However I have not found
'a gradient module which overcomes this yet, either from me or anyone else


Public Sub Gradient(Object As Object, R1 As Integer, G1 As Integer, B1 As Integer, R2 As Integer, G2 As Integer, B2 As Integer, Direction As Integer)
Y = 0
Dim B, G, R As Double
Dim BI, GI, RI As Double
R = R1
G = G1
B = B1

If Direction = 0 Then GoTo Horizontal
If Direction = 1 Then GoTo Vertical
If Direction = 2 Then GoTo Sphere

Horizontal:
RI = (R2 - R1) / Object.Height
GI = (G2 - G1) / Object.Height
BI = (B2 - B1) / Object.Height
Do Until Y >= Object.Height
Object.Line (0, Y)-(Object.Width, Y), RGB(R, G, B)
Y = Y + 1
R = R + RI
G = G + GI
B = B + BI
Loop
Exit Sub

Vertical:
RI = (R2 - R1) / Object.Width
GI = (G2 - G1) / Object.Width
BI = (B2 - B1) / Object.Width
Do Until Y >= Object.Width
Object.Line (Y, 0)-(Y, Object.Height), RGB(R, G, B)
Y = Y + 1
R = R + RI
G = G + GI
B = B + BI
Loop
Exit Sub

Sphere:
Dim Radius
RI = (R2 - R1) / Object.Width
GI = (G2 - G1) / Object.Width
BI = (B2 - B1) / Object.Width
Radius = 1
Xpos = Object.ScaleWidth / 2
Ypos = Object.ScaleHeight / 2
Do Until Radius >= Object.Width
Object.Circle (Xpos, Ypos), Radius, RGB(R, G, B)
Object.Circle (Xpos, Ypos), Radius + 1, RGB(R + 1, G + 1, B + 1)
Object.Circle (Xpos, Ypos), Radius + 2, RGB(R + 1, G + 1, B + 1)
Radius = Radius + 3
R = R + (RI * 3)
G = G + (GI * 3)
B = B + (BI * 3)
Loop
Exit Sub

End Sub


Download this snippet    Add to My Saved Code

Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertica Comments

No comments have been posted about Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertica. Why not be the first to post a comment about Draws a gradient pattern on either a form or picturebox using a line command. Can do either vertica.

Post your comment

Subject:
Message:
0/1000 characters