vb中颜色问题?

来源:百度知道 编辑:UC知道 时间:2024/07/06 17:20:49
vb中左侧一点温度知道(颜色能确定),右侧一点温度知道(颜色也能确定),从左到右100个点如何让颜色值也过度过去呢?

把刚才的代码改了一下,现在简单多了,你试试
C1是起始颜色,C2是终止颜色,可以自己指定

Function NewColor(Color1 As Long, Color2 As Long, i As Integer) As Long
Dim C1 As Long, C2 As Long, j As Integer
For j = 0 To 2
C1 = (Color1 And 255 * 256 ^ j) / 256 ^ j
C2 = (Color2 And 255 * 256 ^ j) / 256 ^ j
NewColor = NewColor Or (C1 + (C2 - C1) * i \ 100) * 256 ^ j
Next
End Function

Private Sub Form_Click()
Dim i As Single, C As Integer, C1 As Long, C2 As Long
C1 = vbRed
C2 = vbBlue
Const PI = 3.1415926
Form1.DrawWidth = 10
Form1.Scale (-2 * PI, 1)-(2 * PI, -1)

Form1.CurrentX = -2 * PI
Form1.CurrentY = Sin(-2 * PI)
For i = -2 * PI To 2 * PI Step 0.01
' C = (i + 2 * PI) * 100 / (4 * PI) '横向渐变
C = (Sin(i) + 1) * 100 / 2 '纵向渐变
Line -(i, Sin(i)), NewColor(C1, C2, C)
Next
End Sub