how to convert numbers in colors?

  • Thread starter Thread starter Patbil
  • Start date Start date
P

Patbil

hello
I want to convert a matrix of results in decimal or real number into a
spectrum of colors (or grey scale if it's not possible) to make a "picture"
it's quiet urgent so a great thanks to who will success the challenge!
 
Tom Ogilvy a écrit :
Excel only supports the display of 56 colors in cells and in the default
pallete, I don't believe all those are unique.

a good place to start looking is here

http://www.mvps.org/dmcritchie/excel/colors.htm
too bad :-(
do you have any idea with another software (a free or classic would be
better)?
and (I'm a beginner) how can I do to apply these colors to the numbers (
grey levels could be a better approach if excel supports more levels of
blacks)
please be nice to help me and you will contribute to develop new
technologies of cell microscopy..... ;-)
 
As Tom says the Excel palette is limited to 56 colours, although you can
customize these as you wish (Tools / Options / Color).

You could add shapes with any of 16 million colours, sized and positioned as
required.

Sub WebSafe216()
Dim r As Long, g As Long, b As Long
Dim rw As Long, cl As Long
Dim shp As Shape

ActiveSheet.DrawingObjects.Delete

For r = 0 To 255 Step 51
cl = cl + 1
rw = 0
For g = 0 To 255 Step 51
For b = 0 To 255 Step 51
rw = rw + 1
With Cells(rw, cl)
Set shp = ActiveSheet.Shapes.AddShape(1, _
.Left, .Top, .Width, .Height)
End With
shp.Fill.ForeColor.RGB = RGB(r, g, b)

Next
Next
Next
End Sub

Regards,
Peter T
 
You can modify the default palette to include the colors you need. If you
need a pseudocolor "heatmap" then 25-30 colors is usually enough...


Here's some sample code which will remap a workbook palette to 52 "heatmap"
colors.
When assiging colors to objects in the workbook you just assign the
corresponding colorindex.

****************************************************************
Option Explicit


Sub Tester()
Dim i As Integer
updatecolors ActiveWorkbook
For i = 1 To 52
ActiveWorkbook.Sheets(1).Cells(i, 1).Interior.ColorIndex = i
Next i
End Sub




'Set the workbook color palette to cover the required range of shades
' Otherwise the map colors get remapped to the nearest palette color
Sub updatecolors(wb As Workbook)
Dim n As Integer
Application.ScreenUpdating = False
For n = 1 To 52
wb.Colors(n) = GetColor(n - 1, 0, 51)
Next n
wb.Colors(53) = RGB(255, 255, 255) 'white
Application.ScreenUpdating = True

End Sub


'Calculate a "heatmap" color (as a Long) for v, given a min (vmin) to max
(vmax)
' value range. Values are clipped to the nearest boundary if outside the
' range
Function GetColor(v, vmin, vmax) As Long

Dim dv As Single, rV As Single, gV As Single, bV As Single


rV = 255: gV = 255: bV = 255

If v < vmin Then v = vmin
If v > vmax Then v = vmax
dv = vmax - vmin

If v < (vmin + 0.25 * dv) Then
rV = 0
gV = 255 * (4 * (v - vmin) / dv)
ElseIf v < (vmin + 0.5 * dv) Then
rV = 0
bV = 255 * (1 + 4 * (vmin + 0.25 * dv - v) / dv)
ElseIf v < (vmin + 0.75 * dv) Then
rV = 255 * (4 * (v - vmin - 0.5 * dv) / dv)
bV = 0
Else
gV = 255 * (1 + 4 * (vmin + 0.75 * dv - v) / dv)
bV = 0
End If

GetColor = RGB(rV, gV, bV)


End Function


**********************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top