Skip to content

Instantly share code, notes, and snippets.

@tompng
Last active October 6, 2024 01:03
Show Gist options
  • Save tompng/989e46a2c36037eaf2b9 to your computer and use it in GitHub Desktop.
Save tompng/989e46a2c36037eaf2b9 to your computer and use it in GitHub Desktop.
ブロック崩しQuine 左右キーかadキーで移動 spaceで一時停止 ファイルに保存するとその状態から再開できるよ
s=%w(ABCDEFGHIJKMNOQRSUWXYZ0123456789 "`^' acegmnopqrsuwxyz)########################################
b='';d=->c{(w=s.find{|a|a[c]})&&(b+=(w.size+w.index(c)).to_s(2)[1..-1])};%(#########################
B^"`^^```^""NB^"`^^```^""NBS4K2DANGSGDJXANGWGDJDBYUS4I2OENGWGDJD""'`"^"'""'J"`^"`^^`"`^DJ"`^"`^^`"`^
D mqwgmqwa anawoqom NOGGS24NNUZ6YX1BJAWC2IUKE21CCKJFFYZWQM wsereues Z pnaxmxex aomoeooo
C 3MDN7SQJ 2BCEA37Q IBEG24XQOOX082HI6X0QZ51B7HW8WUIE7JYQZ4 ME7JSE6W M RO7GG835 N77U0Y5W
F BDZ6UK1K OMZGQU5K O5WSFIME7JYGE34HOJ1Q525RO7SQ54HD2RGKFI UJE6XYJ4 D Q6FDEMXX KNM0GWW9
M 6YH4448A 2YH4Z24R Y3UY9MDM27Y0G3IRYXUY9JDM27Y0G3IRZBZ60U 8O6YH4J4 8 OYDDYZS4 A27FNGSG
D `"""'"` xa "'"'"'" 1JIRYUZ65M7E7QWS13IRYZSE1SCMI9G8KCDM3Xg ``""``" 9 ``^^'`` en `^`"^^`
7F NQSGcsooosasp444WQ3FHY7U4A2OH443IRY3Z6DU4C7FZ0Y5HHI3U0 S21 RZOY G
B xuwpxew "8H3IN27BQW45KOXXY04DA71U8W4RD6YA8GWRM2FE0D5KA27FNW^ psaycsa Y roryxma '" pmswrmz
I HCS5IRDJ HUY0KDC6FXY34MHNFEG5JGMZZEG5IGMYZA84WDOZDF4KWRJJQW S13IM6YG G 841HNMZ6 9JXHJXY0
M 4XFIFANQ S0OI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W9O3DAWHKXOZ
Y0E525M6UF8KXWQIYBERU4GNOZQ32MFBRWS9KMM27Y0G3ICI9B6HUCDZJ04JUJEIYB0855A71WS325KOJSQASGHIDCNKARM2DCSU
34N7FW8Y34C7FZ0Y5HHJOYGB5RI67AQ82HM67FQQ4MI67FGS5DBNBBG82CD7UU8KARMJRENAWMGNBGG1W8QJB1EH29NORF66SUQI
YA84W8I2BE0N2CNORF66SXQIRU8248M33GC'WF"H4^MM'EE'7J`SE^MG`SE'DM'F66SCQIYFGD4MC6BE0N2CNORF6IS7B7XCEKCX
HNJWS9K1OJRA8KSGHIDFN5UIRZMZ65IGD `H4Z24I3QXY355E6M04UW7FA7ZGD21AJFX
GAX7JNYH4C5OMYYH4B5ORZUZ4KC9FAAAa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
).chars.each &d;D,C=[b].pack('b*').split"\x0";eval C################################################
#Stage 1
C=File.read(__FILE__).split('#CODE#')[2]
D='8,599,271,324,12,29,1,1,1,1,1,0,1,1,0,1,1,0,1,0,0,1'
D=''
C=C.gsub(/^ +/,'')
C=C.gsub(/ +/,' ')
vars=%w(ball ballhoge bar barw bits blocks bpos circle export fsize lines message paused render reset resetball restore rng show stage wait).sort_by(&:size).reverse.each_with_index{|a,i|
C=C.gsub(a, "_#{((:a..:z).to_a+(:A..:Z).to_a+(0..9).to_a)[i]}")
}
#CODE#
cab,ca,cb=%w(ABCDEFGHIJKMNOQRSUWXYZ0123456789 "`^' acegmnopqrsuwxyz)
require 'io/console'
q=Queue.new
Thread.new{loop{q<<STDIN.raw(&:getc)}}
stage=0
bar,blocks,message=nil
ball,ballhoge=nil
resetball=->{
ball=[0.5,0.5,0,0.03]
ballhoge=[ball]
}
reset = ->{
a=3+(stage%5)/5.0,3+(stage%7)/7.0,stage
blocks=8.times.flat_map{|ix|
3.times.map{|iy|
x,y=(ix+0.5)/8,(iy+0.5)/8
[x,y,Math.sin(a[2]+a[0]*x+a[1]*y)]
}
}
count=blocks.size*(0.4+0.2*Math.cos(stage*stage))
blocks=blocks.sort_by(&:last).take(count)
bar=0.5
resetball.call
}
restore=->str{
stage,br,x,y,vx,vy,*bls=str.split(',').map(&:to_i)
reset[]
bar=br/1000.0
blocks.zip(bls){|a,b|a[2]=b==1}
ballhoge=[ball=[x,y,vx,vy].map{|a|a/1000.0}]
}
export=->{
[stage,(bar*1000).to_i,ball.map{|a|(a*1000).to_i},*blocks.map{|a|a.last&&1||0}]*','
}
reset[]
restore[D] if D.size>0
size=100
fsize=size.to_f
map=nil
wait=10
render=->{
barw=0.3*[0.8**stage,0.2].max
map=size.times.map{size.times.map{nil}}
r=0.03
br=0.06
if wait > 0
wait-=1
else
message=nil
x,y,vx,vy=ball
x+=vx;y+=vy;
bpos=(x-bar*(1-barw-2*r))/(barw+4*r)
if y>1-4*r&&0<bpos&&bpos<1
vy=-vy.abs
y=[y,1-3*r].min
bx=2*bpos-1
vx+=0.02*(bx-0.2) if bx>0.2
vx+=0.02*(bx+0.2) if bx<-0.2
vx=[-0.1,vx,0.1].sort[1]
end
blocks.each{|b|
hx,hy,f=b
hx-=x;hy-=y
hr=Math.sqrt hx**2+hy**2
if f&&hr<r+br
b[2]=nil
hv=(vx*hx+vy*hy)/hr/hr
(vx-=2*hv*hx;vy-=2*hv*hy)if hv>0
end
}
vy=-0.005 if vy.abs<0.005
(x=r;vx=-vx) if x<r
(y=r;vy=-vy) if y<r
(x=1-r;vx=-vx) if x>1-r
if y>1-2*r
wait=10
message='Failed'
resetball[]
next
end
if !blocks.any?(&:last)
message='Clear'
wait=10
stage=(stage+1)%10
reset[]
next
end
ballhoge.unshift(ball=[x,y,vx,vy])
ballhoge=ballhoge[0,4]
end
circle=->x,y,r,e=2,f=1{
xi,yj=[x,y].map{|x|(x*size).round}
ri=(r*size).ceil;rng=-ri..ri
rng.map{|i|rng.map{|j|
if [xi+i,yj+j].all?{|k|0<=k&&k<size}
map[xi+i][yj+j]=f if ((xi+i)/fsize-x)**e+((yj+j)/fsize-y)**e<r**e
end
}}
}
blocks.select(&:last).each{|x,y|circle[x,y,br,6];circle[x,y,br*0.7,6,nil]}
20.times{|i|
circle[r+bar*(1-barw-2*r)+barw*i/20,1-2*r,r]
}
ballhoge.each{|x,y|circle[x,y,r]}
}
show=->msg{
lines=["s=%w(#{cab} #{ca} #{cb})"]
lines<<"b='';d=->c{(w=s.find{|a|a[c]})&&(b+=(w.size+w.index(c)).to_s(2)[1..-1])};%("
bits=(export[]+"\x0"+C+"\x0").unpack('b*')[0].chars.map &:to_i
(size/2).times{|y|
lines<<(0...size).map{|x|
cs=[cab,ca,cb,' '][(map[x][2*y]?2:0)+(map[x][2*y+1]?1:0)]
cs[bits.shift(Math.log2(cs.size)).join.to_i(2)]
}*''
}
lines<<%[).chars.each &d;D,C=[b].pack('b*').split"\\x0";eval C]
lines.map!{|a|a+='#'*(size-a.size)}
lines<<"\e[1m#Stage #{stage+1} #{msg} #{:error if !bits.empty?}\e[0m"
$><<lines.each_with_index.map{|l,y|"\e[#{y+1};1H\e[K#{l}"}*''
$>.flush
}
paused=nil
$><<"\e[2J"
loop{
sleep 0.02
x=0
q.size.times.map{q.pop}.uniq.each do |c|
x-=1 if c=='a'||c=='D'
x+=1 if c=='d'||c=='C'
paused=!paused if c==' '
exit if c=="\x3"
end
bar+=x*0.05;
bar=[0,bar,1].sort[1]
next if paused
render[]
show[message]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment