8ad72e01c24628e9aa0e66ce81f8ebe3ccbb4aa0
[clinton/3d-models.git] / pacman-ghost / pacman-ghost.scad
1 //
2 // Pacman Ghost
3 // ------------
4 //
5 // Created by Joao Alves (jpralves@gmail.com)
6 // Tea Light added by Clinton Ebadi <clinton@unknownlamer.org>
7 // Pac Guy model by Fry Hyde
8 // ------------------------------------------
9 //
10 // Parameters:
11
12 // Figure diameter
13 ghost_diameter = 50; // [25:5:100]
14 pacguy_diameter = ghost_diameter * 1.5;
15
16 height = ghost_diameter*0.65;
17 // Add keychain
18 key_chain = 0; // [1:On, 0:Off]
19 // Add LED hole
20 led_hole = 0; // [0:Off, 5:5mm, 8:8mm, 10:10mm]
21 // Add tea light holder
22 tea_light = true;
23
24 // Render Ghost
25 ghost = true;
26 // Render Pac Guy
27 pacguy = false;
28
29 // Detail
30 $fa=4; // [20:Low Res, 10:Normal Res, 4:Hi Res]
31
32 // [Tea Light]
33 base_diameter = 30;
34 base_height = 16.2;
35 bulb_diameter = 9;
36
37 /* [Hidden] */
38 $fs=0.1;
39
40 module ghost() {
41 difference () {
42 union() {
43 cylinder(d = ghost_diameter, h = height);
44 translate([0, 0, height]) sphere(d = ghost_diameter);
45 if (key_chain == 1) {
46 translate([0, 0, height+ghost_diameter/2])
47 rotate([0, 90, 0])
48 rotate_extrude()
49 translate([4, 0, 0])
50 circle(r = 1.5);
51 }
52 }
53 translate([ghost_diameter/2, -ghost_diameter/4, height])
54 sphere(d = ghost_diameter/3.5);
55 translate([ghost_diameter/2, ghost_diameter/4, height])
56 sphere(d = ghost_diameter/3.5);
57 translate([0, 0, -0.1])
58 for(a = [0:11]) {
59 rotate([a/12*360,-90,0])
60 scale([1.5,1,1])
61 translate([0,0,ghost_diameter/12.5])
62 cylinder(ghost_diameter, 0,ghost_diameter/25*6.5, $fn=4);
63 }
64 }
65 }
66
67 module led_hole (led_d = led_hole, led_h = 0) {
68 // led_h==0 auto-sets height, openscad can't reference other
69 // arguments so this abomination arises
70 led_h = led_h ? led_h : height - (led_d+2);
71
72 union() {
73 cylinder(d = led_d+2, h = led_h);
74 translate([0, 0, led_h]) sphere(d = led_d+2);
75 }
76 }
77
78 module tea_light_base () {
79 difference () {
80 union () {
81 cylinder (d = base_diameter + 1, h = base_height + 1);
82 led_hole (led_d = bulb_diameter, led_h = base_height+8);
83 }
84 // sacrificial support layer, subtracted since this will be
85 // subtracted from the ghost body
86 translate ([0, 0, base_height+0.7]) #cylinder (d=base_diameter+2, h=0.3);
87 }
88
89 }
90
91 module pacguy () {
92 // original model ghost_diameter is 30.464mm, scale to 1mm and then to
93 // final ghost_diameter. z is slightly smaller due to bottom being cut
94 // flat.
95 s = 1 / 30.464 * pacguy_diameter;
96 scale ([s, s, s]) translate ([0, 0, 28.742 / 2]) import ("PacGuy.stl", convexity=10);
97 }
98
99 module subtract_led () {
100 difference () {
101 children ();
102 if (led_hole > 0) led_hole ();
103 if (tea_light) tea_light_base ();
104 }
105 }
106 if (ghost) {
107 subtract_led () {
108 rotate ([0, 0, -90]) ghost ();
109 }
110 }
111
112 if (pacguy) {
113 translate ([ ghost ? (ghost_diameter + pacguy_diameter) / 2 + 10 : 0, 0, 0]) subtract_led () {
114 pacguy ();
115 }
116 }