rubyscad 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +137 -239
- data/lib/RubyScad.rb +1 -2
- data/lib/rubyscad/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -4,422 +4,320 @@ RubyScad
|
|
4
4
|
Ruby module to easily generate openscad scripts
|
5
5
|
|
6
6
|
General Usage
|
7
|
+
-------------
|
7
8
|
|
8
9
|
Requirements: Ruby 1.9.3
|
10
|
+
Installation: `gem install rubyscad`
|
9
11
|
|
10
12
|
RubyScad is a ruby mixin module which provides functions which allow easy output of openscad scripts . To use simply "include" or "extend" the module into any class or module:
|
11
13
|
|
14
|
+
require "rubyscad"
|
12
15
|
|
13
|
-
|
16
|
+
module Test
|
14
17
|
|
15
|
-
|
18
|
+
extend RubyScad
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
module Test
|
20
|
-
|
21
|
-
extend RubyScad #extend makes all function available at the class level
|
20
|
+
def self.cone(base=5, height=10)
|
22
21
|
|
23
|
-
|
22
|
+
cylinder(r1: base, r2: 0, h:height)
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
cylinder(r1: base, r2: 0, h:height)
|
24
|
+
end
|
28
25
|
|
26
|
+
cone(2, 4)
|
29
27
|
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
cone(2, 4)
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
----------------------------------------------------------------------------
|
29
|
+
---
|
38
30
|
|
39
31
|
from command line:
|
40
32
|
|
41
|
-
print to standard output: ruby test.rb
|
42
|
-
|
43
|
-
generate file: ruby test.rb "test.scad"
|
44
|
-
|
45
|
-
--------------------------------test2.rb------------------------------------
|
46
|
-
|
47
|
-
load "RubyScad.rb" #or use require but it must be in ruby's system path
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
class Test2
|
52
|
-
|
53
|
-
include RubyScad #includ makes function available within the class/module
|
54
|
-
|
55
|
-
|
33
|
+
print to standard output: `ruby test.rb`
|
56
34
|
|
57
|
-
|
35
|
+
generate file: `ruby test.rb "test.scad"`
|
58
36
|
|
59
|
-
|
37
|
+
---
|
60
38
|
|
61
|
-
|
39
|
+
require "rubyscad"
|
62
40
|
|
63
|
-
|
41
|
+
class Test2
|
64
42
|
|
65
|
-
|
43
|
+
include RubyScad
|
66
44
|
|
67
|
-
|
45
|
+
def initialize(args={})
|
46
|
+
@radius = args.fetch(:radius, 3)
|
47
|
+
end
|
68
48
|
|
49
|
+
def render()
|
50
|
+
sphere(r:@radius)
|
51
|
+
end
|
69
52
|
end
|
70
53
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Test2.new.render
|
54
|
+
Test2.new.render
|
76
55
|
|
77
|
-
|
56
|
+
---
|
78
57
|
|
79
|
-
|
58
|
+
print to standard output: `ruby test2.rb`
|
80
59
|
|
81
|
-
|
60
|
+
generate file: `ruby test2.rb "test2.scad"`
|
82
61
|
|
83
|
-
|
62
|
+
General Considerations
|
63
|
+
-----------------------
|
84
64
|
|
65
|
+
- All arguments are passed as named hash values matching the openscad spec, exceptions are for functions fa, fs, fn, echo, include, and use (see below).
|
66
|
+
openscad: `cube(6)`
|
67
|
+
rubyscad: `cube(size: 6)`
|
68
|
+
- Any hash values may be passed to functions (with the exception of the ones noted above) but openscad may or may not use these values
|
69
|
+
*cube(openscadwontusethis: 5)* will produce *cube(openscadwontusethis = 5);*
|
70
|
+
nothing bad will happen here, the value will just have no effect
|
71
|
+
- $fn, $fs, $fa variables are passed without the '$'
|
72
|
+
openscad: `sphere(4, $fn=12)`
|
73
|
+
rubyscad: `sphere(r: 4, fn: 12)`
|
74
|
+
- Ruby's math functions use radians, openscad uses degrees, for ease I've added a 'radians' function to the numeric class so the following is possible:
|
75
|
+
openscad: sin(15)
|
76
|
+
rubyscad: Math.sin(15.radians)
|
77
|
+
- All functions which take code blocks (union, difference, intersection, ...) can use the form "function() { code }" or "function()" with the following result:
|
78
|
+
the code:
|
85
79
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
General Considerations:
|
90
|
-
|
91
|
-
-All arguments passed to rubyscad functions are passed as named hash values matching the openscad spec, exceptions are for functions fa, fs, fn, echo, include, and use (see below).
|
92
|
-
|
93
|
-
openscad: cube(6)
|
94
|
-
|
95
|
-
rubyscad: cube(size: 6)
|
96
|
-
|
97
|
-
-Any arguments may be passed to functions (with the exception of the ones noted above) but openscad may or may not use these values
|
98
|
-
|
99
|
-
-cube(openscadwontusethis: 5) will produce the following openscad
|
100
|
-
|
101
|
-
-cube(openscadwontusethis = 5);
|
102
|
-
|
103
|
-
nothing bad will happen here, the value will just have no effect
|
104
|
-
|
105
|
-
-$fn, $fs, $fa variables are passed without the '$'
|
106
|
-
|
107
|
-
openscad: sphere(4, $fn=12)
|
108
|
-
|
109
|
-
rubyscad: sphere(r: 4, fn: 12)
|
110
|
-
|
111
|
-
-Ruby's math functions use radians, openscad uses degrees, for ease I've added a 'radians' function to the numeric class so the following is possible
|
112
|
-
|
113
|
-
openscad: sin(15)
|
114
|
-
|
115
|
-
rubyscad: Math.sin(15.radians)
|
116
|
-
|
117
|
-
-All functions which take code blocks (union, difference, intersection, ...) can use the form "function() { code }" or "function()" with the following result
|
118
|
-
|
119
|
-
the code:
|
120
|
-
|
121
80
|
translate(x: 5)
|
122
|
-
|
123
81
|
cube(size: 7)
|
124
82
|
|
125
|
-
|
83
|
+
would produce:
|
126
84
|
|
127
85
|
translate([5,0,0])
|
128
|
-
|
129
86
|
cube(size = 7);
|
130
87
|
|
131
|
-
|
88
|
+
the code:
|
132
89
|
|
133
90
|
translate(x: 5) {
|
134
|
-
|
135
91
|
cube(size: 7)
|
136
|
-
|
137
92
|
}
|
138
93
|
|
139
|
-
|
94
|
+
would produce:
|
140
95
|
|
141
96
|
translate([5,0,0]) {
|
142
|
-
|
143
97
|
cube(size = 7);
|
144
|
-
|
145
98
|
}
|
146
99
|
|
147
|
-
|
148
|
-
|
149
100
|
Openscad Functions:
|
101
|
+
-------------------
|
150
102
|
|
151
|
-
|
152
|
-
|
153
|
-
openscad: $fa = 0.2;
|
154
|
-
|
155
|
-
rubyscad: fa 0.2
|
103
|
+
openscad: `$fa = 0.2;`
|
104
|
+
rubyscad: `fa 0.2`
|
156
105
|
|
157
106
|
----------------------------------------------------------------------------
|
158
107
|
|
159
|
-
openscad:
|
160
|
-
|
161
|
-
rubyscad: fs 2
|
108
|
+
openscad: `$fs = 2;`
|
109
|
+
rubyscad: `fs 2`
|
162
110
|
|
163
111
|
----------------------------------------------------------------------------
|
164
112
|
|
165
|
-
openscad:
|
166
|
-
|
167
|
-
rubyscad: fn 5
|
113
|
+
openscad: `$fn = 5;`
|
114
|
+
rubyscad: `fn 5`
|
168
115
|
|
169
116
|
----------------------------------------------------------------------------
|
170
117
|
|
171
|
-
openscad: include <file.scad
|
172
|
-
|
173
|
-
rubyscad: include_scad "file.scad"
|
118
|
+
openscad: `include <file.scad>`
|
119
|
+
rubyscad: `include_scad "file.scad"`
|
174
120
|
|
175
121
|
----------------------------------------------------------------------------
|
176
122
|
|
177
|
-
openscad: use <file.scad
|
178
|
-
|
179
|
-
rubyscad: use "file.scad"
|
123
|
+
openscad: `use <file.scad>`
|
124
|
+
rubyscad: `use "file.scad"`
|
180
125
|
|
181
126
|
----------------------------------------------------------------------------
|
182
127
|
|
183
|
-
openscad: echo(1,2,3)
|
184
|
-
|
185
|
-
rubyscad: echo 1, 2, 3
|
128
|
+
openscad: `echo(1,2,3);`
|
129
|
+
rubyscad: `echo 1, 2, 3`
|
186
130
|
|
187
131
|
----------------------------------------------------------------------------
|
188
132
|
|
189
|
-
openscad:
|
190
|
-
|
191
|
-
rubyscad: background
|
133
|
+
openscad: `%`
|
134
|
+
rubyscad: `background`
|
192
135
|
|
193
136
|
----------------------------------------------------------------------------
|
194
137
|
|
195
|
-
openscad:
|
196
|
-
|
197
|
-
rubyscad: debug
|
138
|
+
openscad: `#`
|
139
|
+
rubyscad: `debug`
|
198
140
|
|
199
141
|
----------------------------------------------------------------------------
|
200
142
|
|
201
|
-
openscad:
|
202
|
-
|
203
|
-
rubyscad: root
|
143
|
+
openscad: `!`
|
144
|
+
rubyscad: `root`
|
204
145
|
|
205
146
|
----------------------------------------------------------------------------
|
206
147
|
|
207
|
-
openscad:
|
208
|
-
|
209
|
-
rubyscad: disable
|
148
|
+
openscad: `*`
|
149
|
+
rubyscad: `disable`
|
210
150
|
|
211
151
|
----------------------------------------------------------------------------
|
212
152
|
|
213
|
-
openscad: projection([args]) [{ code }]
|
214
|
-
|
215
|
-
rubyscad: projection([args]) [{ code }]
|
153
|
+
openscad: `projection([args]) [{ code }]`
|
154
|
+
rubyscad: `projection([args]) [{ code }]`
|
216
155
|
|
217
156
|
----------------------------------------------------------------------------
|
218
157
|
|
219
|
-
openscad: linear_extrude([args]) [{ code }]
|
220
|
-
|
221
|
-
rubyscad: linear_extrude([args]) [{ code }]
|
158
|
+
openscad: `linear_extrude([args]) [{ code }]`
|
159
|
+
rubyscad: `linear_extrude([args]) [{ code }]`
|
222
160
|
|
223
161
|
----------------------------------------------------------------------------
|
224
162
|
|
225
|
-
openscad: rotate_extrude([args]) [{ code }]
|
226
|
-
|
227
|
-
rubyscad: rotate_extrude([args]) [{ code }]
|
163
|
+
openscad: `rotate_extrude([args]) [{ code }]`
|
164
|
+
rubyscad: `rotate_extrude([args]) [{ code }]`
|
228
165
|
|
229
166
|
----------------------------------------------------------------------------
|
230
167
|
|
231
|
-
openscad: import([args])
|
232
|
-
|
233
|
-
rubyscad: import([args])
|
168
|
+
openscad: `import([args])`
|
169
|
+
rubyscad: `import([args])`
|
234
170
|
|
235
171
|
----------------------------------------------------------------------------
|
236
172
|
|
237
|
-
openscad: difference() { code }
|
238
|
-
|
239
|
-
rubyscad: difference() { code }
|
173
|
+
openscad: `difference() { code }`
|
174
|
+
rubyscad: `difference() { code }`
|
240
175
|
|
241
176
|
----------------------------------------------------------------------------
|
242
177
|
|
243
|
-
openscad: union() { code }
|
244
|
-
|
245
|
-
rubyscad: union() { code }
|
178
|
+
openscad: `union() { code }`
|
179
|
+
rubyscad: `union() { code }`
|
246
180
|
|
247
181
|
----------------------------------------------------------------------------
|
248
182
|
|
249
|
-
openscad: intersection() { code }
|
250
|
-
|
251
|
-
rubyscad: intersection() { code }
|
183
|
+
openscad: `intersection() { code }`
|
184
|
+
rubyscad: `intersection() { code }`
|
252
185
|
|
253
186
|
----------------------------------------------------------------------------
|
254
187
|
|
255
|
-
openscad: render([args]) [{ code }]
|
256
|
-
|
257
|
-
rubyscad: render([args]) [{ code }]
|
188
|
+
openscad: `render([args]) [{ code }]`
|
189
|
+
rubyscad: `render([args]) [{ code }]`
|
258
190
|
|
259
191
|
----------------------------------------------------------------------------
|
260
192
|
|
261
|
-
openscad: minkowski() { code }
|
262
|
-
|
263
|
-
rubyscad: minkowski() { code }
|
193
|
+
openscad: `minkowski() { code }`
|
194
|
+
rubyscad: `minkowski() { code }`
|
264
195
|
|
265
196
|
----------------------------------------------------------------------------
|
266
197
|
|
267
|
-
openscad: hull() { code }
|
268
|
-
|
269
|
-
rubyscad: hull() { code }
|
198
|
+
openscad: `hull() { code }`
|
199
|
+
rubyscad: `hull() { code }`
|
270
200
|
|
271
201
|
----------------------------------------------------------------------------
|
272
202
|
|
273
|
-
openscad: cube([args])
|
274
|
-
|
275
|
-
rubyscad: cube([args])
|
203
|
+
openscad: `cube([args])`
|
204
|
+
rubyscad: `cube([args])`
|
276
205
|
|
277
206
|
----------------------------------------------------------------------------
|
278
207
|
|
279
|
-
openscad: sphere([args])
|
208
|
+
openscad: `sphere([args])`
|
209
|
+
rubyscad: `sphere([args])`
|
280
210
|
|
281
|
-
|
282
|
-
|
283
|
-
In addition to the normal arguments d: can also be provided instead of r: to
|
284
|
-
|
285
|
-
specify the diameter instead of the radius
|
211
|
+
* In addition to the normal arguments d: can also be provided instead of r: to specify the diameter instead of the radius
|
286
212
|
|
287
213
|
----------------------------------------------------------------------------
|
288
214
|
|
289
|
-
openscad: polyhedron([args])
|
290
|
-
|
291
|
-
rubyscad: polyhedron([args])
|
215
|
+
openscad: `polyhedron([args])`
|
216
|
+
rubyscad: `polyhedron([args])`
|
292
217
|
|
293
218
|
----------------------------------------------------------------------------
|
294
219
|
|
295
|
-
openscad: square([args])
|
296
|
-
|
297
|
-
rubyscad: square([args])
|
220
|
+
openscad: `square([args])`
|
221
|
+
rubyscad: `square([args])`
|
298
222
|
|
299
223
|
----------------------------------------------------------------------------
|
300
224
|
|
301
|
-
openscad: circle([args])
|
302
|
-
|
303
|
-
rubyscad: circle([args])
|
304
|
-
|
305
|
-
In addition to the normal arguments d: can also be provided instead of r: to
|
225
|
+
openscad: `circle([args])`
|
226
|
+
rubyscad: `circle([args])`
|
306
227
|
|
307
|
-
|
228
|
+
* In addition to the normal arguments d: can also be provided instead of r: to specify the diameter instead of the radius
|
308
229
|
|
309
230
|
----------------------------------------------------------------------------
|
310
231
|
|
311
|
-
openscad: polygon([args])
|
312
|
-
|
313
|
-
rubyscad: polygon([args])
|
232
|
+
openscad: `polygon([args])`
|
233
|
+
rubyscad: `polygon([args])`
|
314
234
|
|
315
235
|
----------------------------------------------------------------------------
|
316
236
|
|
317
|
-
openscad: surface([args])
|
318
|
-
|
319
|
-
rubyscad: surface([args])
|
237
|
+
openscad: `surface([args])`
|
238
|
+
rubyscad: `surface([args])`
|
320
239
|
|
321
240
|
----------------------------------------------------------------------------
|
322
241
|
|
323
|
-
openscad: cylinder([args])
|
324
|
-
|
325
|
-
rubyscad: cylinder([args])
|
242
|
+
openscad: `cylinder([args])`
|
243
|
+
rubyscad: `cylinder([args])`
|
326
244
|
|
327
245
|
----------------------------------------------------------------------------
|
328
246
|
|
329
|
-
openscad: rotate([args]) [{ code }]
|
247
|
+
openscad: `rotate([args]) [{ code }]`
|
248
|
+
rubyscad: `rotate([args]) [{ code }]`
|
330
249
|
|
331
|
-
|
332
|
-
|
333
|
-
In addition to the normal arguments x:, y:, and z: can be used instead of
|
334
|
-
|
335
|
-
the normal vector input
|
250
|
+
* In addition to specifying a: as a vector x:, y:, and z: can be used instead
|
336
251
|
|
337
252
|
----------------------------------------------------------------------------
|
338
253
|
|
339
|
-
openscad: translate([args]) [{ code }]
|
340
|
-
|
341
|
-
rubyscad: translate([args]) [{ code }]
|
254
|
+
openscad: `translate([args]) [{ code }]`
|
255
|
+
rubyscad: `translate([args]) [{ code }]`
|
342
256
|
|
343
|
-
|
344
|
-
|
345
|
-
the normal vector input
|
257
|
+
* In addition to specifying v: as a vector x:, y:, and z: can be used instead
|
346
258
|
|
347
259
|
----------------------------------------------------------------------------
|
348
260
|
|
349
|
-
openscad: scale([args]) [{ code }]
|
350
|
-
|
351
|
-
rubyscad: scale([args]) [{ code }]
|
352
|
-
|
353
|
-
In addition to the normal arguments x:, y:, and z: can be used instead of
|
261
|
+
openscad: `scale([args]) [{ code }]`
|
262
|
+
rubyscad: `scale([args]) [{ code }]`
|
354
263
|
|
355
|
-
|
264
|
+
* In addition to specifying v: as a vector x:, y:, and z: can be used instead
|
356
265
|
|
357
266
|
----------------------------------------------------------------------------
|
358
267
|
|
359
|
-
openscad: mirror([args]) [{ code }]
|
268
|
+
openscad: `mirror([args]) [{ code }]`
|
269
|
+
rubyscad: `mirror([args]) [{ code }]`
|
360
270
|
|
361
|
-
|
362
|
-
|
363
|
-
In addition to the normal arguments x:, y:, and z: can be used instead of
|
364
|
-
|
365
|
-
the normal vector input
|
271
|
+
* In addition to specifying v: as a vector x:, y:, and z: can be used instead
|
366
272
|
|
367
273
|
----------------------------------------------------------------------------
|
368
274
|
|
369
|
-
openscad: multmatrix([args]) [{ code }]
|
370
|
-
|
371
|
-
rubyscad: multmatrix([args]) [{ code }]
|
275
|
+
openscad: `multmatrix([args]) [{ code }]`
|
276
|
+
rubyscad: `multmatrix([args]) [{ code }]`
|
372
277
|
|
373
278
|
----------------------------------------------------------------------------
|
374
279
|
|
375
|
-
openscad: color([args]) [{ code }]
|
280
|
+
openscad: `color([args]) [{ code }]`
|
281
|
+
rubyscad: `color([args]) [{ code }]`
|
376
282
|
|
377
|
-
|
378
|
-
|
379
|
-
Instead of color: being a vector, r:, g:, b:, and a: can be provided
|
380
|
-
|
381
|
-
|
283
|
+
* Instead of color: being defined, r:, g:, b:, and a: can be provided
|
382
284
|
|
383
285
|
RubyScad Functions:
|
286
|
+
-------------------
|
384
287
|
|
385
|
-
|
386
|
-
|
387
|
-
format_command(cmd_str, args={}, &block)
|
388
|
-
|
389
|
-
an easy way to implement new openscad commands.
|
390
|
-
|
391
|
-
cmd_str should be in the form "func_name(%<args>);"
|
392
|
-
|
393
|
-
all arguments passed from "args" will be inserted into the <args> string modifier, if
|
288
|
+
`format_command(cmd_str, args={}, &block)`
|
394
289
|
|
395
|
-
|
290
|
+
* an easy way to implement new openscad commands.
|
291
|
+
* cmd\_str should be in the form "func\_name(%<args>);"
|
292
|
+
* all arguments passed from "args" will be inserted into the <args> string modifier
|
293
|
+
* if a block is passed it will output between { }
|
396
294
|
|
397
295
|
----------------------------------------------------------------------------
|
398
296
|
|
399
|
-
|
297
|
+
`new_line`
|
400
298
|
|
401
|
-
|
299
|
+
* outputs a new line
|
402
300
|
|
403
301
|
----------------------------------------------------------------------------
|
404
302
|
|
405
|
-
|
303
|
+
`start_block`
|
406
304
|
|
407
|
-
|
305
|
+
* outputs a '{' at the correct tab level
|
408
306
|
|
409
307
|
----------------------------------------------------------------------------
|
410
308
|
|
411
|
-
|
309
|
+
`end_block`
|
412
310
|
|
413
|
-
|
311
|
+
* outputs a '}' at the correct tab level
|
414
312
|
|
415
313
|
----------------------------------------------------------------------------
|
416
314
|
|
417
|
-
|
315
|
+
`end_all_blocks`
|
418
316
|
|
419
|
-
|
317
|
+
* outputs a '}' for every open block
|
420
318
|
|
421
319
|
----------------------------------------------------------------------------
|
422
320
|
|
423
|
-
|
321
|
+
`format_output`
|
424
322
|
|
425
|
-
|
323
|
+
* outputs a string at the correct tab level
|
data/lib/RubyScad.rb
CHANGED
@@ -297,7 +297,7 @@ module RubyScad
|
|
297
297
|
end
|
298
298
|
|
299
299
|
def self.start_output
|
300
|
-
@@output_file
|
300
|
+
@@output_file ||= nil
|
301
301
|
if ARGV[0] && ARGV[0].include?(".scad")
|
302
302
|
@@output_file = ARGV[0]
|
303
303
|
ARGV.shift
|
@@ -311,7 +311,6 @@ module RubyScad
|
|
311
311
|
|
312
312
|
def self.extended(mod)
|
313
313
|
start_output
|
314
|
-
mod.class_variable_set(:@@fa, 30)
|
315
314
|
end
|
316
315
|
|
317
316
|
def self.included(mod)
|
data/lib/rubyscad/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyscad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby module to easily generate openscad scripts
|
15
15
|
email:
|