-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetHotColdColor.rvb
More file actions
61 lines (50 loc) · 1.75 KB
/
Copy pathGetHotColdColor.rvb
File metadata and controls
61 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' HotColdColors.rvb -- May 2009
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Return a RGB color given a scalar v in the range [vmin, vmax].
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetHotColdColor(v, vmin, vmax)
Dim r, g, b, dv
r = 1.0 : g = 1.0 : b = 1.0 'white
If (v < vmin) Then v = vmin
If (v > vmax) Then v = vmax
dv = vmax - vmin
If (v < (vmin + 0.25 * dv)) Then
r = 0
g = 4 * (v - vmin) / dv
ElseIf (v < (vmin + 0.5 * dv)) Then
r = 0
b = 1 + 4 * (vmin + 0.25 * dv - v) / dv
ElseIf (v < (vmin + 0.75 * dv)) Then
r = 4 * (v - vmin - 0.5 * dv) / dv
b = 0
Else
g = 1 + 4 * (vmin + 0.75 * dv - v) / dv
b = 0
End If
GetHotColdColor = RGB(Int(r*255), Int(g*255), Int(b*255))
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Test procedure creates a "hot-to-cold" color ramp mesh.
' To see the results, set a viewport to "rendered" display.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub TestGetHotColdColor()
' Mesh with 200 vertices and 100 faces
Dim v(199), f(99), c(199), ub, i
' Fill in arrays
ub = UBound(v)
For i = 0 To UBound(v) Step 2
v(i) = Array(i/2,0,0)
v(i+1) = Array(i/2,10,0)
c(i) = GetHotColdColor(i,0,ub)
c(i+1) = c(i)
f(i/2) = Array(i,i+2,i+3,i+1)
Next
' Create the mesh object
Call Rhino.AddMesh(v,f,,,c)
End Sub