# Cube1

VTKExamples/Python/GeometricObjects/Cube1

### Description

Display a cube.

A nice simple example that demonstrates the operation of the VTK pipeline.

Other Languages

See (Cxx)

### Code

Cube1.py

    #!/usr/bin/env python

    import vtk

    def main():
        colors = vtk.vtkNamedColors()

        # Create a rendering window and renderer.
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetWindowName("Cube")
        renWin.AddRenderer(ren)

        # Create a renderwindowinteractor.
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        # Create cube.
        cube = vtk.vtkCubeSource()
        cube.Update()

        # mapper
        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInputData(cube.GetOutput())

        # Actor.
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.GetProperty().SetColor(colors.GetColor3d("Banana"))

        # Assign actor to the renderer.
        ren.AddActor(cubeActor)

        ren.ResetCamera()
        ren.GetActiveCamera().Azimuth(30)
        ren.GetActiveCamera().Elevation(30)
        ren.ResetCameraClippingRange()
        ren.SetBackground(colors.GetColor3d("Silver"))

        # Enable user interface interactor.
        iren.Initialize()
        renWin.Render()
        iren.Start()

    if __name__ == "__main__":
        main()