Last active
June 12, 2020 10:46
-
-
Save javipacheco/3253e9772b4a5e199be437054fea41eb to your computer and use it in GitHub Desktop.
Script OpenScad para crear objetos 3D desde un array de pixeles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mono | |
// data = [[-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1], [-1, -1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, -1, -1, -1], [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, -1], [1, 1, 0, 1, 3, 2, 1, 1, 1, 3, 2, 1, 0, 1, 1, -1], [-1, 1, 0, 1, 2, 2, 1, 1, 1, 2, 2, 1, 0, 1, -1, -1], [-1, -1, 0, 1, 4, 4, 1, 1, 1, 4, 4, 1, 0, -1, -1, -1], [-1, -1, -1, 0, 1, 1, 1, 2, 1, 1, 1, 0, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1], [-1, 1, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1], [-1, 0, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1], [-1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, -1, -1, -1, -1, -1], [-1, -1, 0, 0, 0, 0, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 0, 1, 1, 0, 1, 1, 0, 0, -1, -1, -1, -1]]; | |
// height = [3, 1, 2, 1, 1]; | |
// mario flower power | |
// data = [[-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1], [-1, -1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, -1, -1], [-1, 0, 1, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, 1, 0, -1], [0, 1, 1, 3, 3, 2, 0, 2, 2, 0, 2, 3, 3, 1, 1, 0], [0, 1, 1, 3, 2, 5, 0, 5, 5, 0, 5, 2, 3, 1, 1, 0], [0, 1, 1, 3, 3, 2, 0, 2, 2, 0, 2, 3, 3, 1, 1, 0], [-1, 0, 1, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, 1, 0, -1], [-1, -1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, -1, -1], [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1], [-1, 0, 0, -1, -1, -1, 0, 4, 4, 0, -1, -1, -1, 0, 0, -1], [0, 4, 4, 0, 0, -1, 0, 4, 4, 0, -1, 0, 0, 4, 4, 0], [0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 4, 0], [0, 4, 4, 4, 4, 4, 0, 4, 4, 0, 4, 4, 4, 4, 4, 0], [-1, 0, 4, 4, 4, 4, 0, 4, 4, 0, 4, 4, 4, 4, 0, -1], [-1, -1, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, -1, -1], [-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1]]; | |
// height = [3, 1, 2, 1, 1, 1]; | |
// cohete | |
// data = [[0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [0, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [0, 1, 2, 2, 5, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 0, 2, 2, 5, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 0, 5, 5, 1, 5, 5, 5, 0, 0, 0, 0, 0, 0, -1, -1], [-1, -1, 0, 1, 5, 2, 2, 5, 5, 0, 1, 1, 1, 0, -1, -1], [-1, -1, 0, 5, 5, 2, 2, 5, 5, 5, 0, 1, 1, 0, -1, -1], [-1, -1, -1, 0, 5, 5, 5, 2, 5, 5, 5, 0, 0, -1, -1, -1], [-1, -1, -1, -1, 0, 5, 5, 5, 5, 5, 5, 0, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 5, 5, 5, 5, 5, 0, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 1, 0, 5, 5, 5, 0, 5, 3, 3, 3, -1], [-1, -1, -1, -1, 0, 1, 1, 0, 0, 0, 5, 3, 4, 4, 3, -1], [-1, -1, -1, -1, 0, 1, 0, -1, -1, -1, 3, 4, 4, 4, 3, 3], [-1, -1, -1, -1, 0, 0, -1, -1, -1, -1, 3, 4, 4, 4, 4, 3], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 4, 4, 3], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3]]; | |
// height = [3, 1, 2, 2, 1, 1]; | |
// estrella | |
// data = [[-1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, 0, 1, 1, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, 0, 1, 1, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0], [-1, 0, 2, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 2, 0, -1], [-1, -1, 0, 2, 1, 1, 0, 1, 1, 0, 1, 1, 2, 0, -1, -1], [-1, -1, -1, 0, 2, 1, 1, 1, 1, 1, 1, 2, 0, -1, -1, -1], [-1, -1, -1, 0, 2, 1, 1, 1, 1, 1, 1, 2, 0, -1, -1, -1], [-1, -1, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, -1, -1], [-1, -1, 0, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, 0, -1, -1], [-1, 0, 2, 1, 1, 2, 2, 0, 0, 2, 2, 1, 1, 2, 0, -1], [-1, 0, 2, 2, 2, 0, 0, -1, -1, 0, 0, 2, 2, 2, 0, -1], [0, 2, 2, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 2, 2, 0], [0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0]]; | |
// height = [3, 1, 2]; | |
// castillo | |
// data = [[-1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, -1, -1, -1, -1], [-1, -1, 0, 1, 1, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, -1, -1, -1, -1, -1], [-1, -1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, -1, -1, -1, -1, -1], [-1, -1, 0, 2, 2, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, -1, -1, -1, -1, -1], [-1, -1, 0, 2, 0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, -1, -1, -1], [-1, -1, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 0, -1, -1], [-1, 0, 0, 0, 2, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 0, -1, -1], [0, 0, 1, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 2, 0, 2, 2, 0, -1, -1], [0, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 0, -1, -1], [0, 1, 1, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, -1, -1], [0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, -1, -1], [0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 0, -1, -1], [0, 2, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 0, 0], [0, 2, 0, 1, 0, 2, 2, 0, 0, 0, 0, 0, 2, 2, 0, 1, 0, 1, 1, 0], [0, 2, 0, 1, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 1, 0, 1, 1, 0], [0, 2, 0, 1, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 1, 0, 0, 0, 0], [0, 2, 0, 1, 0, 2, 2, 2, 0, 0, 0, 2, 2, 2, 0, 1, 0, 2, 2, 0], [0, 2, 0, 1, 0, 2, 2, 2, 0, 0, 0, 2, 2, 2, 0, 2, 0, 2, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]; | |
// height = [3, 1, 1]; | |
// espada minecraft | |
// data = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 2, 0], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 2, 3, 0], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 2, 3, 0, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 2, 3, 0, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 2, 3, 0, -1, -1, -1], [-1, -1, 0, 0, -1, -1, -1, 0, 3, 2, 3, 0, -1, -1, -1, -1], [-1, -1, 0, 2, 0, -1, 0, 3, 2, 3, 0, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 2, 0, 3, 2, 3, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 2, 0, 2, 3, 0, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 1, 0, 2, 2, 0, -1, -1, -1, -1, -1, -1, -1], [-1, -1, 0, 1, 0, -1, 0, 0, 2, 0, -1, -1, -1, -1, -1, -1], [0, 0, 1, 0, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1], [0, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]; | |
// height = [3, 1, 1, 1]; | |
// zorro | |
// data = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1], [-1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1], [-1, 0, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 1, 0, -1], [-1, 0, 1, 3, 1, 1, 0, -1, -1, -1, -1, -1, -1, 0, 1, 1, 3, 1, 0, -1], [-1, 0, 1, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 3, 3, 1, 0, -1], [-1, 0, 1, 3, 3, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 3, 3, 1, 0, -1], [-1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 2, 0, 1, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, -1], [-1, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, -1], [-1, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, -1], [-1, -1, 0, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, -1, -1], [-1, -1, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, -1, -1], [-1, -1, -1, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2, 2, 2, 0, 0, -1, -1, -1], [-1, -1, -1, -1, -1, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]; | |
// height = [3, 2, 1, 3]; | |
// space invaders 1 | |
// data = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 1, 1, 0, -1, -1, -1, -1], [-1, -1, -1, 0, 1, 1, 1, 1, 0, -1, -1, -1], [-1, -1, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1], [-1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, -1], [-1, -1, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1], [-1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, -1], [-1, -1, 0, 1, 0, -1, -1, 0, 1, 0, -1, -1], [-1, -1, -1, 0, -1, -1, -1, -1, 0, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]; | |
// height = [3, 2]; | |
// space invader 2 | |
// data = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 1, 1, 0, -1, -1, -1, -1], [-1, -1, -1, 0, 1, 1, 1, 1, 0, -1, -1, -1], [-1, -1, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1], [-1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, -1], [-1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, -1], [-1, -1, 0, 0, 1, 0, 0, 1, 0, 0, -1, -1], [-1, -1, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1], [-1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, -1], [-1, 0, 0, -1, 0, -1, -1, 0, -1, 0, 0, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]; | |
// height = [3, 2]; | |
// rana | |
// data = [[-1, -1, -1, 0, 0, -1, 0, 0, -1, -1, -1, -1], [-1, -1, 0, 2, 2, -1, 2, 2, 0, -1, -1, -1], [-1, -1, 0, 2, 0, 1, 0, 2, 0, -1, -1, -1], [-1, 0, 1, 2, 0, 1, 0, 2, 1, 0, -1, -1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, -1], [0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, -1], [-1, 0, 1, 1, 0, 0, 0, 1, 1, 0, -1, -1], [-1, -1, 0, 1, 1, 1, 1, 1, 0, -1, -1, -1], [0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, -1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, -1], [-1, 0, 1, 1, 0, 1, 0, 1, 1, 0, -1, -1], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1]]; | |
// height = [3, 2, 1, 1]; | |
// pulpo | |
data = [[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, -1, -1, -1], [-1, -1, -1, -1, -1, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]; | |
height = [3, 2, 1, 1]; | |
rows = len(data); | |
cols = len(data[0]); | |
size = 2; | |
h = 0.8; | |
cubes(); | |
module cubes() { | |
union() { | |
for (c=[0:rows-1]) { | |
for (r=[0:cols-1]) { | |
d = data[c][r]; | |
if (d >= 0) { | |
translate([(r*size), -(c*size), 0]) | |
cube([size, size, height[d]*h]); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment