Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@YuukiToriyama

Workers_of_the_world_unite.rb

More than 1 year has passed since last update.
万国の労働者よ団結せよ
______________________________
________________Wo____________
__________rker__sOfT__________
________heWorl____dUni________
______te!Work______ersO______
____fTheWorl________dUnite____
__!WorkersOfT________heWo____
____rldU__nite!______Worker__
____________sOfThe______Worl__
______________dUnite__!Work__
________er______sOfTheWorl____
______dUnite______!Work______
__ersOfT__heWorldUnite!Wo____
__rker______sOfThe____Worl____
______________________________
unite.rb
class Array
    def msg_fill(str)
        message = ""
        data = self.join("\n").split("")
        for i in 1..self.join("").length
            if message.length == 0
                message.concat(str.chomp)
            end
            if data[i-1] == "0"
                data[i-1] = message.slice!(0,2)
            end
        end
        return data.join("").gsub("1", "__")
    end
end

hammer_and_sickle = "1FFFFFDFFC9FF19FC39F0F1C0F3C8E3F8E7F88FB83E38F100E719FFFF".hex.to_s(2).scan(/.{15}/)
the_manifest = "WorkersOfTheWorldUnite!"
#the_manifest = "ПролетарииВсехСтран,Соединяйтесь!"

puts hammer_and_sickle.msg_fill(the_manifest)

解説

以前投稿したПролетарии всех стран, соединяйтесь!の応用です。Array#msg_fill()というメソッドを定義して鎌と鎚(☭)のAAのなかに文字列を埋め込めるようにしました。

AAはどのように作ってあるの?

"1FFFFFDFFC9FF19FC39F0F1C0F3C8E3F8E7F88FB83E38F100E719FFFF".hex.to_s(2).scan(/.{15}/)

最終行付近にあるこのコードを実行してみると、次のような結果が得られます。

111111111111111
111111110111111
111110010011111
111100011001111
111000011100111
110000111100011
100000011110011
110010001110001
111111000111001
111111100010001
111101110000011
111000111000111
100010000000011
100111000110011
111111111111111

0,1で絵を描いたものをソースコードにそのまま書いてもいいんですが、それではおもしろくないので、0,1の絵から改行を取って一行にして、二進数とみなし、更にそれを16進数に変換したものを保存してあります。

msg_fill()の使い方

上で述べたような0,1で描いた絵の各行を格納した配列に、msg_fill()メソッドをあてると、引数で指定したメッセージをAAの0の部分に埋め込むことができます。好きなメッセージを埋め込んでみてください!

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
YuukiToriyama
#シェル芸

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?