# Colour Lines / Triangles etc different colours

**URL:** https://discourse.vtk.org/t/colour-lines-triangles-etc-different-colours/7033
**Category:** Support
**Created:** [November 1, 2021, 2:55pm UTC](https://discourse.vtk.org/t/colour-lines-triangles-etc-different-colours/7033 "2021-11-01T14:55:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Kevin\_Sweeney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kevin_sweeney/32/3935_2.png) [@Kevin\_Sweeney](https://discourse.vtk.org/u/Kevin_Sweeney)
#### Post date: [November 1, 2021, 2:55pm UTC](https://discourse.vtk.org/t/colour-lines-triangles-etc-different-colours/7033/1 "2021-11-01T14:55:19Z")

</div>

Hello, I was wondering if anyone could share an example where something like this was performed in Python. I am looking at colouring the lines / triangles etc. different colours.

[https://kitware.github.io/vtk-examples/site/Cxx/Modelling/Delaunay3DDemo/](https://kitware.github.io/vtk-examples/site/Cxx/Modelling/Delaunay3DDemo/)

I thought something like this would work as a starting point but the colours (all red for now) are not showing.

```auto
triangulator = vtk.vtkDelaunay2D()
triangulator.SetAlpha(alphaValue)

triangulator.SetInputDataObject(data)

cellData = vtk.vtkUnsignedCharArray()
cellData.SetName("colors")
cellData.SetNumberOfComponents(3)

for i in range(triangulator.GetOutput().GetNumberOfCells()):                
    cellData.InsertNextTypedTuple((255,0,0))

triangulator.GetOutput().GetCellData().SetScalars(cellData)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(triangulator.GetOutputPort())
mapper.SetScalarModeToUseCellData()

sProp = vtk.vtkProperty()
sProp.SetOpacity(1.0)
actor = vtk.vtkActor()
actor.SetProperty(sProp)
actor.SetMapper(mapper)

...

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 2, 2021, 1:59pm UTC](https://discourse.vtk.org/t/colour-lines-triangles-etc-different-colours/7033/2 "2021-11-02T13:59:15Z")

</div>

Hello,

You’re assigning three scalar values to each cell, that is, tuples valued 255,0,0. You didn’t tell VTK how to translate these into colors. You need to use a `vtkLookupTable` to do that:

```python
(...)
    lut = vtkLookupTable()

    mapper = vtkPolyDataMapper()
    mapper.SetLookupTable(lut)
    mapper.SetInputConnection(triangulator.GetOutputPort())
    mapper.SetScalarRange(0, 255)

    actor = vtkActor()
    actor.SetMapper(mapper)
(...)

```

Based on the complete example code here: [https://kitware.github.io/vtk-examples/site/Python/Rendering/Rainbow/](https://kitware.github.io/vtk-examples/site/Python/Rendering/Rainbow/)

regards,

Paulo
