Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
#
# pcb.py
# PCB template
#
# Neil Gershenfeld 10/8/18
# (c) Massachusetts Institute of Technology 2018
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
# acknowledge this project. Copyright is retained and
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#
#
# uncomment for desired output:
#
output = "traces, labels, and exterior"
#output = "traces and exterior"
#output = "interior"
#output = "exterior"
#output = "traces"
#output = "holes"
#output = "solder mask"
#
# import
#
import math,json,sys
#
# define shapes and transformations
#
# color(color,part)
# circle(x0, y0, r)
# cylinder(x0, y0, z0, z1, r)
# cone(x0, y0, z0, z1, r0)
# sphere(x0, y0, z0, r)
# torus(x0, y0, z0, r0, r1)
# rectangle(x0, x1, y0, y1)
# cube(x0, x1, y0, y1, z0, z1)
# right_triangle(x0, y0, h)
# triangle(x0, y0, x1, y1, x2, y2) (points in clockwise order)
# pyramid(x0, x1, y0, y1, z0, z1)
# function(Z_of_XY)
# functions(upper_Z_of_XY,lower_Z_of_XY)
# add(part1, part2)
# subtract(part1, part2)
# intersect(part1, part2)
# move(part,dx,dy)
# translate(part,dx,dy,dz)
# rotate(part, angle)
# rotate_x(part, angle)
# rotate_y(part, angle)
# rotate_z(part, angle)
# rotate_90(part)
# rotate_180(part)
# rotate_270(part)
# reflect_x(part,x0)
# reflect_y(part,y0)
# reflect_z(part,z0)
# reflect_xy(part)
# reflect_xz(part)
# reflect_yz(part)
# scale_x(part, x0, sx)
# scale_y(part, y0, sy)
# scale_z(part, z0, sz)
# scale_xy(part, x0, y0, sxy)
# scale_xyz(part, x0, y0, z0, sxyz)
# coscale_x_y(part, x0, y0, y1, angle0, angle1, amplitude, offset)
# coscale_x_z(part, x0, z0, z1, angle0, angle1, amplitude, offset)
# coscale_xy_z(part, x0, y0, z0, z1, angle0, angle1, amplitude, offset)
# taper_x_y(part, x0, y0, y1, s0, s1)
# taper_x_z(part, x0, z0, z1, s0, s1)
# taper_xy_z(part, x0, y0, z0, z1, s0, s1)
# shear_x_y(part, y0, y1, dx0, dx1)
# shear_x_z(part, z0, z1, dx0, dx1)
true = "1"
false = "0"
def color(color, part):
part = '('+str(color)+'*(('+part+')!=0))'
return part
Red = (225 << 0)
Green = (225 << 8)
Blue = (225 << 16)
Gray = (128 << 16) + (128 << 8) + (128 << 0)
White = (255 << 16) + (255 << 8) + (255 << 0)
Teal = (255 << 16) + (255 << 8)
Pink = (255 << 16) + (255 << 0)
Yellow = (255 << 8) + (255 << 0)
Brown = (45 << 16) + (82 << 8) + (145 << 0)
Navy = (128 << 16) + (0 << 8) + (0 << 0)
Tan = (60 << 16) + (90 << 8) + (125 << 0)
def circle(x0, y0, r):
part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))) <= (r*r))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('r',str(r))
return part
def cylinder(x0, y0, z0, z1, r):
part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0)) <= (r*r)) & (Z >= (z0)) & (Z <= (z1)))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('z0',str(z0))
part = part.replace('z1',str(z1))
part = part.replace('r',str(r))
return part
def cone(x0, y0, z0, z1, r0):
part = cylinder(x0, y0, z0, z1, r0)
part = taper_xy_z(part, x0, y0, z0, z1, 1.0, 0.0)
return part
def sphere(x0, y0, z0, r):
part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0)) + (Z-(z0))*(Z-(z0))) <= (r*r))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('z0',str(z0))
part = part.replace('r',str(r))
return part
def torus(x0, y0, z0, r0, r1):
part = "(((r0 - sqrt((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))))*(r0 - sqrt((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))) + (Z-(z0))*(Z-(z0))) <= (r1*r1))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('z0',str(z0))
part = part.replace('r0',str(r0))
part = part.replace('r1',str(r1))
return part
def rectangle(x0, x1, y0, y1):
part = "((X >= (x0)) & (X <= (x1)) & (Y >= (y0)) & (Y <= (y1)))"
part = part.replace('x0',str(x0))
part = part.replace('x1',str(x1))
part = part.replace('y0',str(y0))
part = part.replace('y1',str(y1))
return part
def cube(x0, x1, y0, y1, z0, z1):
part = "((X >= (x0)) & (X <= (x1)) & (Y >= (y0)) & (Y <= (y1)) & (Z >= (z0)) & (Z <= (z1)))"
part = part.replace('x0',str(x0))
part = part.replace('x1',str(x1))
part = part.replace('y0',str(y0))
part = part.replace('y1',str(y1))
part = part.replace('z0',str(z0))
part = part.replace('z1',str(z1))
return part
def right_triangle(x0, y0, l):
part = "((X > x0) & (X < x0 + l - (Y-y0)) & (Y > y0))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('l',str(l))
return part
def triangle(x0, y0, x1, y1, x2, y2): # points in clockwise order
part = "(((((y1)-(y0))*(X-(x0))-((x1)-(x0))*(Y-(y0))) >= 0) & ((((y2)-(y1))*(X-(x1))-((x2)-(x1))*(Y-(y1))) >= 0) & ((((y0)-(y2))*(X-(x2))-((x0)-(x2))*(Y-(y2))) >= 0))"
part = part.replace('x0',str(x0))
part = part.replace('y0',str(y0))
part = part.replace('x1',str(x1))
part = part.replace('y1',str(y1))
part = part.replace('x2',str(x2))
part = part.replace('y2',str(y2))
return part
def pyramid(x0, x1, y0, y1, z0, z1):
part = cube(x0, x1, y0, y1, z0, z1)
part = taper_xy_z(part, (x0+x1)/2., (y0+y1)/2., z0, z1, 1.0, 0.0)
return part
def function(Z_of_XY):
part = '(Z <= '+Z_of_XY+')'
return part
def functions(upper_Z_of_XY,lower_Z_of_XY):
part = '(Z <= '+upper_Z_of_XY+') & (Z >= '+lower_Z_of_XY+')'
return part
def add(part1, part2):
part = "part1 | part2"
part = part.replace('part1',part1)
part = part.replace('part2',part2)
return part
def subtract(part1, part2):
part = "(part1) & ~(part2)"
part = part.replace('part1',part1)
part = part.replace('part2',part2)
return part
def intersect(part1, part2):
Loading
Loading full blame...