crystalscad 0.2.0
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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/crystalscad.gemspec +24 -0
- data/lib/crystalscad/CrystalScad.rb +196 -0
- data/lib/crystalscad/version.rb +4 -0
- data/lib/crystalscad.rb +3 -0
- metadata +75 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 cjbissonnette
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
CrystalScad
|
2
|
+
===========
|
3
|
+
|
4
|
+
Produce OpenSCAD code in Ruby. Based on RubyScad
|
5
|
+
|
6
|
+
Requires Ruby 1.9.3
|
7
|
+
|
8
|
+
Currently not feature complete
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
Example Code:
|
14
|
+
===========
|
15
|
+
|
16
|
+
require "crystalscad"
|
17
|
+
|
18
|
+
include CrystalScad
|
19
|
+
|
20
|
+
res = cylinder(r:5,h:10).translate(x:10).rotate(y:45)
|
21
|
+
|
22
|
+
res+= cube([10,20,30])
|
23
|
+
|
24
|
+
res-= cube([5,10,40]).translate(z:-1)
|
25
|
+
|
26
|
+
puts res.output
|
27
|
+
|
28
|
+
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/crystalscad.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require "crystalscad/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "crystalscad"
|
9
|
+
gem.version = CrystalScad::VERSION
|
10
|
+
gem.authors = ["Joachim Glauche"]
|
11
|
+
gem.email = ["webmaster@joaz.de"]
|
12
|
+
gem.homepage = "http://github.com/Joaz/CrystalScad"
|
13
|
+
gem.summary = %q{Generate OpenSCAD scripts with ruby}
|
14
|
+
gem.description = %q{Inspired by SolidPython, based on RubyScad}
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.required_ruby_version = ">= 1.9.3"
|
22
|
+
gem.requirements << "rubyscad"
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rubyscad"
|
3
|
+
|
4
|
+
module CrystalScad
|
5
|
+
|
6
|
+
|
7
|
+
class ScadObject
|
8
|
+
attr_accessor :args
|
9
|
+
attr_accessor :transformations
|
10
|
+
def initialize(*args)
|
11
|
+
@transformations = []
|
12
|
+
@args = args.flatten
|
13
|
+
if @args[0].kind_of? Hash
|
14
|
+
@args = @args[0]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def walk_tree
|
20
|
+
res = ""
|
21
|
+
|
22
|
+
@transformations.reverse.each{|trans|
|
23
|
+
res += trans.walk_tree
|
24
|
+
}
|
25
|
+
res += self.to_rubyscad.to_s+ "\n"
|
26
|
+
res
|
27
|
+
end
|
28
|
+
alias :output :walk_tree
|
29
|
+
|
30
|
+
def to_rubyscad
|
31
|
+
""
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class Primitive < ScadObject
|
37
|
+
|
38
|
+
def rotate(args)
|
39
|
+
@transformations << Rotate.new(args)
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def translate(args)
|
44
|
+
@transformations << Translate.new(args)
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def union(args)
|
49
|
+
@transformations << Union.new(args)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class TransformedObject < Primitive
|
56
|
+
attr_accessor :scad
|
57
|
+
def initialize(string)
|
58
|
+
@scad = string
|
59
|
+
@transformations = []
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_rubyscad
|
63
|
+
return @scad
|
64
|
+
end
|
65
|
+
alias :output :walk_tree
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
class Transformation < ScadObject
|
70
|
+
end
|
71
|
+
|
72
|
+
class Rotate < Transformation
|
73
|
+
def to_rubyscad
|
74
|
+
return RubyScadBridge.new.rotate(@args)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Translate < Transformation
|
79
|
+
def to_rubyscad
|
80
|
+
return RubyScadBridge.new.translate(@args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Cylinder < Primitive
|
85
|
+
def to_rubyscad
|
86
|
+
return RubyScadBridge.new.cylinder(@args)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def cylinder(args)
|
91
|
+
Cylinder.new(args)
|
92
|
+
end
|
93
|
+
|
94
|
+
class Cube < Primitive
|
95
|
+
def to_rubyscad
|
96
|
+
return RubyScadBridge.new.cube(@args)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def cube(args)
|
101
|
+
if args.kind_of? Array
|
102
|
+
args = {size:args}
|
103
|
+
end
|
104
|
+
Cube.new(args)
|
105
|
+
end
|
106
|
+
|
107
|
+
# 2d primitives
|
108
|
+
class Square < Primitive
|
109
|
+
def to_rubyscad
|
110
|
+
return RubyScadBridge.new.square(@args)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def square(args)
|
115
|
+
Square.new(args)
|
116
|
+
end
|
117
|
+
|
118
|
+
class Circle < Primitive
|
119
|
+
def to_rubyscad
|
120
|
+
return RubyScadBridge.new.circle(@args)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def circle(args)
|
125
|
+
Circle.new(args)
|
126
|
+
end
|
127
|
+
|
128
|
+
class Polygon < Primitive
|
129
|
+
def to_rubyscad
|
130
|
+
return RubyScadBridge.new.polygon(@args)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def polygon(args)
|
135
|
+
Polygon.new(args)
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
class RubyScadBridge
|
140
|
+
include RubyScad
|
141
|
+
|
142
|
+
def raw_output(str)
|
143
|
+
return str
|
144
|
+
end
|
145
|
+
|
146
|
+
def format_output(str)
|
147
|
+
return str
|
148
|
+
end
|
149
|
+
|
150
|
+
def format_block(output_str)
|
151
|
+
return output_str
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def csg_operation(operation, code1, code2)
|
159
|
+
ret = "#{operation}(){"
|
160
|
+
ret +=code1
|
161
|
+
ret +=code2
|
162
|
+
ret +="}"
|
163
|
+
return TransformedObject.new(ret)
|
164
|
+
end
|
165
|
+
|
166
|
+
def +(args)
|
167
|
+
csg_operation("union",self.walk_tree,args.walk_tree)
|
168
|
+
end
|
169
|
+
|
170
|
+
def -(args)
|
171
|
+
csg_operation("difference",self.walk_tree,args.walk_tree)
|
172
|
+
end
|
173
|
+
|
174
|
+
def *(args)
|
175
|
+
csg_operation("intersection",self.walk_tree,args.walk_tree)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Fixme: currently just accepting named colors
|
179
|
+
def color(args)
|
180
|
+
ret = "color(\"#{args}\"){"
|
181
|
+
ret +=self.walk_tree
|
182
|
+
ret +="}"
|
183
|
+
return TransformedObject.new(ret)
|
184
|
+
end
|
185
|
+
|
186
|
+
def linear_extrude(args)
|
187
|
+
args = args.collect { |k, v| "#{k} = #{v}" }.join(', ')
|
188
|
+
ret = "linear_extrude(#{args}){"
|
189
|
+
ret +=self.walk_tree
|
190
|
+
ret +="}"
|
191
|
+
return TransformedObject.new(ret)
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
|
data/lib/crystalscad.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crystalscad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joachim Glauche
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-09-08 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Inspired by SolidPython, based on RubyScad
|
22
|
+
email:
|
23
|
+
- webmaster@joaz.de
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Gemfile
|
32
|
+
- LICENSE.txt
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- crystalscad.gemspec
|
36
|
+
- lib/crystalscad.rb
|
37
|
+
- lib/crystalscad/CrystalScad.rb
|
38
|
+
- lib/crystalscad/version.rb
|
39
|
+
homepage: http://github.com/Joaz/CrystalScad
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 53
|
53
|
+
segments:
|
54
|
+
- 1
|
55
|
+
- 9
|
56
|
+
- 3
|
57
|
+
version: 1.9.3
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements:
|
68
|
+
- rubyscad
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.15
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Generate OpenSCAD scripts with ruby
|
74
|
+
test_files: []
|
75
|
+
|