diff options
Diffstat (limited to 'sample/trick2018/05-tompng')
-rw-r--r-- | sample/trick2018/05-tompng/authors.markdown | 3 | ||||
-rw-r--r-- | sample/trick2018/05-tompng/entry.rb | 41 | ||||
-rw-r--r-- | sample/trick2018/05-tompng/preview_of_output.png | bin | 0 -> 66800 bytes | |||
-rw-r--r-- | sample/trick2018/05-tompng/remarks.markdown | 31 |
4 files changed, 75 insertions, 0 deletions
diff --git a/sample/trick2018/05-tompng/authors.markdown b/sample/trick2018/05-tompng/authors.markdown new file mode 100644 index 0000000000..26ebe24da6 --- /dev/null +++ b/sample/trick2018/05-tompng/authors.markdown @@ -0,0 +1,3 @@ +* Tomoya Ishida (tompng) + * tomoyapenguin@gmail.com + * cctld: jp diff --git a/sample/trick2018/05-tompng/entry.rb b/sample/trick2018/05-tompng/entry.rb new file mode 100644 index 0000000000..31522b6de2 --- /dev/null +++ b/sample/trick2018/05-tompng/entry.rb @@ -0,0 +1,41 @@ + X=[];def self.method_missing n;n.to_s.chars;end + l=[];def l.-a;X<<a=[nil,*a];a;end;def l.+a;self-a;end + class Array;def-@;[]-self;end;def-a;replace [*self,nil,*a + ]end;alias +@ -@;alias + -;end;def gen3d f;yield;b=['solid obj'];w, + h=X[0].size,X.size;X<<[];a=->r,z,dr,dz{;r-=w/2.0;z*=2;r2,z2=r+dr,z+dz*2;if r>0||r2> + 0;r=[0,r].max;r2=[0,r2].max;16.times{|i|m=Math;p=m::PI/8;;c,s=m.cos(t=i*p),m.sin(t) + c2,s2=m.cos(t=(i+1)*p),m.sin(t);t-=p/2;[[0,1,2],[0,2,3]].map{|a|b.push [:facet,'n'+ + + 'ormal',dz*m.cos(t),dz*m.sin(t),-dr]*' ','outer loop',a.map{|i|'v'+ + ++ "ertex #{[[r*c,r*s,z],[r*c2,r*s2,z],[r2*c2,r2*s2,z2],[r2* + +c, r2*s,z2]][i]*' '}"},:endloop,:endfacet}}end};(0...h). + map{| y|w.times{|x|[X[y-1][x]||a[x,y,1,0],X[y+1][x]|| + a[x+1,y+ + 1,-1,0],X[ + y][x-+1]||a[ + x,y+1,0,-1],X[y + ][x++1]||a[x+1,y, + 0,1]]if X[y][x]}} + s=[b,'end'+b[0]]* + $/;File.write(f, + s);X.replace( + []);end + +gen3d 'wine_glass.stl' do + l--ww------------------ww--l + l--ww------------------ww--l + l--ww++++++++++++++++++ww--l + l--ww++++++++++++++++++ww--l + l--ww++++++++++++++++++ww--l + l--ww++++++++++++++++++ww--l + l---ww++++++++++++++++ww---l + l----www++++++++++++www----l + l------www++++++++www------l + l--------wwwwwwwwww--------l + l-----------wwww-----------l + l------------ww------------l + l------------ww------------l + l------------ww------------l + l-----------wwww-----------l + l---------wwwwwwww---------l + l----wwwwwwwwwwwwwwwwww----l +end diff --git a/sample/trick2018/05-tompng/preview_of_output.png b/sample/trick2018/05-tompng/preview_of_output.png Binary files differnew file mode 100644 index 0000000000..db511ee2f3 --- /dev/null +++ b/sample/trick2018/05-tompng/preview_of_output.png diff --git a/sample/trick2018/05-tompng/remarks.markdown b/sample/trick2018/05-tompng/remarks.markdown new file mode 100644 index 0000000000..17be56b61f --- /dev/null +++ b/sample/trick2018/05-tompng/remarks.markdown @@ -0,0 +1,31 @@ +### Remarks + +Just run it with no argument: + + ruby entry.rb + +I confirmed the following implementations/platforms: + +* ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16] +* ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16] +* ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16] + +### Description + +This program will generate `wine_glass.stl`, a 3D data file(STL format) of a wine glass. +You can change the shape by modifying the DSL part. +For sake cup: +```ruby +gen3d 'ochoko.stl' do + l------------------------l + l-ww------------------ww-l + l-ww------------------ww-l + l-ww++++++++++++++++++ww-l + l-ww++++++++++++++++++ww-l + l--ww++++++++++++++++ww--l + l---wwww++++++++++wwww---l + l----wwwwwwwwwwwwwwww----l + l----www----------www----l +end +``` +`+` and `-` are the same meaning(just for apperance) |