Skip to content

Instantly share code, notes, and snippets.

@tompng
Last active July 30, 2020 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tompng/b09345c5317d588f1d99d0abe6b4dd13 to your computer and use it in GitHub Desktop.
Save tompng/b09345c5317d588f1d99d0abe6b4dd13 to your computer and use it in GitHub Desktop.
めでたい
require 'chunky_png'
img = ChunkyPNG::Image.from_file 'medetai.png'
imgdata = (1...img.height-1).map{|y|img.width.times.map{|x|img[x,y]>>8==0}}
compressed = imgdata.flatten.chunk(&:itself).map{|a,b|b.size}
puts (0..76).min_by{|i|compressed.map{|a|(a+i).chr}.to_json.size rescue 9999}
data = "3%U&T%+&>,.&6%=&)&->-&%%0&.&-&$.*5($(3/&/&-63''\#$&&-5%1&+'&&'&1&(&#%*&%0'%2&(*$&)&/&+$.%'(.%3%'&$*+&.%9&9%3&&%&(,&-&8&:%3&%&&'-&.%7&&#6&$%.&%%%)+&/'5%'%5%$%.&%+,(1)1%(&5)7''-6++&)2)&C)>'*&-/@"
data = "4&V'U&,'?-/'7&>'*'.?.'&&1'/'.'%/+6)%)40'0'.74(($%''.6&2',(''('2')'$&+'&1(&3')+%'*'0',%/&()/&4&('%+,'/&:':&4''&')-'.'9';&4'&''(.'/&8''$7'%&/'&&&*,'0(6&(&6&%&/'&,-)2*2&)'6*8((.7,,'*3*'D*?(+'.0A"
compressed = data.chars.map{_1.ord-34}
puts compressed.map.with_index{|a,i|[i%2]*a}.flatten.each_slice(120).map(&:join)
code = <<RUBY
data=[*"4&V'U&,'?-/'7&>'*'.?.'&&1'/'.'%/+6)%)40'0'.74(($%''.6&2',(''('2')'$&+'&1(&3')+%'*'0',%/&()/&4&('%+,'/&:':&4''&')-'.'9';&4'&''(.'/&8''$7'%&/'&&&*,'0(6&(&6&%&/'&,-)2*2&)'6*8((.7,,'*3*'D*?(+'.0A".chars.map{_1.ord-35}.map.with_index{|a,i|[i%2]*a}.flatten.each_slice(120)];
(0..).each{|i|
ry=rand(9)-4;
rx=rand(9)-4;
s=[12288,127874].map{_1.chr'utf-8'};
puts "%c[1;1H"%27 + 28.times.map{|y|
30.times.map{|x|
ix=(x+rx);
iy=(y+ry)/2;
s[0<=ix&&ix<30&&0<=iy&&iy<14?data[iy][ix+i/10%4*30]:0]
}*''
}*$/;
sleep(0.1)
}
RUBY
code.delete! " \n"
code="eval %w@#{code}@*''"
puts code.size
img = ChunkyPNG::Image.from_file 'template.png'
imgdata = img.height.times.map{|y|img.width.times.map{|x|(img[x,y]>>8)&0xff<0x80}}
puts imgdata.flatten.count(&:itself)
chars=code.chars
puts imgdata.map{|l|l.map{|a|a ? chars.shift : ' '}.join}
eval %w@
da ta=[ *"4&V'U&,' ?-/' 7&>
'*'. ?.'& &1'/'.'%/+6)%)40'0'.74(($%'' .6&2 ',( ''(' 2')'
$&+' &1(&3')+%'*' 0',%/&()/&4&('%+,'/ &: ':&4''&')-'.'9';& 4'&' '(.'
/&8''$7'%&/'&&&*,'0( 6&(&6 & %&/' &,-)2*2&)'6 *8( (.7,
,'*3* 'D*? (+'. 0A". char s.m ap{_ 1.ord-35}.map. wit h_in
dex{|a,i |[i% 2]*a }.fl at ten .each_ sli ce(
120) ];(0..). each {|i |ry= ran d(9)
-4; rx=ran d(9) -4;s =[12 288 ,127
874] .map{ _1.c hr' utf- 8 '};p uts "%c[
1;1 H"%27+2 8.ti mes.m ap{ |y| 30. tim es.m
ap{|x|ix= (x+rx) ;iy=(y+ ry) /2;s [0<=ix&
&ix<3 0&&0<=iy&&i y<14?data [iy] [ix+i/10%4*30]:0 ]}*'
'}*$/;s leep( 0.1) }@*''#medetai
eval %w@
da ta=[ *"4&V'U&,' ?-/' 7&>
'*'. ?.'& &1'/'.'%/+6)%)40'0'.74(($%'' .6&2 ',( ''(' 2')'
$&+' &1(&3')+%'*' 0',%/&()/&4&('%+,'/ &: ':&4''&')-'.'9';& 4'&' '(.'
/&8''$7'%&/'&&&*,'0( 6&(&6 & %&/' &,-)2*2&)'6 *8( (.7,
,'*3* 'D*? (+'. 0A". char s.m ap{_ 1.ord-35}.map. wit h_in
dex{|a,i |[i% 2]*a }.fl at ten .each_ sli ce(
120) ];(0..). each {|i |ry= ran d(9)
-4; rx=ran d(9) -4;s =[12 288 ,128
044] .map{ _1.c hr' utf- 8 '};p uts "%c[
1;1 H"%27+2 8.ti mes.m ap{ |y| 30. tim es.m
ap{|x|ix= (x+rx) ;iy=(y+ ry) /2;s [0<=ix&
&ix<3 0&&0<=iy&&i y<14?data [iy] [ix+i/10%4*30]:0 ]}*'
'}*$/;s leep( 0.1) }@*''#medetai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment