crystalscad 0.4.2 → 0.5
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.
- checksums.yaml +15 -0
- data/examples/openscad_examples/example002.rb +0 -1
- data/examples/pipe.rb +41 -0
- data/examples/printed_gear.rb +4 -4
- data/examples/printed_thread2.rb +4 -9
- data/lib/crystalscad.rb +1 -0
- data/lib/crystalscad/CrystalScad.rb +6 -1
- data/lib/crystalscad/Pipe.rb +150 -0
- data/lib/crystalscad/PrintedThreads.rb +3 -2
- data/lib/crystalscad/version.rb +1 -1
- metadata +7 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjZhYjQ1ZDg1OTI4YzAyODE5ZDAxZWMwYmRjYTQ2NzYwMGQyMGMwOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDk5ZWIzOTRhNTZlZDBhMmE4MzJmYTdlNTZjMDUwNDUxNTA0NWYwNA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzBmZGEyMmEwNmQzZThlMjZlM2E1MDU5YTJiODMyNjE2YzkwNWM2MjI5Y2Yz
|
10
|
+
ODdiNDg3ZWJjODU2NTkxNjQ0MDg3ZDgyZWY5NTdlNjY3OGRhOGJkMGU1ODFi
|
11
|
+
OGQ0NTZiYzQzMzQ1YTA4ZWZiOWMwYzFmNjdkN2Q1ZDgyNTAyMTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDlkMTA2OTY3M2JhMzgwN2QzNDMwOTQyMDdmNDVjMWFiNjM2MWRkODg0OTZk
|
14
|
+
ZWQzZmExMGE3M2YwYTdlOWZhNmQ4ZTc5N2Q2ZGUwN2U1MDNjNTYzZjRkNzll
|
15
|
+
OTQ1ODA1MjYzMTdhMGU3YWU0NDhkYWMxMzNlYzU5N2ZiODU3NTI=
|
data/examples/pipe.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby1.9.3
|
2
|
+
require "rubygems"
|
3
|
+
require "crystalscad"
|
4
|
+
include CrystalScad
|
5
|
+
|
6
|
+
|
7
|
+
class MyPipe < CrystalScad::Pipe
|
8
|
+
def shape
|
9
|
+
@line_rotation = 30
|
10
|
+
return circle(d:@diameter,fn:6)
|
11
|
+
end
|
12
|
+
|
13
|
+
def inner_shape
|
14
|
+
circle(d:6)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
pipe = MyPipe.new(diameter:10)
|
19
|
+
|
20
|
+
pipe.line(10)
|
21
|
+
pipe.ccw(20,30,"yellow")
|
22
|
+
pipe.line(30)
|
23
|
+
|
24
|
+
pipe.cw(30,60,"blue")
|
25
|
+
pipe.ccw(30,45,"green")
|
26
|
+
pipe.line(3)
|
27
|
+
pipe.ccw(30,160,"blue")
|
28
|
+
pipe.ccw(30,60,"green")
|
29
|
+
|
30
|
+
|
31
|
+
#pipe.cw(30,60,"blue")
|
32
|
+
#pipe.cw(20,60,"green")
|
33
|
+
#pipe.cw(10,60,"black")
|
34
|
+
#pipe.line(33)
|
35
|
+
#pipe.cw(30,90,"white")
|
36
|
+
#pipe.cw(15,95,"silver")
|
37
|
+
#pipe.line(10,"pink")
|
38
|
+
res = pipe.pipe
|
39
|
+
|
40
|
+
res.save("pipe.scad","$fn=64;")
|
41
|
+
|
data/examples/printed_gear.rb
CHANGED
@@ -4,11 +4,11 @@ require "crystalscad"
|
|
4
4
|
include CrystalScad
|
5
5
|
|
6
6
|
|
7
|
-
g1 = PrintedGear.new(module:2.0,teeth:40,bore:
|
7
|
+
g1 = PrintedGear.new(module:2.0,teeth:40,bore:8,height:4)
|
8
8
|
g2 = PrintedGear.new(module:2.0,teeth:20,bore:5,height:4,rotation:0.5) # rotation in number of teeth
|
9
9
|
|
10
|
-
res = g1.show.color("red")
|
11
|
-
res += g2.show.
|
10
|
+
res = g1.show.color("red")
|
11
|
+
res += g2.show.translate(x:g1.distance_to(g2))
|
12
12
|
|
13
|
-
res.save("printed_gear.scad")
|
13
|
+
res.save("printed_gear.scad","$fn=64;")
|
14
14
|
|
data/examples/printed_thread2.rb
CHANGED
@@ -4,16 +4,11 @@ require "crystalscad"
|
|
4
4
|
include CrystalScad
|
5
5
|
|
6
6
|
|
7
|
-
t1 = PrintedThread.new(diameter:20, pitch:5, length:22.5, internal:true)
|
8
|
-
t2 = PrintedThread.new(diameter:20, pitch:5, length:20, internal:false)
|
9
|
-
|
10
|
-
#t1 = PrintedThread.new(diameter:12, pitch:1.75, length:22.5, internal:true)
|
11
|
-
#t2 = PrintedThread.new(diameter:12, pitch:1.75, length:20, internal:false)
|
12
|
-
|
13
|
-
|
14
|
-
res = cube([25,25,z=26]).center_xy.color(a:40)
|
15
|
-
res -= t1.output.translate(z:0)
|
7
|
+
t1 = PrintedThread.new(diameter:20, pitch:2.5, length:22.5, internal:true)
|
8
|
+
t2 = PrintedThread.new(diameter:20, pitch:2.5, length:20, internal:false)
|
16
9
|
|
10
|
+
res = cube([25,25,z=26]).center_xy
|
11
|
+
res -= t1.output
|
17
12
|
res += t2.output.translate(z:z)
|
18
13
|
|
19
14
|
res.save("printed_thread2.scad")
|
data/lib/crystalscad.rb
CHANGED
@@ -219,7 +219,12 @@ module CrystalScad
|
|
219
219
|
class Square < Primitive
|
220
220
|
def initialize(*args)
|
221
221
|
super(args)
|
222
|
-
|
222
|
+
if args[0][:size].kind_of? Array
|
223
|
+
@x,@y = args[0][:size].map{|l| l.to_f}
|
224
|
+
else
|
225
|
+
@x = args[0][:size].to_f
|
226
|
+
@y = @x
|
227
|
+
end
|
223
228
|
end
|
224
229
|
|
225
230
|
def to_rubyscad
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# This file is part of CrystalScad.
|
2
|
+
#
|
3
|
+
# CrystalScad is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# CrystalScad is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with CrystalScad. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
module CrystalScad
|
19
|
+
class Pipe
|
20
|
+
attr_accessor :x,:y, :pipe
|
21
|
+
def radians(a)
|
22
|
+
a/180.0 * Math::PI
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(args={})
|
26
|
+
@diameter = args[:diameter]
|
27
|
+
@pipe = nil
|
28
|
+
@line_rotation = 0 # z rotation in case needed with fn values
|
29
|
+
end
|
30
|
+
|
31
|
+
def shape
|
32
|
+
res = circle(d:@diameter)
|
33
|
+
end
|
34
|
+
|
35
|
+
def inner_shape
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# go clockwise
|
40
|
+
def cw(radius,angle,color=nil)
|
41
|
+
if angle > 360
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
# since bent can only do up to 90°, splitting it up in chunks in order to grow it
|
45
|
+
if angle > 90
|
46
|
+
return cw(radius,90,color) + cw(radius,angle-90,color)
|
47
|
+
end
|
48
|
+
|
49
|
+
if @pipe == nil
|
50
|
+
@pipe = bent_cw(radius,angle)
|
51
|
+
@pipe = @pipe.color(color) unless color == nil
|
52
|
+
else
|
53
|
+
rotated_pipe = @pipe.rotate(z:-angle)
|
54
|
+
pipe_piece = bent_cw(radius,angle)
|
55
|
+
pipe_piece = pipe_piece.color(color) unless color == nil
|
56
|
+
@pipe = pipe_piece + rotated_pipe.translate(x:x,y:y-radius)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# go counter clockwise
|
61
|
+
def ccw(radius,angle,color=nil)
|
62
|
+
if angle > 360
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
# since bent can only do up to 90°, splitting it up in chunks in order to grow it
|
66
|
+
if angle > 90
|
67
|
+
return ccw(radius,90,color) + ccw(radius,angle-90,color)
|
68
|
+
end
|
69
|
+
|
70
|
+
if @pipe == nil
|
71
|
+
@pipe = bent_ccw(radius,angle)
|
72
|
+
@pipe = @pipe.color(color) unless color == nil
|
73
|
+
else
|
74
|
+
rotated_pipe = @pipe.rotate(z:angle)
|
75
|
+
pipe_piece = bent_ccw(radius,angle)
|
76
|
+
pipe_piece = pipe_piece.color(color) unless color == nil
|
77
|
+
@pipe = pipe_piece + rotated_pipe.translate(x:x,y:y+radius)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def line(length,color=nil)
|
83
|
+
if @pipe == nil
|
84
|
+
@pipe = create_line(length,color)
|
85
|
+
else
|
86
|
+
@pipe = @pipe.translate(x:length) + create_line(length,color)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def create_line(length,color=nil)
|
93
|
+
res = shape.linear_extrude(h:length)
|
94
|
+
if inner_shape
|
95
|
+
res -= inner_shape.linear_extrude(h:length+0.2).translate(z:-0.1)
|
96
|
+
end
|
97
|
+
if color
|
98
|
+
res = res.color(color)
|
99
|
+
end
|
100
|
+
res.rotate(z:@line_rotation).rotate(y:90)
|
101
|
+
end
|
102
|
+
|
103
|
+
def bent_cw(radius,angle)
|
104
|
+
res = shape.translate(x:radius).rotate_extrude(convexity:10)
|
105
|
+
res -= inner_shape.translate(x:radius).rotate_extrude(convexity:10) unless inner_shape == nil
|
106
|
+
|
107
|
+
len = radius+@diameter/2.0
|
108
|
+
@x = Math::sin(radians(angle))*len
|
109
|
+
@y = Math::cos(radians(angle))*len
|
110
|
+
cut = polygon(points:[[0,0],[0,len],[@x,@y]]).scale(2)
|
111
|
+
|
112
|
+
# for working with it
|
113
|
+
len = radius #- @diameter / 2.0
|
114
|
+
@x = Math::sin(radians(angle))*len
|
115
|
+
@y = Math::cos(radians(angle))*len
|
116
|
+
|
117
|
+
|
118
|
+
res *= cut.linear_extrude(h:100).translate(z:-50)
|
119
|
+
|
120
|
+
# Positioning it on 0
|
121
|
+
|
122
|
+
return res.translate(y:-radius)
|
123
|
+
end
|
124
|
+
|
125
|
+
def bent_ccw(radius,angle)
|
126
|
+
res = shape.translate(x:radius).rotate_extrude(convexity:10)
|
127
|
+
res -= inner_shape.translate(x:radius).rotate_extrude(convexity:10) unless inner_shape == nil
|
128
|
+
|
129
|
+
len = radius+@diameter/2.0
|
130
|
+
@x = Math::sin(radians(angle))*len
|
131
|
+
@y = Math::cos(radians(angle))*len
|
132
|
+
cut = polygon(points:[[0,0],[0,len],[@x,@y]]).scale(2)
|
133
|
+
|
134
|
+
# for working with it
|
135
|
+
len = radius #- @diameter / 2.0
|
136
|
+
@x = Math::sin(radians(angle))*len
|
137
|
+
@y = -1*Math::cos(radians(angle))*len
|
138
|
+
|
139
|
+
|
140
|
+
res *= cut.linear_extrude(h:100).translate(z:-50)
|
141
|
+
res = res.mirror(y:1)
|
142
|
+
# Positioning it on 0
|
143
|
+
|
144
|
+
return res.translate(y:radius)
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
@@ -37,6 +37,7 @@ module CrystalScad::PrintedThreads
|
|
37
37
|
end
|
38
38
|
# cut to length
|
39
39
|
res *= cube(x:@args[:diameter]*1.1, y:@args[:diameter]*1.1, z:@args[:length]).center.translate(z:@args[:length]/2.0)
|
40
|
+
|
40
41
|
if @args[:internal]
|
41
42
|
# Solid center, including Dmin truncation.
|
42
43
|
res += cylinder(r:@args[:diameter]/2.0 - h*5.0/8.0, h:@args[:length], segments:number_of_segments)
|
@@ -95,8 +96,8 @@ module CrystalScad::PrintedThreads
|
|
95
96
|
fraction_circle = 1.0/n_segments
|
96
97
|
|
97
98
|
h = pitch * Math::cos(radians(30))
|
98
|
-
outer_r = radius + (internal ? h/
|
99
|
-
|
99
|
+
outer_r = radius + (internal ? h/20 : 0) # Adds internal relief.
|
100
|
+
|
100
101
|
inner_r = radius - 0.875*h # Does NOT do Dmin_truncation - do later with cylinder.
|
101
102
|
|
102
103
|
# Make these just slightly bigger (keep in proportion) so polyhedra will overlap.
|
data/lib/crystalscad/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalscad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.5'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joachim Glauche
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rubyscad
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: require_all
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: wijet-thor
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: observr
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -95,6 +86,7 @@ files:
|
|
95
86
|
- examples/openscad_examples/example003.rb
|
96
87
|
- examples/openscad_examples/example004.rb
|
97
88
|
- examples/openscad_examples/example005.rb
|
89
|
+
- examples/pipe.rb
|
98
90
|
- examples/printed_gear.rb
|
99
91
|
- examples/printed_gear2.rb
|
100
92
|
- examples/printed_thread.rb
|
@@ -109,6 +101,7 @@ files:
|
|
109
101
|
- lib/crystalscad/Gears.rb
|
110
102
|
- lib/crystalscad/Hardware.rb
|
111
103
|
- lib/crystalscad/LinearBearing.rb
|
104
|
+
- lib/crystalscad/Pipe.rb
|
112
105
|
- lib/crystalscad/PrintedThreads.rb
|
113
106
|
- lib/crystalscad/ScrewThreads.rb
|
114
107
|
- lib/crystalscad/version.rb
|
@@ -120,26 +113,25 @@ files:
|
|
120
113
|
homepage: http://github.com/Joaz/CrystalScad
|
121
114
|
licenses:
|
122
115
|
- GPL-3
|
116
|
+
metadata: {}
|
123
117
|
post_install_message:
|
124
118
|
rdoc_options: []
|
125
119
|
require_paths:
|
126
120
|
- lib
|
127
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
122
|
requirements:
|
130
123
|
- - ! '>='
|
131
124
|
- !ruby/object:Gem::Version
|
132
125
|
version: 1.9.3
|
133
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
-
none: false
|
135
127
|
requirements:
|
136
128
|
- - ! '>='
|
137
129
|
- !ruby/object:Gem::Version
|
138
130
|
version: '0'
|
139
131
|
requirements: []
|
140
132
|
rubyforge_project:
|
141
|
-
rubygems_version:
|
133
|
+
rubygems_version: 2.2.2
|
142
134
|
signing_key:
|
143
|
-
specification_version:
|
135
|
+
specification_version: 4
|
144
136
|
summary: CrystalScad is a framework for programming OpenScad models in Ruby
|
145
137
|
test_files: []
|