# Sarcone's dynamic Muller-Lyer illusion¶

Gen Kuroki

2018-03-10

See

In [1]:
using Plots
gr(legend=false)
ENV["PLOTS_TEST"] = "true"

# 線分を描く函数
segment(A, B; color="black", kwargs...) = plot([A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)
segment!(A, B; color="black", kwargs...) = plot!([A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)
segment!(p, A, B; color="black", kwargs...) = plot!(p, [A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)

# 円周を描く函数
function circle(O, r; a=0, b=2π, color="black", kwargs...)
t = linspace(a, b, 1001)
x(t) = O[1] + r*cos(t)
y(t) = O[1] + r*sin(t)
plot(x.(t), y.(t); color=color, kwargs...)
end
function circle!(O, r; a=0, b=2π, color="black", kwargs...)
t = linspace(a, b, 1001)
x(t) = O[1] + r*cos(t)
y(t) = O[2] + r*sin(t)
plot!(x.(t), y.(t); color=color, kwargs...)
end
function circle!(p, O, r; a=0, b=2π, color="black", kwargs...)
t = linspace(a, b, 1001)
x(t) = O[1] + r*cos(t)
y(t) = O[1] + r*sin(t)
plot!(p, x.(t), y.(t); color=color, kwargs...)
end

# 表示用函数
showimg(mime, fn) = open(fn) do f
base64 = base64encode(f)
display("text/html", """<img src="data:$mime;base64,$base64">""")
end

Out[1]:
showimg (generic function with 1 method)
In [3]:
A = [1.5, 0]
B = [3.5, 0]
C = [5.5, 0]

N = 10

θ₀ = 2π/(2N)
R = [
cos(θ₀) -sin(θ₀)
sin(θ₀)  cos(θ₀)
]

V(θ) = [cos(θ), sin(θ)]
r = 1.55*2π/(2N)

@time anim = @animate for a in [0.6:0.025:1.4; 1.375:-0.025:0.625]
θ = a*2π/4
p = plot(xlim=(-6.5, 6.5), ylim=(-6.5, 6.5))
plot!(grid=false, legend=false, xaxis=false, yaxis=false)
for k in 1:10
RR = R^(2k-1)
segment!(RR*A, RR*B, lw=2, color=:black)
segment!(RR*B, RR*C, lw=2, color=:blue)
segment!(RR*A, RR*(A+r*V(θ)),  lw=2, color=:black)
segment!(RR*A, RR*(A+r*V(-θ)), lw=2, color=:black)
segment!(RR*B, RR*(B+r*V(π-θ)), lw=2, color=:black)
segment!(RR*B, RR*(B+r*V(π+θ)), lw=2, color=:black)
segment!(RR*C, RR*(C+r*V(θ)),  lw=2, color=:black)
segment!(RR*C, RR*(C+r*V(-θ)), lw=2, color=:black)
end
plot(p, size=(500, 500))
end

gifname = "dynamic Muller-Lyer.gif"
@time gif(anim, gifname, fps = 15)
sleep(0.1)
showimg("image/gif", gifname)

  4.391085 seconds (25.55 M allocations: 891.715 MiB, 3.92% gc time)
0.721048 seconds (1.05 k allocations: 69.688 KiB)

INFO: Saved animation to C:\Users\genkuroki\OneDrive\Math6\dynamic Muller-Lyer.gif

In [5]:
lw = 1.0 # 太さ

A = [1.5, 0]
B = [3.5, 0]
C = [5.5, 0]

N = 10

θ₀ = 2π/(2N)
R = [
cos(θ₀) -sin(θ₀)
sin(θ₀)  cos(θ₀)
]

V(θ) = [cos(θ), sin(θ)]
r = 1.55*2π/(2N)

@time anim = @animate for a in [0.6:0.025:1.4; 1.375:-0.025:0.625]
θ = a*2π/4
p = plot(xlim=(-6.5, 6.5), ylim=(-6.5, 6.5))
plot!(grid=false, legend=false, xaxis=false, yaxis=false)
for k in 1:10
RR = R^(2k-1)
segment!(RR*A, RR*B,            lw=lw, color=:black)
segment!(RR*B, RR*C,            lw=lw, color=:blue)
segment!(RR*A, RR*(A+r*V(θ)),   lw=lw, color=:black)
segment!(RR*A, RR*(A+r*V(-θ)),  lw=lw, color=:black)
segment!(RR*B, RR*(B+r*V(π-θ)), lw=lw, color=:black)
segment!(RR*B, RR*(B+r*V(π+θ)), lw=lw, color=:black)
segment!(RR*C, RR*(C+r*V(θ)),   lw=lw, color=:black)
segment!(RR*C, RR*(C+r*V(-θ)),  lw=lw, color=:black)
end
plot(p, size=(500, 500))
end

gifname = "dynamic Muller-Lyer $lw.gif" @time gif(anim, gifname, fps = 15) sleep(0.1) showimg("image/gif", gifname)   4.428483 seconds (25.60 M allocations: 892.076 MiB, 3.92% gc time) 0.712961 seconds (1.03 k allocations: 68.266 KiB)  INFO: Saved animation to C:\Users\genkuroki\OneDrive\Math6\dynamic Muller-Lyer 1.0.gif  In [7]: lw = 1.0 # 太さ A = [1.5, 0] B = [3.5, 0] C = [5.5, 0] D = [7.5, 0] N = 10 θ₀ = 2π/(2N) R = [ cos(θ₀) -sin(θ₀) sin(θ₀) cos(θ₀) ] V(θ) = [cos(θ), sin(θ)] r = 1.55*2π/(2N) @time anim = @animate for a in [0.5:0.025:1.5; 1.475:-0.025:0.525] θ = a*2π/4 p = plot(xlim=(-8.5, 8.5), ylim=(-8.5, 8.5)) plot!(grid=false, legend=false, xaxis=false, yaxis=false) for k in 1:10 RR = R^(2k-1) segment!(RR*A, RR*B, lw=lw, color=:black) segment!(RR*B, RR*C, lw=lw, color=:blue) segment!(RR*C, RR*D, lw=lw, color=:red) segment!(RR*A, RR*(A+r*V(θ)), lw=lw, color=:black) segment!(RR*A, RR*(A+r*V(-θ)), lw=lw, color=:black) segment!(RR*B, RR*(B+1.5r*V(π-θ)), lw=lw, color=:black) segment!(RR*B, RR*(B+1.5r*V(π+θ)), lw=lw, color=:black) segment!(RR*C, RR*(C+2.0r*V(θ)), lw=lw, color=:black) segment!(RR*C, RR*(C+2.0r*V(-θ)), lw=lw, color=:black) segment!(RR*D, RR*(D+2.5r*V(π-θ)), lw=lw, color=:black) segment!(RR*D, RR*(D+2.5r*V(π+θ)), lw=lw, color=:black) end plot(p, size=(500, 500)) end gifname = "dynamic Muller-Lyer 2$lw.gif"
@time gif(anim, gifname, fps = 15)
sleep(0.1)
showimg("image/gif", gifname)

  6.446699 seconds (36.61 M allocations: 1.312 GiB, 3.91% gc time)
0.873159 seconds (1.03 k allocations: 68.656 KiB)

INFO: Saved animation to C:\Users\genkuroki\OneDrive\Math6\dynamic Muller-Lyer 2 1.0.gif