========================= Material -- colored faces ========================= .. _material_faces: .. index:: .. |a| image:: /images/all/blender-basics/h_material/faces-colored-100.png Objectives ========== .. tabularcolumns:: | c | l | :border: none +-------+-------------------------------------------------------------------------+ | |a| | In the last station we applied the material to the hole object. Now we | | | select a few faces to color only parts of the object surface. | +-------+-------------------------------------------------------------------------+ Instructions ============ :Tasks: 1. Create a cylinder and change the color of the top and bottom base. 2. Create a chessboard like in this image: .. image:: /images/all/blender-basics/h_material/chessboard.png 3. | Create an set of tokens for the game draughts (or checkers) an the board. .. figure:: /images/all/blender-basics/h_material/Boilly-Checkers-1803.jpg :width: 300px | Louis-Léopold Boilly (1761–1845) | Painting of a family game of checkers | (»jeu des dames«) A colored cube ============== To be able to color of one or more faces, select them. At first the script: .. literalinclude:: files/colored_cube.py :language: python :emphasize-lines: 0 Name the colors =============== Every color should have a name. This is the first Step. .. literalinclude:: files/colored_cube.py :language: python :lines: 10-12 Add the materials ================= This is little bit tricky, to add a color for each face. Step by step: - All faces of an object (a cube has six) are saved in a list of polygons. - In a for loop wie iterate over this list. - The index number from the list is divided by three with the modulo operator. So we get three possible results 0, 1 or 2. - Each number is connected with a color. - Finally the color number is assigned to the material index, because materials are also managed with an index. .. literalinclude:: files/colored_cube.py :language: python :lines: 31-33 :hint: In old tutorials before 2.68 faces are selected from a list named *faces*. Now the new list and name is *polygons*.