Last active
January 23, 2020 15:07
-
-
Save tompng/45d93b3386b5986a94b9c3c8beecba69 to your computer and use it in GitHub Desktop.
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
;eval((c=%{E=Math::E;P=Math::PI;m=96;n=48.0; | |
w=32.chr;c=(w*26+';eval((c=%{'+c+"}).split*'')") | |
.split$/;gr=->r,t{r<1&&(r>1-(t%u=P*2/3)**2/6||(r*E | |
**((t-u/ 2)%u-u/2).i-0. 6).abs | |
<0.4)?2:0};gt=->x,y{y-=0.2;i=n+x*168;j=24+y*84;next(x*(-y) | |
**0.5*16%1<0.5?1:2)if(y<-0.4&&y>-0.9-x**6&&y>-0.4/x**2);next( | |
x.abs*2.6%1>0.6||y>-0.35||x.abs<0.1?2:0)if(y>=-0.4&&y<-0.32-x**4 | |
/10);next( 2)if(0< =j&&j<n&&0<i&& (c[j][i] ||w)!=w);nex | |
t(1)if(2*x**4+y**4<0.01);x=(x.abs-0.5).abs;y<-0.4||y>0.55||x >0.2?0:x> | |
0.12||y>0.47||(y-0.2)%0.5<0.1?y>0.45&&x>0.12?2:1:2*x*x+y*y<0.0 1+y%0.05/ | |
5?1:0};e=27.chr;puts'<<A',e+'[2J';e+='[1;1H';0.upto(90){|tm|tm/ =10.0;cn | |
=(1..m). map{[0 ]*m};rn=->x, y,z,th{xx=n+m* | |
x/z;yy =n+m*y/z;rr=144/z;r1=2**2i;r2=E**th.i;tr=->x,y,z{x,y=((x+ y.i)*r1 | |
).re ct;x,z=((x+z.i)*r2).rect;[*((x+y.i)/r1).rect,z]};([0,xx-rr] .max. | |
ce il..[m-1,xx+rr].min).each{|ix|([0,yy-rr].max.ceil..[m-1,yy+rr ]. | |
min).each{| iy|vx,vy,vz=tr [ix/n-1,iy/ | |
n-1,-2];cx,cy,cz=tr[-x,-y,z];vv=vx*vx+vy*vy+vz*vz*3;vc=vx*cx+ | |
vy*cy+vz*cz*3;h=0.3;d=vc*vc-vv*(cx**2+cy**2+cz**2*3-1-h*h*3); | |
d<0&&next;n ext(cn[iy][ix] =1)if((cz+ | |
vz*t=(-vc-d**0.5)/vv).abs<h);x2=cx-vx*s=(h/vz).abs+cz/vz;y2=cy | |
-vy*s;x2**2+y2**2>1&&next;i=(24+36*y2).round;j=(n+72*x2).roun | |
d;tm>6.3?cn[iy][ix]=tm<8.1?gt[x2*1.1,-y2*1.1]:(0<=i&&0<=j&&i | |
<n&&j< m&&(c[i ][j]||w )!=(w) | |
?i*m+j+m:0):cn[iy][ix]=gr[*(1. 2*(x2+y2.i)/E**tm.i).polar]}}} | |
;t=(3-2*t=[tm/4,1].min)*t*t;x=1 .62*t+2;y=-1.44*t-2;z=10-7*t-4. | |
1*[tm-6,0].max/9;th=(1+[tm-1,0]. max**2)**0.5-1;m.times{|i|m.ti | |
mes{|j|(((i/ n-1-2*y/z) **2+(j/n-1 -2*x/z)**2) | |
**0.5-10/z).abs<(1-t)/5/z&&cn[ i][j]=1}};8.times{|i|rn[*(x+y.i | |
+5*E**(P*i/4-(tm-(1+(tm-4)**2) **0.5-4)/4).i).rect,z,th/(65**0 | |
.5-1)*4*P]};tm<=7&&(0...[tm*4- 16,0,40].sort[1]*(tm<6?1:(7-tm) | |
/2)).each{ ix=rand(m) ;iy=rand(m );v=ix+42. | |
5-15*tm+(iy+42.5-15*tm).i;vx,v y=(v/v.abs).rect;(iy,vx,vy=0,0, | |
1)if(tm>6);f=1+rand(2);m.times {4.times{|j|i=ix+j/2;j=iy+j%2;0 | |
<=j&&j<m&&0<=i&&i<m&&cn[j][i] =f};ix+=vx+rand(3)-1;iy+=vy+ra | |
nd(3)-1}}; tn=->i ,j{a= 1-j/52;b=j | |
>40?0:1;j= n-j/2.0;j/ | |
2-a*16<i&& i<j-b*16}; | |
tm>6&&tm<6 .5&&m.time | |
s{|i|m.tim es{|j|tn[j | |
-40,i]&&cn [i][j]=2;t | |
m<6.2&&cn[ i][j]=2-cn | |
[i][j]}};p uts((tm<9? | |
e:[e,?A,?% ]*$/+w+e)+ | |
(0..47).map{ |i|m.time s.map{|j|l | |
,j=[cn[2*i+1 ][j],cn[2*i][j]];k=[l,j].max | |
;(w+%['".:Y ,L#])[3*l+j]||c[k/m-1][ | |
k%m]}*'' }*$/);sleep(0.05)} | |
}).split*'') |
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
def prepare | |
code = File.read(__FILE__).split(/\n#AAA\n/)[1].split.join | |
shape = File.read('template.txt').split($/).map{|a|(a+' '*96)[0,96]}.join($/) | |
count = shape.count '#' | |
prefix = ';eval((c=%{' | |
suffix = "}).split*'')" | |
missing = [(count - prefix.size - suffix.size - code.size), 0].max | |
chars = (prefix + code + ';' * missing + suffix).chars | |
output = shape.gsub('#') { chars.shift }+chars.join + $/ | |
lines = output.lines | |
lines[0] = lines[0].split(prefix).last | |
lines[-1] = lines[-1].split(suffix).first | |
c = lines.join | |
[output, c] | |
end | |
output, c = prepare | |
puts output | |
sleep 1 | |
File.write 'gorogoro.rb', output | |
#AAA | |
E=Math::E;P=Math::PI;m=96;n=48.0; | |
w=32.chr; | |
c=(w*26+';eval((c=%{'+c+"}).split*'')").split$/; | |
gr=->r,t{r<1&&(r>1-(t%u=P*2/3)**2/6||(r*E**((t-u/2)%u-u/2).i-0.6).abs<0.4)?2:0}; | |
gt=->x,y{ | |
y-=0.2; | |
i=n+x*168; | |
j=24+y*84; | |
next(x*(-y)**0.5*16%1<0.5?1:2)if(y<-0.4&&y>-0.9-x**6&&y>-0.4/x**2); | |
next(x.abs*2.6%1>0.6||y>-0.35||x.abs<0.1?2:0)if(y>=-0.4&&y<-0.32-x**4/10); | |
next(2)if(0<=j&&j<n&&0<i&&(c[j][i]||w)!=w); | |
next(1)if(2*x**4+y**4<0.01); | |
x=(x.abs-0.5).abs; | |
y<-0.4||y>0.55||x>0.2?0: | |
x>0.12||y>0.47||(y-0.2)%0.5<0.1 ? y>0.45&&x>0.12?2:1 : | |
2*x*x+y*y<0.01+y%0.05/5?1:0 | |
}; | |
e=27.chr; | |
puts'<<A',e+'[2J'; | |
e+='[1;1H'; | |
0.upto(90){|tm| | |
tm /=10.0; | |
cn=(1..m).map{[0]*m}; | |
rn=->x,y,z,th{ | |
xx=n+m*x/z; | |
yy=n+m*y/z; | |
rr=144/z; | |
r1=2**2i; | |
r2=E**th.i; | |
tr=->x,y,z{ | |
x,y=((x+y.i)*r1).rect; | |
x,z=((x+z.i)*r2).rect; | |
[*((x+y.i)/r1).rect,z] | |
}; | |
([0,xx-rr].max.ceil..[m-1,xx+rr].min).each{|ix| | |
([0,yy-rr].max.ceil..[m-1,yy+rr].min).each{|iy| | |
vx,vy,vz=tr[ix/n - 1,iy/n - 1,-2]; | |
cx,cy,cz=tr[-x,-y,z]; | |
vv = vx*vx+vy*vy+vz*vz*3; | |
vc = vx*cx+vy*cy+vz*cz*3; | |
h=0.3; | |
d=vc*vc-vv*(cx**2+cy**2+cz**2*3-1-h*h*3); | |
d<0&&next; | |
next(cn[iy][ix]=1)if((cz+vz*t=(-vc-d**0.5)/vv).abs<h); | |
x2=cx-vx*s=(h/vz).abs+cz/vz; | |
y2=cy-vy*s; | |
x2**2+y2**2>1&&next; | |
i=(24+36*y2).round; | |
j=(n+72*x2).round; | |
tm>6.3 ? | |
cn[iy][ix]=tm<8.1?gt[x2*1.1,-y2*1.1]:(0<=i&&0<=j&&i<n&&j<m&&(c[i][j]||w)!=(w)?i*m+j+m:0) : | |
cn[iy][ix]=gr[*(1.2*(x2+y2.i)/E**tm.i).polar] | |
} | |
} | |
}; | |
t=(3-2*t=[tm/4,1].min)*t*t; | |
x=1.62*t+2; | |
y=-1.44*t-2; | |
z=10-7*t-4.1*[tm-6,0].max/9; | |
th=(1+[tm-1,0].max**2)**0.5-1; | |
m.times{|i|m.times{|j| | |
(((i/n-1-2*y/z)**2+(j/n-1-2*x/z)**2)**0.5-10/z).abs<(1-t)/5/z&&cn[i][j]=1 | |
}}; | |
8.times{|i| | |
rn[*(x+y.i+5*E**(P*i/4-(tm-(1+(tm-4)**2)**0.5-4)/4).i).rect,z,th/(65**0.5-1)*4*P] | |
}; | |
tm<=7&&(0...[tm*4-16,0,40].sort[1]*(tm<6?1:(7-tm)/2)).each{ | |
ix=rand(m); | |
iy=rand(m); | |
v=ix+42.5-15*tm+(iy+42.5-15*tm).i; | |
vx,vy=(v/v.abs).rect; | |
(iy,vx,vy=0,0,1)if(tm>6); | |
f=1+rand(2); | |
m.times{ | |
4.times{|j| | |
i=ix+j/2; | |
j=iy+j%2; | |
0<=j&&j<m&&0<=i&&i<m&&cn[j][i]=f | |
}; | |
ix+=vx+rand(3)-1; | |
iy+=vy+rand(3)-1 | |
} | |
}; | |
tn = ->i,j{ | |
a=1-j/52; | |
b=j>40?0:1; | |
j=n-j/2.0; | |
j/2-a*16<i&&i<j-b*16 | |
}; | |
tm>6&&tm<6.5&&m.times{|i| | |
m.times{|j| | |
tn[j-40,i]&&cn[i][j]=2; | |
tm < 6.2&&cn[i][j] = 2-cn[i][j] | |
} | |
}; | |
puts((tm<9?e:[e,?A,?%]*$/+w+e)+(0..47).map{|i| | |
m.times.map{|j| | |
l,j=[cn[2*i+1][j],cn[2*i][j]]; | |
k=[l,j].max; | |
(w+%['".:Y,L#])[3*l+j] || c[k/m-1][k%m] | |
}*'' | |
}*$/); | |
sleep(0.05) | |
} |
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
############################################ | |
################################################ | |
################################################## | |
######## ############## ###### | |
########################################################## | |
############################################################# | |
################################################################ | |
########## ####### ############## ######## ############ | |
############################################################ ######### | |
############################################################## ######### | |
############################################################### ######## | |
######## ###### ############ ############## | |
###### ######################################################### ####### | |
#### ########################################################### ##### | |
## ############################################################# ## | |
########### ############## ########### | |
############################################################# | |
############################################################# | |
########### ############## ########## | |
############################################################## | |
############################################################# | |
############################################################ | |
###### ####### ####### ###### | |
############################## ############################## | |
############################### ############################### | |
################################ ############################## | |
############ ########## ########## ########### | |
############################## ############################### | |
############################## ############################### | |
############################## ############################### | |
########## ########## ########## ########## | |
############################## ############################### | |
############################## ############################### | |
############################# ############################## | |
########## ###### ##### ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
########## ########## | |
############ ######### ########## | |
############ ############################ | |
########### ####################### | |
######## ################## | |
############ |
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
code = File.read 'gorogoro.rb' | |
frames = `ruby gorogoro.rb` | |
last_frame = frames.split("\e[1;1H").last | |
def assert_equal(acode, bcode) | |
diff_count = 0 | |
acode.lines.zip bcode.lines do |a, b| | |
unless a.rstrip == b.rstrip | |
diff_count += 1 | |
puts '-' + a.rstrip | |
puts '+' + b.rstrip | |
end | |
end | |
binding.irb unless diff_count.zero? | |
p :eq, acode.size, bcode.size, acode == bcode | |
end | |
assert_equal code, last_frame | |
File.write 'frames.rb', frames | |
frames2 = `ruby frames.rb` | |
assert_equal last_frame, frames2.split("\e[1;1H").last | |
puts :ok | |
puts code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment