// Exemplo de arquivo de descricao de cena para POV-ray // Last edited on 2023-12-23 03:51:13 by stolfi // ====================================================================== // CORES E TEXTURAS background{ color rgb < 0.75, 0.80, 0.85 > } #declare tx_plastico = texture{ pigment{ color rgb < 0.10, 0.80, 1.00 > } finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 } } // ====================================================================== // BASIC #declare roleta = seed(27); #declare M = 4; #declare N = 3; // ====================================================================== // TANQUES #declare TANK_SIZE = 2; #declare TANK_OFFSET = 1; #declare BASE_SIZE = 0.5; #declare cylinder_tank = union { box{ <-TANK_SIZE / 2, -TANK_SIZE / 2, 0>, } cylinder { <0, 0, 0>, <0, 0, TANK_SIZE>, TANK_SIZE / 4 } texture { tx_plastico } } #declare cone_tank = union { cylinder{ <0, 0, 0>, <0, 0, 2 * TANK_SIZE / 3>, TANK_SIZE / 2 } cone { <0, 0, 2 * TANK_SIZE / 3>, TANK_SIZE / 2 <0, 0, TANK_SIZE>, 0 } texture { tx_plastico } } #declare sphere_tank = union { sphere { <0, 0, TANK_SIZE / 3>, TANK_SIZE / 3 } sphere { <0, 0, 2 * TANK_SIZE / 3>, TANK_SIZE / 3 } texture { tx_plastico } } // ====================================================================== // PINS #declare NUMBER_OF_PINS = 3 * M * N; #declare PINS = array[NUMBER_OF_PINS][4]; #declare PINS_DIRECTIONS = array[NUMBER_OF_PINS][4]; #declare CURRENT_VERTEX = 0; #declare CURRENT_PIN = 0; #declare PIN_SIZE = 0.2; #declare PIN_LENGTH = 0.5; #macro finalize_vertex_pin() #declare CURRENT_VERTEX = CURRENT_VERTEX + 1; #declare CURRENT_PIN = 0; #end #macro tube_IO(from, to) object { cylinder { from, to, PIN_SIZE } texture { tx_plastico } } #declare PINS[CURRENT_VERTEX][CURRENT_PIN] = to; #declare PINS_DIRECTIONS[CURRENT_VERTEX][CURRENT_PIN] = 2 * (to - from); #declare CURRENT_PIN = CURRENT_PIN + 1; #end #macro full_4th_degree_vertex(position) union { object { cylinder_tank translate position } #local tube_center = position + <0, 0, BASE_SIZE / 2>; tube_IO(tube_center, tube_center + ) tube_IO(tube_center, tube_center - ) tube_IO(tube_center, tube_center + <0, PIN_LENGTH + TANK_SIZE / 2, 0>) tube_IO(tube_center, tube_center - <0, PIN_LENGTH + TANK_SIZE / 2, 0>) finalize_vertex_pin() } #end #macro full_3th_degree_vertex(position) union { object { cone_tank translate position } #local tube_center = position + <0, 0, 2 * TANK_SIZE / 3>; tube_IO(tube_center, tube_center - ) tube_IO(tube_center, tube_center + ) tube_IO(tube_center, tube_center + <0, -(PIN_LENGTH + TANK_SIZE / 2), 0>) finalize_vertex_pin() } #end #macro full_2th_degree_vertex(position) union { object { sphere_tank translate position } #local tube_center = position + <0, 0, TANK_SIZE / 2>; tube_IO(tube_center, tube_center + <0, 0, PIN_LENGTH + TANK_SIZE / 2>) tube_IO(tube_center, tube_center - <0, 0, PIN_LENGTH + TANK_SIZE / 2>) finalize_vertex_pin() } #end #macro full_1th_degree_vertex(position) union { object { sphere { <0, 0, TANK_SIZE / 2>, TANK_SIZE / 2 } translate position texture { tx_plastico } } #local tube_center = position + <0, 0, TANK_SIZE / 2>; tube_IO(tube_center, tube_center + <0, PIN_LENGTH + TANK_SIZE / 2, 0>) finalize_vertex_pin() } #end // ====================================================================== // INTERPOLACAO #macro interpola1(currentT, t0, v0, t1, v1) #local ss = (currentT - t0) / (t1 - t0); #local vv = (1 - ss) * v0 + ss * v1; vv #end #macro interpola3(currentT, t0, t1, v0, v1, v2, v3) #local v01 = interpola1(currentT, t0, v0, t1, v1); #local v12 = interpola1(currentT, t0, v1, t1, v2); #local v23 = interpola1(currentT, t0, v2, t1, v3); #local v012 = interpola1(currentT, t0, v01, t1, v12); #local v123 = interpola1(currentT, t0, v12, t1, v23); #local v0123 = interpola1(currentT, t0, v012, t1, v123); v0123 #end #macro interpola3_multi(tt, n, initial, p1, p2, final) #local k = int(tt); #local patchStart = initial; #local patchFinish = final; #if (k > 0) #local patchStart = (p2[k - 1] + p1[k]) / 2; #end #if (k < n - 1) #local patchFinish = (p2[k] + p1[k + 1]) / 2; #end #local result = interpola3(tt, k, k + 1, patchStart, p1[k], p2[k], patchFinish); result #end #macro testa_interpola1(p0, p1, n, raio) union { #local CURRENT_K = 0; #while (CURRENT_K <= n) #local centro = interpola1(CURRENT_K, 0, p0, n, p1); sphere { centro, raio } #local CURRENT_K = CURRENT_K + 1; #end texture { tx_plastico } } #end #macro testa_interpola3(p0, p1, v0, v1, n, raio) union { #local CURRENT_K = 0; #while (CURRENT_K <= n) #local centro = interpola3(CURRENT_K, 0, n, p0, v0, v1, p1); sphere { centro, raio } #local CURRENT_K = CURRENT_K + 1; #end texture { tx_plastico } } #end #macro testa_interpola3_multi(numberOfSegments, initial, p1, p2, final, numberOfCylinders, raio) union { #local CURRENT_K = 0; #while (CURRENT_K < numberOfSegments) #local centro = interpola3_multi(CURRENT_K, numberOfSegments, initial, p1, p2, final); sphere { centro, raio } #local CURRENT_K = CURRENT_K + numberOfSegments / numberOfCylinders; #end texture{ pigment{ color rgb < 1, 0.11, 0.32 > } } } #end // ====================================================================== // Random Utils! #declare rng = seed(10); #macro random_inside(BOX_SIZE) #local randomPos = ( - 0.5 * <1, 1, 1>) * BOX_SIZE / 2; randomPos #end #macro randomize_positions(NUMBER_VERTICES, MAP_SIZE) #local positions = array[NUMBER_VERTICES]; #local current = 0; #while (current < NUMBER_VERTICES) #local positions[current] = random_inside(MAP_SIZE); #local current = current + 1; #end positions #end // ====================================================================== // Tubes #macro conectar(NUMBER_CONTROL_POINTS, INITIAL_POINT, INITIAL_TANGENT, FINAL_POINT, FINAL_TANGENT, MAP_SIZE, SPHERES_PER_SEGMENT) #local controls1 = randomize_positions(NUMBER_CONTROL_POINTS, MAP_SIZE); #local controls2 = randomize_positions(NUMBER_CONTROL_POINTS, MAP_SIZE); #local controls1[0] = INITIAL_TANGENT; #local controls2[NUMBER_CONTROL_POINTS - 1] = FINAL_TANGENT; // #local numberOfSpheres = NUMBER_CONTROL_POINTS * SPHERES_PER_SEGMENT; union { #local CURRENT_K = 0; #while (CURRENT_K < NUMBER_CONTROL_POINTS) #local centro = interpola3_multi(CURRENT_K, NUMBER_CONTROL_POINTS, INITIAL_POINT, controls1, controls2, FINAL_POINT); sphere { centro, PIN_SIZE } #local CURRENT_K = CURRENT_K + 1 / SPHERES_PER_SEGMENT; #end texture{ pigment{ color rgb < 1, 0.11, 0.32 > } } } #end #macro calculate_degrees(NUMBER_VERTICES, NUMBER_EDGES, ORIGINS, DESTINATIONS) #local vertices_degrees = array[NUMBER_VERTICES]; #local current = 0; #while (current < NUMBER_VERTICES) #local vertices_degrees[current] = 0; #local current = current + 1; #end #local current = 0; #while (current < NUMBER_EDGES) #local vertices_degrees[ORIGINS[current]] = vertices_degrees[ORIGINS[current]] + 1; #local vertices_degrees[DESTINATIONS[current]] = vertices_degrees[DESTINATIONS[current]] + 1; #local current = current + 1; #end // Why do I not need to divide by 2???? // #local current = 0; // #while (current < NUMBER_VERTICES) // #local vertices_degrees[current] = int(vertices_degrees[current] / 2); // #local current = current + 1; // #end vertices_degrees #end #macro gera_grafo(NUMBER_VERTICES, NUMBER_EDGES, ORIGINS, DESTINATIONS, MAP_SIZE, CONTROL_POINTS_PER_EDGE) #local vertices_degrees = calculate_degrees(NUMBER_VERTICES, NUMBER_EDGES, ORIGINS, DESTINATIONS); #local positions = randomize_positions(NUMBER_VERTICES, MAP_SIZE); union { #local current = 0; #while (current < NUMBER_VERTICES) #if (vertices_degrees[current] = 1) full_1th_degree_vertex(positions[current]) #end #if (vertices_degrees[current] = 2) full_2th_degree_vertex(positions[current]) #end #if (vertices_degrees[current] = 3) full_3th_degree_vertex(positions[current]) #end #if (vertices_degrees[current] = 4) full_4th_degree_vertex(positions[current]) #end #local current = current + 1; #end } union { #local pinTracking = array[NUMBER_VERTICES]; #local current = 0; #while (current < NUMBER_VERTICES) // prof #local pinTracking[current] = 0; #local current = current + 1; #end #local current = 0; #while (current < NUMBER_EDGES) #local from = ORIGINS[current]; #local to = DESTINATIONS[current]; #local fromPinIndex = pinTracking[from]; #local toPinIndex = pinTracking[to]; conectar(CONTROL_POINTS_PER_EDGE, PINS[from][fromPinIndex], PINS[from][fromPinIndex] + PINS_DIRECTIONS[from][fromPinIndex], PINS[to][toPinIndex], PINS[to][toPinIndex] + PINS_DIRECTIONS[to][toPinIndex], MAP_SIZE, 500) #local pinTracking[from] = pinTracking[from] + 1; #local pinTracking[to] = pinTracking[to] + 1; #local current = current + 1; #end } #end // ====================================================================== // Test bezier #macro half_heart(sign) #local testP1 = array[2]; #local testP2 = array[2]; #local testP1[0] = <0, 0, 3>; #local testP2[0] = <0, sign * 5, 3>; #local testP1[1] = <0, sign * 5, -3>; #local testP2[1] = <0, 0, -3.5>; testa_interpola3_multi(2, <0, 0, 0>, testP1, testP2, <0, 0, -6>, 300, 0.2) #end #macro heart() half_heart(1) half_heart(-1) #end #declare nv_grafo = 7; #declare ne_grafo = 6; #declare D = 50; #declare raio = 1.500; #include "eixos.inc" union{ // object{ eixos(0.25*D + 3.00) } #local org = array[ne_grafo]; #local dst = array[ne_grafo]; #local org[0] = 0; #local dst[0] = 1; #local org[1] = 1; #local dst[1] = 2; #local org[2] = 2; #local dst[2] = 3; #local org[3] = 3; #local dst[3] = 5; #local org[4] = 3; #local dst[4] = 4; #local org[5] = 5; #local dst[5] = 6; gera_grafo(nv_grafo, ne_grafo, org, dst, D, 3) } #declare cmin = -0.25*< D, D, D >; #declare cmax = +0.25*< D, D, D >; #include "gaiola.inc" // object{ gaiola(cmin,cmax) } #declare centro_cena = (cmin + cmax)/2; #declare raio_cena = 0.50*vlength(cmax-cmin); #declare dist_camera = 7*raio_cena; #include "camlight.inc" #declare dir_camera = < 14.00, 7.00, 4.00 >; #declare intens_luz = 1.20; camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)