source: 2016/koodauskerho/VilleH/Untitled.scad @ 8415

Revision 8402, 3.8 KB checked in by jotapoti, 6 years ago (diff)
Line 
1// Mario Box template for OpenSCAD
2// (C) Copyright 2011, Brian Enigma <brian@netninja.com>
3// [http://netninja.com/fun/mariobox]
4//
5// Licensed under a Creative Commons Attribution, Non-Commercial, Share-Alike license.
6// For the detailed license, see [http://creativecommons.org/licenses/by-nc-sa/3.0/]
7//
8// This file is for feeding into OpenSCAD to produce an STL file
9// for 3D printing.  For more information about OpenSCAD, see [http://www.openscad.org/]
10//
11
12pixels = [
130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
150, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
160, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0,
170, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0,
180, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0,
190, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
200, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
210, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
220, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
230, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
240, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
250, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
260, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27];
28
29
30pixelCountX = 14;
31pixelCountY = 14;
32
33EDGE_LENGTH = 50;               // 5cm cube
34BOTTOM_THICKNESS = (0.4 * 3);   // about 3 layers on the bottom
35WALL_THICKNESS = 2;             // 2mm wall
36COLUMN_LENGTH = 4;              // corner support column
37PIXEL_SPACING_ADJUSTMENT = 2;   // Make this bigger to make the pixels smaller, but the space between pixels larger
38
39PIXEL_WIDTH = (EDGE_LENGTH - COLUMN_LENGTH * 2) / (pixelCountX + PIXEL_SPACING_ADJUSTMENT);
40PIXEL_HEIGHT = PIXEL_WIDTH; // (EDGE_LENGTH - BOTTOM_THICKNESS * 2) / (pixelCountY + PIXEL_SPACING_ADJUSTMENT);
41PIXEL_GRID_WIDTH = (EDGE_LENGTH - COLUMN_LENGTH * 2) / pixelCountX;
42PIXEL_GRID_HEIGHT = PIXEL_GRID_WIDTH; // (EDGE_LENGTH - BOTTOM_THICKNESS * 2) / pixelCountY;
43
44difference()
45{
46    union() // Box body (sides, bottom, support columns)
47    {
48        // Bottom
49        translate(v = [EDGE_LENGTH / -2, EDGE_LENGTH / -2, 0])
50            cube(size = [EDGE_LENGTH, EDGE_LENGTH, BOTTOM_THICKNESS]);
51        // Corner support columns
52        for (i = [0 : 90 : 270])
53            rotate(a = i, v = [0, 0, 1])
54                translate(v = [EDGE_LENGTH / 2 - COLUMN_LENGTH, EDGE_LENGTH / 2 - COLUMN_LENGTH, 0]) // center it
55                    cube(size = [COLUMN_LENGTH, COLUMN_LENGTH, EDGE_LENGTH]);
56        // Walls
57        for (i = [0 : 90 : 270])
58            rotate(a = i, v = [0, 0, 1])
59                translate(v = [EDGE_LENGTH / 2 - WALL_THICKNESS, EDGE_LENGTH / -2, 0])
60                    cube(size = [WALL_THICKNESS, EDGE_LENGTH, EDGE_LENGTH]);
61    }
62    for (i = [0 : 90 : 270]) // Apply pixel grid to all four sides
63    {
64        rotate(a = i, v = [0, 0, 1]) // Rotate to side
65        {
66            translate(v = [PIXEL_GRID_WIDTH * pixelCountX / -2, EDGE_LENGTH / -2 + WALL_THICKNESS + 2, (EDGE_LENGTH - (PIXEL_GRID_HEIGHT * pixelCountY)) / 2]) // Move over, centered on wall
67            {
68                rotate(a = 90, v = [1, 0, 0]) // Stand it upright
69                {
70                    union() // These are the pixels
71                    {
72                        for (posX = [0 : pixelCountX - 1])
73                        {
74                            for (posY = [0 : pixelCountY - 1])
75                            {
76                                if (pixels[((pixelCountY - 1) - posY) * pixelCountX + posX] == 1)
77                                {
78                                    translate(v = [PIXEL_GRID_WIDTH * posX, PIXEL_GRID_HEIGHT * posY, 2.8])
79                                        cube(size = [PIXEL_WIDTH, PIXEL_HEIGHT, WALL_THICKNESS * 4]);
80                                }
81                            }
82                        }
83                    }
84                }
85            }
86        }
87    }
88}
Note: See TracBrowser for help on using the repository browser.