Skip to content

Instantly share code, notes, and snippets.

@tompng

tompng/sakura.rb Secret

Last active March 27, 2021 08:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tompng/a43c9d87d8492db862068c46ea20cf41 to your computer and use it in GitHub Desktop.
Save tompng/a43c9d87d8492db862068c46ea20cf41 to your computer and use it in GitHub Desktop.
sakura quine
;;eval(c=%w@C=[c.split(/#[;]/)[0]]*4*(?#+?;);w=64;h=32;c=(1..h).
map{[1]*w};p=[];include(Math ) ;w.times{x=2.0*_1/w-1;w.time
s{|y|v=1.4*y=2.0*y/w-1; v*v<(1-x*x)**1.6*(1+x/4)-
1/(1+64*v*v)/(1+16* (1-x)**2)&&p.push([x,y,(s
in(3.7*x)+sin(4.1 *y)-sin(2.3*x+2.9*y+2))/
16])}};$><<'%; ';trap(:INT){ex
it};204.times {|i|t=i/5.0;c.
map{_1.fill( 0)};v=PI/10*u
=[t,10].min ;(xx,yx),(xy
,yy),(xz, yz)=[1,2,4].
map{g=-> x,y,t{((x+y
.i)*E**t .i).rect};x
,y=g[_1 [0],_1[1],s
in(v)-1 ];y,z=g[y,_
1[2],v* 4];z,x=g[z,x
,sin(v )];x,y=g[x,y
,sin(v) -(t-u)/7];[x
*s=0.96 -u*0.05,s*y]}
;y0=(t- u)/20+(sin(u*0
.51)-co s(u*0.31))*d=0.1
+u/20;x 0=d*(sin(u*0.41)-
cos(u*0. 37))-(t-u)/15;f=->
x,y{x=w* (x+1)/2;y=h*(y+1)/2;x
>=0&&y>=0 &&x<w&&y<h&&c[y][x]=1}
;p.map{f[ xx*_1+xy*_2+xz*_3+x0,yx*_1
+yy*_2+yz* _3+y0]};rc,rs=(E**(t/5i)*0.46)
.rect;t>10&& p.map{|x,y|f[x0+1.4+x*rc+y*rs,y0-0
.07+x*rs-y*rc] } ;r1=4+r0=24*t-230;0<r1&&r0<w&&h.times{|y|w.
times{|x|r=hypot(x-w*(x0+1)/2,2*(y-h*(y0+1)/2));r0<r&&r<r1&&c[y]
[x]=1}};j=-1;s=c.map{|l|l.map{(?.<<32)[_1]}*''}*$/;a=64.chr;s[0,
12]=';;eval(c=%w'+a;s[-5..]=a+"*'')"<<$/<<0;$><<"%c[#{?2[i]}J%c[
H"%[27,27]+s.gsub(?.){C[j+=1]};sleep(0.05)}#;C=[c.split(/#[@*'')
# rubocop:disable all
c = File.read(__FILE__).split(/\n# CODE\n/).last.split.join
# CODE
C=[c.split(/#[;]/)[0]]*4*(?#+?;);
w = 64;
h = 32;
c = (1..h).map{[1] * w};
p=[];
include(Math);
w.times{x=2.0*_1/w-1;w.times{|y|
v=1.4*y=2.0*y/w-1;
v*v<(1-x*x)**1.6*(1+x/4)-1/(1+64*v*v)/(1+16*(1-x)**2) &&
p.push([x,y,
(sin(3.7*x)+sin(4.1*y)-sin(2.3*x+2.9*y+2))/16
])
}};
$><<'%;';
trap(:INT){exit};
204.times{|i|
t=i/5.0;
c.map{_1.fill(0)};
v=PI/10*u=[t,10].min;
(xx,yx),(xy,yy),(xz,yz)=[1,2,4].map {
g=->x,y,t{((x+y.i)*E**t.i).rect};
x,y=g[_1[0],_1[1],sin(v)-1];
y,z=g[y,_1[2],v*4];
z,x=g[z,x,sin(v)];
x,y=g[x,y,sin(v)-(t-u)/7];
[x*s=0.96-u*0.05,s*y]
};
y0=(t-u)/20+(sin(u*0.51)-cos(u*0.31))*d=0.1+u/20;
x0=d*(sin(u*0.41)-cos(u*0.37))-(t-u)/15;
f=->x,y{
x=w*(x+1)/2;
y=h*(y+1)/2;
x>=0&&y>=0&&x<w&&y<h&&c[y][x]=1
};
p.map { f[xx*_1+xy*_2+xz*_3+x0,yx*_1+yy*_2+yz*_3+y0] };
rc,rs=(E**(t/5i)*0.46).rect;
t>10 && p.map {|x,y| f[x0+1.4+x*rc+y*rs,y0-0.07+x*rs-y*rc]};
r1=4+r0=24*t-230;
0 < r1 && r0 < w && h.times{|y|w.times{|x|
r=hypot(x-w*(x0+1)/2, 2*(y-h*(y0+1)/2));r0<r && r<r1 && c[y][x] = 1
}};
j=-1;
s=c.map{|l|l.map{(?.<<32)[_1]}*''}*$/;
a=64.chr;
s[0,12]=';;eval(c=%w'+a;
s[-5..]=a+"*'')"<<$/<<0;
$><<"%c[#{?2[i]}J%c[H"%[27,27]+s.gsub(?.){C[j+=1]};
sleep(0.05)
}
# rubocop:disable all
def sleep(n); end
frames = `ruby sakura_base.rb`.split(/(?:\e[^A-Z]*[A-Z]|\0)+/)
frames.shift if frames[0].size < 10
eval = method(:eval)
def eval(code); $eval_code = code; end
codes = frames.map do |frame|
$eval_code = nil
c=''
eval.call frame
[c.split(/#[;]/)[0],$eval_code.split('#;')[0]]
rescue => e
puts e
puts frame
end
if codes.uniq.size == 1
File.write 'sakura.rb', frames[0]
puts 'OK'
else
puts 'ERROR'
p codes.uniq.size
puts codes.uniq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment