mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
sample/trick2018/: adds the top-five entries of TRICK 2018
See https://github.com/tric/trick2018 for TRICK 2018. Fixes #14930. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8d0f5f1bfa
commit
e613cdd53d
21 changed files with 372 additions and 0 deletions
3
sample/trick2018/01-kinaba/authors.markdown
Normal file
3
sample/trick2018/01-kinaba/authors.markdown
Normal file
|
@ -0,0 +1,3 @@
|
|||
* kinaba
|
||||
* twitter.com/kinaba
|
||||
* cctld: jp
|
8
sample/trick2018/01-kinaba/entry.rb
Normal file
8
sample/trick2018/01-kinaba/entry.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
alias BEGIN for unless def class
|
||||
super true or return defined? next
|
||||
break while begin undef do end
|
||||
rescue then retry else undef module
|
||||
nil ensure case if yield __LINE__
|
||||
self and redo elsif not __FILE__
|
||||
alias END in end when __ENCODING__
|
||||
end until false end
|
55
sample/trick2018/01-kinaba/remarks.markdown
Normal file
55
sample/trick2018/01-kinaba/remarks.markdown
Normal file
|
@ -0,0 +1,55 @@
|
|||
### Remarks
|
||||
|
||||
Just run it with no argument:
|
||||
|
||||
ruby entry.rb
|
||||
|
||||
(Anyway it is just a no-op program. The above command only verifies
|
||||
that entry.rb is a valid Ruby program.)
|
||||
|
||||
I confirmed the following implementations/platforms:
|
||||
|
||||
* ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32]
|
||||
|
||||
### Description
|
||||
|
||||
First, look at
|
||||
|
||||
https://docs.ruby-lang.org/ja/latest/doc/spec=2flexical.html#reserved
|
||||
|
||||
and then, look at entry.rb.
|
||||
|
||||
The source code of entry.rb consists only of reserved words of Ruby,
|
||||
and all the reserved words are used in the code, in a way that the code
|
||||
forms a valid Ruby program. No compile error, no warning, or no runtime error.
|
||||
|
||||
|
||||
### Internals
|
||||
|
||||
Difficult (and interesting) points of the theme are:
|
||||
|
||||
* Since many of the reserved words define program structures, we cannot
|
||||
use them independently. For instance, `retry` must be inside `rescue`,
|
||||
or `break`/`next`/`redo` must be inside a looping construct.
|
||||
Or, jump-out statements cannot occur at a position that requires a
|
||||
value; `if return then true end` is a "void value expression" syntax error.
|
||||
* Inserting newlines for each 6 word (to match with the spec html) is also
|
||||
an interseting challenge, since Ruby is sensitive to newlines.
|
||||
|
||||
Tricks used in the code are:
|
||||
|
||||
* def/alias/undef can take even reserved words as parameters.
|
||||
That is, `def class ... end` defines a method named `class`.
|
||||
The feature is crucial since otherwise `BEGIN` etc inevitably
|
||||
introduces non-reserved tokens (like `{}`).
|
||||
* `defined?` can take some reserved words too (which I didn't know
|
||||
until trying to write this program.)
|
||||
* "void value expression" can be avoided by using `or` or `and`.
|
||||
`if begin return end then true end` is a syntax error, but
|
||||
`if begin false or return end then true end` is not.
|
||||
|
||||
|
||||
### Limitation
|
||||
|
||||
Sad to say that it's not a "perfect pangram".
|
||||
It uses 'alias' and 'undef' twice, and 'end' 4 times.
|
3
sample/trick2018/02-mame/authors.markdown
Normal file
3
sample/trick2018/02-mame/authors.markdown
Normal file
|
@ -0,0 +1,3 @@
|
|||
* Yusuke Endoh
|
||||
* mame@ruby-lang.org
|
||||
* cctld: jp
|
15
sample/trick2018/02-mame/entry.rb
Normal file
15
sample/trick2018/02-mame/entry.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
'';eval(r=%q(->z{r="'';eval(r=\
|
||||
%q(#{r}))[%q`#{z}`]";i=-040;30.
|
||||
times{|n|(15+n%2*15-n/2).times{
|
||||
r<<r[i+=(1.-n&2)*(32-n%2*31)]}}
|
||||
i=r[524,0]=?\0;eval(r[479..-1])
|
||||
c['"']}))[%q`GFEDCBA"+"[e\"'"'t
|
||||
kE*;;\";" TRICK2018 ";tb,;{{r
|
||||
2E0$ob[us@*0)[90,336])_#i\n}s#i
|
||||
0H}>["t]];};o[1,?\n*8];ex"-}eac
|
||||
1Hl<1[-1]*2*t=n%2];o[14-n,0)mvk
|
||||
8M$<4,?\n];15.times{|n|;o[35ie2
|
||||
!Pss.slice!(0,1)+x;sleep(0.0t;0
|
||||
'W=%q"<<95<<$s<<95;o=->n,x{n.'1
|
||||
;@[2]}|\e../,%@s="'%trick2018!8
|
||||
eval$s=%q_eval($s.gsub!(/#{%@`]
|
16
sample/trick2018/02-mame/remarks.markdown
Normal file
16
sample/trick2018/02-mame/remarks.markdown
Normal file
|
@ -0,0 +1,16 @@
|
|||
This program quines with animation.
|
||||
|
||||
```
|
||||
$ ruby entry.rb
|
||||
```
|
||||
|
||||
Of course, the output is executable.
|
||||
|
||||
```
|
||||
$ ruby entry.rb > output
|
||||
$ ruby output
|
||||
```
|
||||
|
||||
Note, we don't cheat. This program uses escape sequences just for moving the cursor. It doesn't use attribution change nor overwrite to hide any code.
|
||||
|
||||
The program is crafted so that it works in two ways; it works as a normal program text, and, it also works when it is rearranged in a spiral order. Some parts of the code are actually overlapped.
|
2
sample/trick2018/03-tompng/Gemfile
Normal file
2
sample/trick2018/03-tompng/Gemfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
ruby '2.5.0'
|
||||
gem 'chunky_png'
|
15
sample/trick2018/03-tompng/Gemfile.lock
Normal file
15
sample/trick2018/03-tompng/Gemfile.lock
Normal file
|
@ -0,0 +1,15 @@
|
|||
GEM
|
||||
specs:
|
||||
chunky_png (1.3.8)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
chunky_png
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.5.0p0
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.1
|
3
sample/trick2018/03-tompng/authors.markdown
Normal file
3
sample/trick2018/03-tompng/authors.markdown
Normal file
|
@ -0,0 +1,3 @@
|
|||
* Tomoya Ishida (tompng)
|
||||
* tomoyapenguin@gmail.com
|
||||
* cctld: jp
|
31
sample/trick2018/03-tompng/entry.rb
Normal file
31
sample/trick2018/03-tompng/entry.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
X=[];class String def-@;replace ?-+self end;def-a;X.reject!{|x|x.
|
||||
__id__==__id__};a.replace(self+?-+a) end end;at_exit{eval C=(Zlib
|
||||
.inflate Integer((X*?-).tr(?-,'').tr('q-z','0-9'),26).digits(256)
|
||||
.pack'C*')};def method_missing n;(X<<n.to_s)[-1]end;require'zlib'
|
||||
fzygtoxyzgntmdmuwvfoffbpmvzojpkhczvjvjdbtscnldwbdoprackddovivvmkz
|
||||
ponzmosvtjciwkgaslscxxxwudeesmmqpfhislxuxnnypulxstzgobyaekqqhbjcg
|
||||
mvko------------ddkeys----eivhnccaqyiw---bzyccmt-----------ymtnge
|
||||
jwhi--------------pjxf------mdarbtumnv---qasda--------------gmwdt
|
||||
wrtk---qtpzgnce----fsl-------fkgzgtbpp---gwnm----pxkpqkdiw---owga
|
||||
momz---yjjvpnvar---zeo---v-----duvalwu---nsqt---waofemwakivnyqkjd
|
||||
fzag---uhvusmkl----kzb---rhc----iutzjr---mqlh---ayijpwativpweaato
|
||||
xexs--------------rvgv---pjdz-----lkkg---uiaw---lovitupw-----fwmn
|
||||
kfru------------jvjpgv---jskycf----pal---gbuf---hfdnywog-----iuca
|
||||
pntn---apmkqroeuzwuwkw---gqnmgof-----b---hlpl---vkkyhfyrqfr--jwrl
|
||||
kmdb---dhspujhmtgrkccu---uonfummdt-------rqfw----bpiactehwp--fncq
|
||||
yzvz---gdaxebplhfndran---ytfmviryeh------hqwkl---------------nced
|
||||
bibu---fnkdthgldhkxxjg---rwnmpudhbqin----gucoyki------------hfura
|
||||
cqdgqpyzqfzknvdjoxxhpjulwwyebtocxdrvklbuviwwcatlmdosxfvwntzbijguy
|
||||
iglrvvzlxerflupxvsyujfacuwhrvmnecgtewtqkhtdggcltejiyqcluclkycwvzg
|
||||
vvxfysvttfbeglvrlngntdngzyhqrmltazwdydxrsvjploembhgxdvfmmhepbschm
|
||||
brn--iqrcdb--evv----tqp------lg--uein-wzut--mr------wkh------foqz
|
||||
zsf--srjnjp--ampb--pfio--hgtekx--rrr---fwd--jn--xqkezcz--vsb--nya
|
||||
khrc--evlr--oioxs--mqce--bqfmag--bwz---xda--qw--jnuzelr--qzi--itx
|
||||
mdxd--duso--wxbot--nmon--ugnbdpc--a--c--e--hlg--twxndre--tby--rhg
|
||||
evhbn--zb--dtxmiz--dpia------vie--h--i--t--shh------kfn------owna
|
||||
ealmt--kb--scxdjy--smvl--dqmgebk--t--s--t--gfd--updcbnc--rh--dwwp
|
||||
dvpnxb----wpljjdy--kolc--qflyleok---xkv---usbj--jhrawbn--ewx--bgf
|
||||
eaqwrw----ejwxhet--dice--eoczconm---urz---rqyp--hovvvfc--bskj--el
|
||||
aocjcts--jtumwxm----mgy------xpaoq-jtwqr-aipay------dhy--iync--hk
|
||||
sckddmvuvvuhhqstumaykvczaaujrumqbbqsdvdycplyrlkkojlxnkrhbbrmnjxyf
|
||||
cdtcmpfmjvthwkpzucbblttgumomlxnxwjeypfeagaukfzeokzxjebkpigcvlqnso
|
44
sample/trick2018/03-tompng/output.txt
Normal file
44
sample/trick2018/03-tompng/output.txt
Normal file
|
@ -0,0 +1,44 @@
|
|||
undef p;X=[];class String def-@;replace ?-+dup end;def-a;X.reject!{|x|x.__id__==__id__};a.replace(self+?-+a) end end;at_exit{eval C=
|
||||
(Zlib.inflate (X*?-).tr(?-,'').tr('q-z','0-9').to_i(26).digits(256).pack'C*')};def method_missing n;(X<<n.to_s)[-1]end;require'zlib'
|
||||
gmlztzdculbtzgtjfetuh---k--htf----d-----------------------------------------------------g-b-----s--t-g--------jmuwescmgchftikfjafccs
|
||||
ivchcveidpvxdabnvwyga-f--v-------xf----------------------------------------------------q-v---l-------q---------liiNeawriayymwooxgxqw
|
||||
rfosepqsmojseyezmwbhi--------------ew--------------------------------------------------m---k-r-----------vwu--hiotltdmczwyjmlvbyfqwq
|
||||
uvvykqdjednoqgtcmtfbzs---------f----o--------------------------------------------------t--a------m----x---f-----dldzsakyofetfozfpmrq
|
||||
geusutariiiNiulkjbwlm-----d------------------------------------------------------------j---------o---------x--j-uitzrgwpupwhvendhyno
|
||||
uubvnssiywkklwwdufhhi-rw----k---v-------------------------------------------------------sty-----yg---l---c-v----wkffpskpumolqmkeryzg
|
||||
zrxdaiposwybbzgxdnegh-----g-----ma--n---------------------------------------------------------j----n--b-n-------yqavmscswdogpcgopygt
|
||||
axiqfswlhzeamvymdnteo---q-q-w--------------------------fhrmj-----------------hkou-----------f-----d----u-o------evcuxxegekfgivzzujan
|
||||
nslioftsvqvtkeigvfgwr-------------lyco-----------------igyvg-----------------okuk---------m--b-u--d--y------s---dadjrlykfhtermzfyktu
|
||||
btoxzfpPicxxfligbivvf--------h----yrat---------------------------------------vjwd---------------------d-ki--o--tyqosehopkwttigwwfskp
|
||||
komzvnyrvkjcjwbmdwdkp----------vxphiNdtawn--xms-saketo--jnld----ezulntdaz----nzna-----vhjwt------h----x--x--o--saxxsrkgktqotaluylbkk
|
||||
sclegratyaarmgmepheml----------hwgglhlrfcx--znvmpfsgjx-onhju---gtxsmzqprlt---mjzy---frhdk-------------v---mj----dzjujmbgldfwoybgicwu
|
||||
tfhgnhlzxlwtdtkgzlaca-------------gmex------arlm--------rvmh-ajtgf-----pqal--wcux-zatyi-------------------------xnluwybcugjclmablshn
|
||||
tnjohqtqzivgmyutrssil-------------lcwq------jrf--------gcaii-maie------------vvnfjfqwo--------------------------filivosyhkxcvuwdibwj
|
||||
tyxjiopiFqypvwdzoatuq-------------tdln------cnx---------ffuf-ajvq------------tyyypglpzmj------------------------vtqzwewqdsijrbymvpwn
|
||||
niNffphoehukpvvmzvhyd-------------ahqd------nfr---------jeqk--toap-----mxhyg-tedv---otrwy-----------------------mjxnrktackwxwiajdnuc
|
||||
kkxhuwbvibpvgvcampadi-------------ebmencqz--obf--------wfprz---qmrotkijiqv---ggfp-----hlzw----------------------kastwdpxiyftmypuxbtu
|
||||
xetudmwzpomktgnjkcsyc---------------fwpdx---xb----j-----se-k------tllakc-----gjoo-------we------mic---lktk------ubtnrxvrjzuqlrfrsnmf
|
||||
okdvfvcdbdqkckjialskk---------------------------v---u-------l----------------------------------z--q--qfg--------aaliNbxbjjpxebboneye
|
||||
kcbkjmdclwnfawtfnwkeq----------------------------------j---y-------------------------------a---jmbyo-sgef--gf---extljbozuoofgyvsilct
|
||||
xzoqmsqgzjxxpjqwkjkdd------------------------o--------m-------f---------------------------------n--de-ajz-rzv---fhnpbkrwdxoozpxeaxaf
|
||||
mbcwxuiqdwcmadheiykaa-----------------------q-f------l---i---------------------------------r----zf---k--y---fi--dcnycheytylcgnioauee
|
||||
yekiNacriqoevtdjerqbp----------------------------w---yy-----my----------------------------ko--mnbpskr--c-----j--ozyqpbfovhbhyoprzgqr
|
||||
czwtuopxkdbphocfawvbk--------------------------q-s----j--b---------------------------------hd-xsb----bfiNp--w---fmwuvfambdqvxtzldwmh
|
||||
xysnyrseydlkjcwfbsjnr-------------------------d-d-------------------------------------------f-enpss---qllpwr----almsdidvjwoigvldfqoa
|
||||
lrpbixjpofxocxlflscpo------------------------------q-fyu--z-------------------------------------kfd-z---n-------bqxurujnxzurrdgcojks
|
||||
jetyfdkcekckxbyosbfws-------------wdfhgwuvejjmf-----sxjubpvgcsl-------tnmixpv---------eurabjsdvstfv-------------qcyiqhonwoyixqeonfvp
|
||||
mopPhywsozohitutgmmrb------------zxwtxe--riedeo---mspgpnv--pimlh------jhtzajk--------qqovvq---ldbrh-------------xtooxpayonpcvvtmvpra
|
||||
vvuyiunpoeagdzqjecsub------------klrw------snrc---rrct------aajom--------nsyk--------peea-------azq-------------iNjefdkfhnagjicqwmsm
|
||||
mbwwbfgehhbdmvvlflmee---------------------hkejn---jtbo-------jdtje-------jcei---------afyz-----smtc-------------kksvfjyuaqtohxiohhlz
|
||||
dvfmfrzcmnsfruhqgjuxz------------------dfxdnlk----kkra-------xmmtf-------jwkw----------rdoozxtcho---------------bbwwferxwnnmdzcniicv
|
||||
mfneisdlyeqwynldjgonj----------------jgrjvc-------uxga-------ghnpr-------sers--------scbknx----gmjo-------------moedtnlbflhtlkjibrqk
|
||||
gobwqshnpbdcpjmjaeczr--------------iscsxs---------zfpo-------hhfwy-------qbba-------vhlxc-------ntod------------ndwzdomaptumzejiwqbn
|
||||
snucynymvfpnadyqkzfcv-------------ggze------------kuvfs-----zuhod--------mylo-------jhwyp-----z-pywd------------dqfmpnevmtqcikbrilto
|
||||
aotyxkipebdkassogpcbl-----------wgackesmvvsrihhd---orzndjndlzpb----------eobf-------kkayixzyotqfafa-w-----------mjjxoomwdglwvccozzut
|
||||
rthesuszfwycsqqrtxlot-----------ejcqlhriilqbtrys------lwbkzmvp-----------zzwm-------l--qijwfllndzb-ik-----------mmokqomjepdcotnsiNig
|
||||
nloryyoswwdmefywnnuhph------------------------------------------------------r--r-nd-----h--x--------------------hlgzeqqslwxgtjgghquf
|
||||
nssngjtiudsrvfuxjzclhjhj----------------------------------------------------------t----------------k-f-mp-------obhyehqebtpjbkeepqzt
|
||||
ezogzsimfynqmkteaipejo-g-yser-----------------------------------------------e------h-------------i---y----------qpgcqnltivmmsximbbsy
|
||||
wtjjolwyoselcumgklqwpldkl-ulm-m---------------------------------------------------------------q---u-f--l--------buixfiitufktsqdtnrei
|
||||
tgrtitcewseetlpeuuujb-osdokjozc------------------------------------------n---d-----f--------g--------q--g-------jyyqtezuzmcxgpcwuwfx
|
||||
dpPayqmzxrwhbswwalygfurtkruw-u-k---------------------------------------------d---h------i----------c----i-------ulowcddvjbxthqlxjzbe
|
19
sample/trick2018/03-tompng/remarks.markdown
Normal file
19
sample/trick2018/03-tompng/remarks.markdown
Normal file
|
@ -0,0 +1,19 @@
|
|||
### Remarks
|
||||
|
||||
Bundle install
|
||||
this program depends on `gem chunky_png`
|
||||
|
||||
Run it with the following command:
|
||||
bundle exec ruby entry.rb trick.png
|
||||
bundle exec ruby entry.rb [other png file]
|
||||
|
||||
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]
|
||||
|
||||
### Description
|
||||
|
||||
This program is a png image viewer.
|
||||
The output is an asciiart of the given png file,
|
||||
and it is also a source code of the png viewer itself.
|
BIN
sample/trick2018/03-tompng/trick.png
Normal file
BIN
sample/trick2018/03-tompng/trick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
3
sample/trick2018/04-colin/authors.markdown
Normal file
3
sample/trick2018/04-colin/authors.markdown
Normal file
|
@ -0,0 +1,3 @@
|
|||
* Colin Fulton
|
||||
* justcolin@gmail.com
|
||||
* cctld: us
|
2
sample/trick2018/04-colin/entry.rb
Normal file
2
sample/trick2018/04-colin/entry.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Copyright 2018. Available for use under the terms of the MIT License.
|
||||
$🚀=0;def 🤔 🏷,🤔=0,&b;puts ' '*$🚀+(🤔 ?"":"🚫 ")+🏷;$🚀+=4;b&.[];$🚀-=4;end
|
62
sample/trick2018/04-colin/remarks.markdown
Normal file
62
sample/trick2018/04-colin/remarks.markdown
Normal file
|
@ -0,0 +1,62 @@
|
|||
### Remarks
|
||||
|
||||
Create a Ruby file that requires entry.rb with a series of test in it the run the file using ruby:
|
||||
|
||||
```
|
||||
ruby name_of_test_file.rb
|
||||
```
|
||||
|
||||
To create a test, call 🤔 with two arguments. The first is a string describing what this tests, the second argument is the test assertion. If the assertion is truthy, the test passes. If the assertion if falsy, the test fails.
|
||||
|
||||
```
|
||||
string_1 = "Hello world!"
|
||||
string_2 = "This is not the same!"
|
||||
|
||||
🤔 "The two strings are equal",
|
||||
string_1 == string_2
|
||||
```
|
||||
|
||||
To create a group of tests under a label, call 🤔 with a string describing the group and a block containing the tests in that group.
|
||||
|
||||
```
|
||||
🤔 "This is a group of tests" do
|
||||
# Add other groups and/or tests here.
|
||||
end
|
||||
```
|
||||
|
||||
Here is an example:
|
||||
|
||||
```
|
||||
require './entry'
|
||||
|
||||
🤔 "Math" do
|
||||
🤔 "Addition" do
|
||||
🤔 "One plus one equals two.",
|
||||
1+1 == 2
|
||||
🤔 "One plus one equals eleven. (This should fail.)",
|
||||
1+1 == 11
|
||||
end
|
||||
|
||||
🤔 "Subtraction" do
|
||||
🤔 "One minus one equals zero.",
|
||||
1-1 == 0
|
||||
🤔 "Ten minus one equal nine.",
|
||||
10-1 == 9
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
It has been tested with the following Ruby versions:
|
||||
|
||||
* ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
|
||||
* ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
|
||||
* If you replace `b&.[]` with `b&&b[]` it will work with ruby 2.0.0 as well, but it will be one character longer.
|
||||
|
||||
|
||||
### Description
|
||||
|
||||
The goal was to create a testing library where the test files looked good and the output looked good in as few characters as possible. The result is 68 characters and has one method to handle everything.
|
||||
|
||||
### Limitation
|
||||
|
||||
Your terminal program must support Unicode characters for the test output to look correct. If your terminal does not support Unicode, simply replace the 🚫 in the code with whatever character you want to prefix failing tests.
|
3
sample/trick2018/05-tompng/authors.markdown
Normal file
3
sample/trick2018/05-tompng/authors.markdown
Normal file
|
@ -0,0 +1,3 @@
|
|||
* Tomoya Ishida (tompng)
|
||||
* tomoyapenguin@gmail.com
|
||||
* cctld: jp
|
41
sample/trick2018/05-tompng/entry.rb
Normal file
41
sample/trick2018/05-tompng/entry.rb
Normal file
|
@ -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
|
BIN
sample/trick2018/05-tompng/preview_of_output.png
Normal file
BIN
sample/trick2018/05-tompng/preview_of_output.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
31
sample/trick2018/05-tompng/remarks.markdown
Normal file
31
sample/trick2018/05-tompng/remarks.markdown
Normal file
|
@ -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)
|
16
sample/trick2018/README.md
Normal file
16
sample/trick2018/README.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
This directory contains the award-winning entries of
|
||||
the 3rd Transcendental Ruby Imbroglio Contest for rubyKaigi (TRICK 2018).
|
||||
|
||||
THESE ARE BAD EXAMPLES! You must NOT use them as a sample code.
|
||||
|
||||
* 01-kinaba/entry.rb: "Most reserved" - **Gold award**
|
||||
* 02-mame/entry.rb: "Best spiral" - **Silver award**
|
||||
* 03-tompng/entry.rb: "Best png viewer" - **Bronze award**
|
||||
* 04-colin/entry.rb: "Best one-liner" - 4th prize
|
||||
* 05-tompng/entry.rb: "Most three-dimentional" - 5th prize
|
||||
|
||||
These files are licensed under MIT license.
|
||||
|
||||
For the contest outline and other winning entries, see:
|
||||
|
||||
https://github.com/tric/trick2018
|
Loading…
Reference in a new issue