1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* sample/trick2013/: added the award-winning entries of TRICK 2013.

See https://github.com/tric/trick2013 for the contest outline.
  (Matz has approved the attachment.)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2013-12-25 03:45:15 +00:00
parent 1e7a929c1d
commit e8052778c1
16 changed files with 301 additions and 0 deletions

View file

@ -0,0 +1,3 @@
* Yusuke Endoh
* mame@tsg.ne.jp
* cctld: jp

View file

@ -0,0 +1,97 @@
eval$C=%q(at_exit{
open("/dev/dsp","wb"){|g|h=[0]*80
$><<"\s"*18+"eval$C=%q(#$C);S=%:"
(S<<m=58).lines{|l|s=[128]*n=20E2
t=0; h.map!{|v|d=?!==l[
t]?1 :(l[
t]== ?#)?
0*v= 6:03
(v<1 ?[]:
0..n -1).
each {|z|
s[z] +=2*
M.sin(($*[0] ||1)
.to_f*M.sin(y= 40*(z+m)*2**
(t/12E0)/463)+ y)*(v-z*d/n)};
t+=1;v-d};m+= n;g.flush<<(s.
pack"C*"); puts(l)}}};M=
Math);S=%:
Jesu, Joy of Man's Desiring
Johann Sebastian Bach
#
| #
| #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | #
# # # #
| | | #
| #| #
# # | #
| | | #
| | # #
# # # #
| | # |
| | # #
# # # #
| | | #
| | #
# # # #
| | # |
| # # |
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| | # #
# # # #
| | | #
| # #
# # #
| | | #
| # | #
# # # #
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | :

Binary file not shown.

View file

@ -0,0 +1,47 @@
### Remarks
Run the program under a platform that `/dev/dsp` is available.
For example, if you are using pulseaudio, use `padsp`:
padsp ruby entry.rb
Please see Limitation if you want to run this program on os x.
I confirmed the following platforms.
* ruby 2.0.0p0 (2013-02-24 revision 39474) [x86\_64-linux]
* ruby 1.9.3p194 (2012-04-20 revision 35410) [x86\_64-linux]
* ruby 1.9.3p327 (2012-11-10 revision 37606) [x86\_64-darwin10.8.0]
For those who are lazy, I'm attaching a screencast.
### Description
This program is a music-box quine.
It prints itself with playing "Jesu, Joy of Man's Desiring".
### Internal
Like a real music box, this program consists of a mechanical part (code) and a piano roll.
In the piano roll, `#` represents a pin that hits a note, and `|` represents a slur.
The leftmost column corresponds 110Hz (low A).
Every column corresponds a semitone higher than the left one.
This program uses [the frequency modulation synthesis](http://en.wikipedia.org/wiki/Frequency_modulation_synthesis) to play the sound like a music-box.
You can create a different-sounding tone by changing the parameter.
For example, the following will play the sound like a harpsichord.
padsp ruby entry.rb 2.0
Note that this program does *not* use an idiom to remove whitespace, such as `.split.join`. All newlines and spaces do not violate any of the Ruby syntax rules.
### Limitation
On os x, `/dev/dsp` is not available.
You have to use sox by replacing the following part:
open("/dev/dsp","wb")
with:
IO.popen("./pl","wb")