|
8 | 8 | #declare rubik_cube_colors_classic = array[6] {Green, Red, Yellow, Blue, Orange, White};
|
9 | 9 |
|
10 | 10 |
|
11 |
| -// Generates a piece of cube with defined colors. |
| 11 | +// Generates a piece of cube. |
12 | 12 | //
|
13 |
| -// colors - array of six colors to be applied for the piece. Colors |
14 |
| -// are ordered in the same manner as for rubik_cube_create_cube() |
15 |
| -// macro. |
| 13 | +// dim - dimensions of the cube (3D vector). |
| 14 | +// pos - piece position (3D vector), where the coordinates are numbers |
| 15 | +// from 0 to corresponding dimension minus one. |
| 16 | +// gen_name - name of the file that contains the generator |
| 17 | +// implementation. |
| 18 | +// gen_param - a parameter which is passed to the generator. If |
| 19 | +// several parameters must be passed, they can be combined in an |
| 20 | +// array. |
| 21 | +// |
| 22 | +// Normally, a generator returns a piece which is embedded into a cube |
| 23 | +// with coordinates <0, 0, 0>, <1, 1, 1>. |
16 | 24 | //
|
17 | 25 | // Returns the generated piece.
|
18 |
| -#macro rubik_cube_create_piece(colors) |
19 |
| - object { |
20 |
| - Round_Box(<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5>, 0.1, 1) |
21 |
| - pigment { |
22 |
| - cubic colors[0], colors[1], colors[2], colors[3], colors[4], colors[5] |
23 |
| - } |
24 |
| - translate <0.5, 0.5, 0.5> |
25 |
| - } |
| 26 | +#macro rubik_cube_generate_piece(dim, pos, gen_name, gen_param) |
| 27 | + #include gen_name |
26 | 28 | #end
|
27 | 29 |
|
28 | 30 |
|
29 | 31 | // Returns a new cube (3D array of the generated cube pieces).
|
30 |
| -// Pieces of the cube are smaller cubes of 1 unit size, so a cube |
31 |
| -// 3x3x3 will have size of 3 units. |
| 32 | +// Pieces of the cube are created by the provided generator. |
32 | 33 | //
|
33 | 34 | // dim - dimensions of the cube (3D vector).
|
34 |
| -// colors - array of six colors to be applied for the cube. Colors are |
35 |
| -// ordered in the following way: right face (0); top face (1); back |
36 |
| -// face (2); left face (3); bottom face (4); front face (5). |
37 |
| -// Note. Interior faces are colored in black. |
38 |
| -#macro rubik_cube_create_cube(dim, colors) |
| 35 | +// gen_name - name of the file that contains the generator |
| 36 | +// implementation. |
| 37 | +// gen_param - parameter which is passed to the generator. |
| 38 | +#macro rubik_cube_generate_cube(dim, gen_name, gen_param) |
39 | 39 | #local rcube = array[dim.x][dim.y][dim.z];
|
40 | 40 | #for (pos_x, 0, dim.x - 1)
|
41 | 41 | #for (pos_y, 0, dim.y - 1)
|
42 | 42 | #for (pos_z, 0, dim.z - 1)
|
43 |
| - #local piece_colors = colors; |
44 |
| - #if (pos_x != 0) #local piece_colors[3] = Black; #end |
45 |
| - #if (pos_x != dim.x - 1) #local piece_colors[0] = Black; #end |
46 |
| - #if (pos_y != 0) #local piece_colors[4] = Black; #end |
47 |
| - #if (pos_y != dim.y - 1) #local piece_colors[1] = Black; #end |
48 |
| - #if (pos_z != 0) #local piece_colors[5] = Black; #end |
49 |
| - #if (pos_z != dim.z - 1) #local piece_colors[2] = Black; #end |
50 |
| - |
51 | 43 | #local rcube[pos_x][pos_y][pos_z] =
|
52 | 44 | object {
|
53 |
| - rubik_cube_create_piece(piece_colors) |
| 45 | + rubik_cube_generate_piece(dim, <pos_x, pos_y, pos_z>, gen_name, gen_param) |
54 | 46 | transform {
|
55 | 47 | translate <pos_x, pos_y, pos_z> - <dim.x / 2, dim.y / 2, dim.z / 2>
|
56 | 48 | }
|
|
63 | 55 | #end
|
64 | 56 |
|
65 | 57 |
|
| 58 | +// Returns a new cube (3D array of the generated cube pieces). |
| 59 | +// Pieces of the cube are smaller cubes of 1 unit size, so a cube |
| 60 | +// 3x3x3 will have size of 3 units. |
| 61 | +// |
| 62 | +// dim - dimensions of the cube (3D vector). |
| 63 | +// colors - array of six colors to be applied for the cube. Colors are |
| 64 | +// ordered in the following way: right face (0); top face (1); back |
| 65 | +// face (2); left face (3); bottom face (4); front face (5). |
| 66 | +// Note. Interior faces are colored in black. |
| 67 | +#macro rubik_cube_create_cube(dim, colors) |
| 68 | + rubik_cube_generate_cube(dim, "rubik-cube-generator-cube.inc", colors) |
| 69 | +#end |
| 70 | + |
| 71 | + |
66 | 72 | // Returns dimensions of the layers perpendicular to the provided
|
67 | 73 | // axis.
|
68 | 74 | //
|
|
0 commit comments