chiark / gitweb /
quacks-ingredients: ready for test
[reprap-play.git] / quacks-ingredients.scad
1 // -*- C -*-
2
3 token_dia = 18;
4 spot_dia = 4;
5 spot_gap = spot_dia / 3.0;
6
7 thick = 1.5;
8
9 multicolour_gap = 0.15; // each side
10 initial_layer_thick = 0.400;
11 initial_layer_width = 0.750;
12 final_layer_thick = 0.250;
13 multicolour_post = 4;
14
15 $nspots = 3;
16 $spots_absent = false;
17 $spots_plusgap = false;
18
19 $fs=0.1;
20 $fa=1;
21
22 module Spots_Extrude_Lower(){
23   d = $spots_plusgap ? 1 : 0;
24   translate([0,0,-d])
25     linear_extrude(height= initial_layer_thick + d)
26     children(0);
27 }
28
29 module Spots_Extrude_Upper(){
30   d = $spots_plusgap ? 1 : 0;
31   translate([0,0, thick + d])
32     mirror([0,0, 1])
33     linear_extrude(height= final_layer_thick + d)
34     children(0);
35 }
36
37 module SpotAt(condition, xy) {
38   if (condition == !$spots_absent) {
39     echo(condition, $spots_absent, "Y");
40     translate(xy * (spot_gap + spot_dia) * sqrt(0.5))
41       circle(r= spot_dia/2 +
42              ($spots_plusgap ? multicolour_gap : 0));
43   } else {
44     echo(condition, $spots_absent, "N");
45   }
46 }
47
48 module Token_Spots(){
49   SpotAt(($nspots % 2) > 0,  [0,0]);
50   SpotAt($nspots >= 2, [ 1, 1]);
51   SpotAt($nspots >= 2, [-1,-1]);
52   SpotAt($nspots >= 4, [ 1,-1]);
53   SpotAt($nspots >= 4, [-1, 1]);
54 }
55
56 module Token_Spots_All(){
57   $nspots = 5;
58   Token_Spots();
59 }
60
61 module Token_L1(){
62   Spots_Extrude_Lower()
63     Token_Spots();
64 }
65
66 module Token_L2(){
67   $spots_absent = true;
68   Spots_Extrude_Lower()
69     Token_Spots();
70 }
71
72 module Token_L3(){
73   $spots_plusgap = true;
74   difference(){
75     linear_extrude(height=thick)
76       circle(r=token_dia/2);
77     Spots_Extrude_Lower() Token_Spots_All();
78     Spots_Extrude_Upper() Token_Spots_All();
79   }
80 }
81
82 module Token_L4(){
83   $spots_absent = true;
84   Spots_Extrude_Upper()
85     Token_Spots();
86 }
87
88 module Token_L5(){
89   Spots_Extrude_Upper()
90     Token_Spots();
91 }
92
93 module Demo(){ ////toplevel
94   color("red") { Token_L3(); }
95   color("white") { Token_L1(); Token_L5(); }
96   color("black") { Token_L2(); Token_L4(); }
97 }
98
99 module Frame(phase) {
100   zs = [ initial_layer_thick,
101          initial_layer_thick,
102          thick,
103          thick,
104          thick ];
105
106   base_sz = token_dia * [ 6, 1.5 ];
107   sz = base_sz + phase * initial_layer_width * 2 * [1,1];
108   linear_extrude(height= initial_layer_thick) {
109     difference(){
110       square(center=true, sz + initial_layer_width * 2 * [1,1]);
111       square(center=true, sz);
112     }
113   }
114   translate([-base_sz[0]/2, (phase-3)*(multicolour_post + multicolour_gap)])
115     linear_extrude(height= zs[phase-1])
116     square(multicolour_post);
117 }
118
119 module Tests(){
120   for ($nspots = [1,2,3,4]) {
121     translate(($nspots - 2) * (token_dia + 3) * [1,0])
122       children();
123   }
124 }
125
126 module Test_L1(){ ////toplevel
127   Frame(1); Tests() Token_L1();
128 }
129 module Test_L2(){ ////toplevel
130   Frame(2); Tests() Token_L2();
131 }
132 module Test_L3(){ ////toplevel
133   Frame(3); Tests() Token_L3();
134 }
135 module Test_L4(){ ////toplevel
136   Frame(4); Tests() Token_L4();
137 }
138 module Test_L5(){ ////toplevel
139   Frame(5); Tests() Token_L5();
140 }
141
142 //Demo();