Last active
May 20, 2024 08:41
-
-
Save tompng/af91853a48e69d639cda6224e7411561 to your computer and use it in GitHub Desktop.
wave_quine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t=( s=" wav e=- >c{ eva l(c.split( | |
$/) .map{ (_1 *2)[/ #.+ #/] }.j | |
oin .de let e(' #'+ 32. chr ))} ;class<<wa | |
ve;de f+(c) =call(c); end;w ave | |
"). tr" #$/ ",+ ''; eval(t)+%~ | |
s . s p l i t(Re g e x p . n e # s p =3 2. c h r ; q = | |
) . z i p ( [ 0,4,4 , 5 , 1 , 1, 3# w ( s p + ' + ') | |
3, 2 , 2 , 1 ,1, 1 , 4 , 1 , 4 ,1 , 3 , # , 3 , 4 , 4 , | |
* _ 1 }) . join # 3 , 3 , 4 , 4 , 4 ,4 ] . m a p { s p | |
' + s p* 5 #;heade r = ' t = ( ' + s p * 5 + ' s = " | |
' + s p * 4 + 35.c# +q+' " ) . ' + s p * 5 + ' t r " | |
* 4 + " ' ' ;"#hr+'$/' + s p * 5+ '" , + ' + s p | |
h r ; h e a # +sp*5+'eval( t ) +% '+1 2 6 . c | |
e r s = 1 0 00.times.map { |t |hea d e r # d | |
x { | l , y | a t # .lines.ma p . with_ i n d e | |
1 9 , 1 1] ; c t =l[30,#=l [ 0 ,19]; b t= l [ | |
; d t = l[4 1. . ] ;ai,bi,ci, di=4. # 11 ] | |
0 0 4 * t + _ 1 * 7 ; (2.#time s .map { t h =0. | |
4 . * 3 + 1 i* * ( 5 *th+y*0 . 1 )+1i * * ( 7* # | |
* ( 6 * t h - y *0 .3)).r#t h + y*0. 2 ) + 1 i * | |
s p * ( 3 + a i )+a t+sp * ( 1 # e al.r o u n d } ; | |
+ b i- a i )+b t + sp*(1 6 + c i-bi)+c t + # 6 | |
( 1 6 + d i - ci ) + d t } . j o i n };t=hea # s p * | |
n d _ i n d e x { _ 1 .i ncl u d e ?s}#ders. f i | |
s = c . l i n e s . # || 0;W = 1 20;H=40;li n e | |
m a p{_ 1 . s p # l a s t(H ) ; c h ars=lines . | |
lin#lit . j o i n . c har s } ; p ositions= | |
es.sele c t { l [ _ 1 #es . m a p{ |l|W.tim | |
,t{12.ti # ] & . ! =sp}}; n o ize=->x,y | |
(2+i%3) * x * 4 . 0 # mes. s um{|i|1i**( | |
W+(i*8%17- 8 . 0 ) *y/H - 0 .004*(8+#/ | |
1))}. re al / 3 } ; e = #i % 5 ) *t*(i%2*2- | |
';trap# 27. c h r ; $ > < <e + ' [H'+e+'[J | |
(:INT){ ex it } ; ( t . . ) . e a c h{|t|ou# | |
ime s. m ap { | y | w =W- y / ( H - # tput=H. t | |
x# 1) ;p o s = p o s iti o n s [y] . m a p!{|x| | |
p =p o # + 0 . 1 + 0 . 2*n oi z e [x % w , y ,t]}; | |
m e s { p o s. m a p! {| v| p # s[- 1 ] - w; 2.ti | |
l i n e = [ s p # = [ v, p+ 1] . m a x } ; p -=w}; | |
c s = c ha r s [ y ] ; c s. s i z e .t i m e#]*w ; | |
[ _ 1 ] . r o u n # s { l ine [ p o s i t ions[ y ] | |
} ; p u t s # d % w ]= cs[ _ 1 ] } ; line.jo i n | |
1 0 0 0 ] , ' ' # (e+"[ H " + ( [ h eaders [ t % | |
) . g s u b # , o utput]. j o i n ( $/)<< 12 6 | |
) } # ($ / , e +'[K'+$ / ) ) ; sleep( 0. 0 2 ~ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rubocop:disable all | |
def prepare | |
code = File.read(__FILE__) | |
w = code[/^W = (\d+)/][/\d+/].to_i | |
h = code[/^H = (\d+)/][/\d+/].to_i | |
wc = w/4 | |
embedded = code.split('#CODE_START').last.gsub(/#DEBUG:start\n(\n|[^#].*\n)*#DEBUG:end/, '').delete("\n ").chars | |
counts = h.times.map{ | |
embedded.size/h | |
} | |
(embedded.size-counts.sum).times { counts[_1] += 1 } | |
chars = counts.map.with_index{(['#'] + embedded.shift(_1)).rotate(31.pow(_2,333331)%w)} | |
positions = h.times.map{(_1 == h - 1 ? w - 1 : w).times.to_a.sample(wc).sort} | |
c = "\n" + h.times.map do |y| | |
line = [' '] * (y == h - 1 ? w - 1 : w) | |
positions[y].zip(chars[y]).each{ line[_1] = _2 } | |
line.join | |
end.join("\n") | |
header = <<~'TEMPLATE' | |
t=( s=" www www www www wwwwwwwwww | |
www wwwww www wwwww www www www | |
www www www www www www www www wwwwwwwwww | |
wwwww wwwww wwwwwwwww wwwww www | |
"). tr" #$/ ",+ ''; eval(t)+%~ | |
TEMPLATE | |
proc_chars = "wave=->c{eval(c.split($/).map{(_1*2)[/#.+#/]}.join.delete('#'+32.chr))};class<<wave;def+(c)=call(c);end;wave".delete(' ').chars | |
header.gsub!('w') { proc_chars.shift || ';' } | |
t=s=nil | |
eval header.gsub('eval', '')+'~' | |
[c, t, s] | |
end | |
c, t, s = prepare | |
#CODE_START | |
sp=32.chr; | |
q=s.split(Regexp.new(sp+'+')).zip([ | |
0,4,4,5,1, | |
1,3,3,4,4,3,2, | |
2,1,1,1,4,1,4,1,3,3, | |
3,4,4,4,4].map{sp*_1}).join; | |
header = 't=('+sp*5+'s="'+sp*5+q+'").'+sp*5+'tr"'+sp*4+35.chr+'$/'+sp*5+'",+'+sp*4+"'';"+sp*5+'eval(t)+%'+126.chr; | |
headers = 1000.times.map { |t| | |
header.lines.map.with_index{|l,y| | |
at=l[0,19]; | |
bt=l[19,11]; | |
ct=l[30,11]; | |
dt=l[41..]; | |
ai,bi,ci,di=4.times.map{th=0.004*t+_1*7; (2.4.*3+1i**(5*th+y*0.1)+1i**(7*th+y*0.2)+1i**(6*th-y*0.3)).real.round}; | |
sp*(3+ai)+at+sp*(16+bi-ai)+bt+sp*(16+ci-bi)+ct+sp*(16+di-ci)+dt | |
}.join | |
}; | |
t=headers.find_index{_1.include?s}||0; | |
#DEBUG:start | |
s_dups = {} | |
headers.each_with_index do |h, t| | |
s_part = h[/s=(.|\n)+"\)\./] | |
p [t, s_dups[s_part]] if s_dups[s_part] && s_dups[s_part].any?{(_1 - t).abs > 1} | |
(s_dups[s_part] ||= []) << t | |
end | |
p s_dups.size | |
sleep 1 | |
#DEBUG:end | |
W = 120; | |
H = 40; | |
lines = c.lines.last(H); | |
chars = lines.map{_1.split.join.chars}; | |
positions = lines.map{|l|W.times.select{l[_1]&.!=sp}}; | |
noize=->x,y,t{ | |
12.times.sum { |i| | |
1i**((2+i%3)*x*4.0/W + (i*8%17-8.0)*y/H-0.004*(8+i%5)*t*(i%2*2-1)) | |
}.real/3 | |
}; | |
e=27.chr; | |
$><<e+'[H'+e+'[J'; | |
trap(:INT){exit}; | |
(t..).each { |t| | |
output = H.times.map { |y| | |
w=W-y/(H-1); | |
pos = positions[y].map!{|x|x+0.1+0.2*noize[x%w,y,t]}; | |
p = pos[-1]-w; | |
2.times{ | |
pos.map!{|v|p=[v,p+1].max}; | |
p -= w | |
}; | |
line = [sp]*w; | |
cs=chars[y]; | |
cs.size.times { | |
line[positions[y][_1].round%w] = cs[_1] | |
}; | |
line.join | |
}; | |
puts(e+"[H"+([headers[t%1000],'',output].join($/)<<126).gsub($/,e+'[K'+$/)); | |
sleep(0.02) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment