include ; red_color = [0.69, 0.15, 0.15]; $fn=64; /** * Creates a Swiss cross shape with optional background. * * @param w - Width of the cross (number, positive) * @param h - Height of extrusion (number, positive) * @param bg - If true, adds a red background (boolean, default: true) * * Usage: * swiss_x(w, h, bg); * * Example: * * swiss_x(50, 10); // Cross without background * swiss_x(50, 10, true); // Cross with red background */ module swiss_x(w, h, bg = true) { // Parameter validation assert(is_num(w) && w > 0, "Width 'w' must be a positive number."); assert(is_num(h) && h > 0, "Height 'h' must be a positive number."); assert(is_bool(bg), "Background 'bg' must be a boolean."); // Calculate dimensions l = w * 80/110; // Length of cross arm t = w * 24/110; // Thickness of cross arm // Half dimensions for point calculation hw = l / 2; // Half width ht = t / 2; // Half thickness // Points for the cross shape pts = [ [-hw, ht], // 0 [-ht, ht], // 1 [-ht, hw], // 2 [ ht, hw], // 3 [ ht, ht], // 4 [ hw, ht], // 5 [ hw,-ht], // 6 [ ht,-ht], // 7 [ ht,-hw], // 8 [-ht,-hw], // 9 [-ht,-ht], // 10 [-hw,-ht] // 11 ]; // Draw white cross color("white") linear_extrude(h) polygon(pts); // Optional red background if (bg) color("red") linear_extrude(h/2) square(w, center=true); } // Example usage //swiss_x(w = 8, h = 1, bg = false); // Extrude to 10 units in height module swiss_x_2(w, h, bg = true) { // Calculate dimensions l = w * 80/110; // Length of cross arm t = w * 24/110; // Thickness of cross arm w2 = l-t; echo ("l",l); echo ("t",t); echo ("x",x); // Half dimensions for point calculation hw = l / 2; // Half width ht = t / 2; // Half thickness // Points for the cross shape pts = [ [-hw, ht], // 0 [-ht, ht], // 1 [-ht, hw], // 2 [ ht, hw], // 3 [ ht, ht], // 4 [ hw, ht], // 5 [ hw,-ht], // 6 [ ht,-ht], // 7 [ ht,-hw], // 8 [-ht,-hw], // 9 [-ht,-ht], // 10 [-hw,-ht] // 11 ]; x = w * 26/110; // Thickness of cross arm x1 = hw + ht; //down(h) %swiss_x( w = w, h = h, bg = false); f = 1.8; d = 0.14; s1 = t*1.2; s2 = (hw-ht) * 1.1; r = w * 3/110; linear_extrude(h) difference() { //color (red_color) round2d(r=3) { color (red_color) round2d(r=r) { translate([0,x1,0]) square((f-0*d) * s1 *0.8,center=true); translate([x,x,0]) square((f-1*d) * s2,center=true,anchor=LEFT); translate([x1,0,0]) square((f-2*d) * s1,center=true); translate([x,-x,0]) square((f-3*d) * s2,center=true,anchor=LEFT); translate([0,-x1,0]) square((f-4*d) * s1,center=true); translate([-x,-x,0]) square((f-5*d) *s2,center=true,anchor=LEFT); translate([-x1,0,0]) square((f-6*d) * s1,center=true); translate([-x,x,0]) square( (f-7*d) * s2* 1.1,center=true,anchor=LEFT); }; round2d(r=r) polygon(pts); } } //swiss_x_2(w = 110, h = 1, bg = false); // Extrude to 10 units in height swiss_x_2(w = 10, h = 2, bg = false); // Extrude to 10 units in height