Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active March 7, 2019 22:54
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 JoshCheek/99acc9250785db2c34697e315b02ebbe to your computer and use it in GitHub Desktop.
Save JoshCheek/99acc9250785db2c34697e315b02ebbe to your computer and use it in GitHub Desktop.
Rainy Pond

You can view the final version here

# the first version (~575 chars)
ruby -e H,W=$LINES,$COLUMNS'/2
include Math
circles = []
add = -> { circles<<[rand(H),rand(W),0,rand(6)+1] }
add[]
S = H + W
def print_circle(y, x, r, c, o)
str=(4*S).times.map { |i|
ø = 2*PI*i/4/S
[y+r*sin(ø), x+r*cos(ø)].map(&:round)
}.reject { |cy, cx| cy < 0 || cx < 0 || cy >= H || cx >= W-2 }
.uniq.map { |y, x| "\e[#{y+1};#{2*x+1}H " }.join
o<<"\e[4#{c}m"+str
str.size > 0
end
while circles.any?
o = "\e[0m\e[H\e[2J\e[45m"
circles = circles.flat_map do |y, x, r, c|
next [] if !print_circle(y, x, r, c, o)
[[y,x,r+1,c]]
end
add[] if rand < 0.1
$><<o
sleep 0.05
end'
# ~448
ruby -e H,W=$LINES,$COLUMNS'/2
S=4*H+4*W
alias a rand
b=[]
add=->{b<<[a(H),a(W),0,a(6)+1]}
add[]
while b.any?
o="\e[0m\e[H\e[J"
b=b.flat_map do |y, x, r, c|
str=S.times.map { |i|
ø = 2*6.3*i/S
[y+r*Math.sin(ø), x+r*Math.cos(ø)].map(&:round)
}.reject { |cy, cx| cy < 0 || cx < 0 || cy > H || cx > W-1 }
.uniq.map { |y, x| "\e[#{y+1};#{2*x+1}H " }.join
o<<"\e[4#{c}m"+str
next[]if str.size <= 0
[[y,x,r+1,c]]
end
add[] if a<0.2
$><<o
sleep 0.05
end'
# ~402
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=4*H+4*W
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0,a(6)]}
A[]
while b.any?
o="\e[47m\e[H\e[J"
b=b.flat_map{|y,x,r,c|
s=S.times.map{|i|
ø=6.3*i/S
[y+r*C[ø+1.6], x+r*C[ø]].map &:round
}.reject {|y,x|y<0||x<0||y>H||x>W-1}
.uniq.map { |y, x| "\e[#{y+1};#{2*x+1}H " }.join
o<<"\e[4#{c}m"+s
next[]if s.size <= 0
[[y,x,r+1,c]]
}
a<0.2&&A[]
$><<o
sleep 0.05
end'
# ~377
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=4*H+4*W
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0,a(6)]}
A[]
while b.any?
o="\e[47m\e[H\e[J"
b=b.flat_map{|y,x,r,c|
s=S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]].map &:round}.reject{|y,x|y<0||x<0||y>H||x>W-1}.uniq.map{|y,x|"\e[#{y+1};#{2*x+1}H "}*""
o<<"\e[4#{c}m"+s
s==""?[]:[[y,x,r+1,c]]}
a<0.1&&A[]
$><<o
sleep 0.05
end'
# ~366
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=4*H+4*W
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0,a(7)]}
A[]
loop{o="\e[47m\e[H\e[J"
b=b.flat_map{|y,x,r,c|s=S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]].map &:round}.reject{|y,x|y<0||x<0||y>H||x>W-1}.uniq.map{|y,x|"\e[#{y+1};#{2*x+1}H "}*""
s==""?[]:o<<"\e[4#{c}m"+s&&[[y,x,r+1,c]]}
a<0.1&&A[]
$><<o
sleep 0.05}'
# ~322, removes clearing, causing output to be very different
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=999
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0,a(7)]}
A[]
loop{b=b.flat_map{|y,x,r,c|s=S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]].map &:round}.reject{|y,x|y<0||x<0||y>H||x>W-1}.map{|y,x|"\e[#{y+1};#{2*x+1}H "}*""
s==""?[]:$><<"\e[4#{c}m"+s&&[[y,x,r+1,c]]}
a<0.1&&A[]}'
# ~322 stops maintaining a circle's colour over time, causing it to print more like a rainbow
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=999
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0]}
A[]
loop{b=b.flat_map{|y,x,r|s=S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]].map &:round}.reject{|y,x|y<0||x<0||y>H||x>W-1}.map{|y,x|"\e[#{y+1};#{2*x+1}H "}*""
s==""?[]:$><<"\e[4#{a 7}m"+s&&[[y,x,r+1]]}
a<0.1&&A[]}'
# ~289, stops removing old circles from the array
# (means it will get slower over time and has a memory leak, but removes a lot of overhead)
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=999
C=->ø{Math.cos ø}
b=[]
A=->{b<<[a(H),a(W),0]}
loop{b.map!{|y,x,r|s=S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]]}.reject{|y,x|y<0||x<0||y>H||x>W}.map{|y,x|"\e[#{y.to_i+1};#{2*x.to_i+1}H "}*""
$><<"\e[4#{a 8}m"+s
[y,x,r+1]}
a<0.1&&A[]}'
# ~276
ruby -e H,W=$LINES,$COLUMNS'/2
alias a rand
S=999
C=->ø{Math.cos ø}
b=[]
loop{b.map!{|y,x,r|$><<"\e[4#{a 8}m"
S.times.map{|i|ø=6.3*i/S
[y+r*C[ø+1.6],x+r*C[ø]]}.reject{|y,x|y<0||x<0||y>H||x>W}.map{|y,x|$><<"\e[#{y.to_i+1};#{2*x.to_i+1}H "}
[y,x,r+1]}
a<0.1&&b<<[a(H),a(W),0]}'
# ~237 (only prints one circle at a time)
ruby -e H,W=$LINES,$COLUMNS'/2
C=->ø{Math.cos ø}
loop{y=rand H
x=rand W
(H+W).times{|r|$><<"\e[4#{r%8}m"
0.step(6.3, 0.01).map{|ø|[y+r*C[ø+1.6],x+r*C[ø]]}.reject{|y,x|y<0||x<0||y>H||x>W}.map{|y,x|$><<"\e[#{y.to_i+1};#{2*x.to_i+1}H "}}}'
# ~278 (moves loop out of the program, saves enough chars to deobfuscate)
yes|ruby -ne h,w=$LINES,$COLUMNS'/2
cy=rand h
cx=rand w
(h+w).times{|r|
print"\e[4#{rand 8}m"
0.step(6.28, 0.001)
.map{|ø|[cy+r*Math.sin(ø),cx+r*Math.cos(ø)]}
.map{|y,x|[y.round,x.round]}
.reject{|y,x|y<0||x<0||y>h-1||x>w-1}
.map{|y,x|print"\e[#{y+1};#{2*x+1}H "}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment