Created
March 19, 2018 19:40
-
-
Save genkuroki/e0803500260c9a4edf68651c4f8e36df to your computer and use it in GitHub Desktop.
Sarcone's dynamic Muller-Lyer illusion no output
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
{ | |
"cells": [ | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "# Sarcone's dynamic Muller-Lyer illusion\n\nGen Kuroki\n\n2018-03-10\n\nSee\n\n* https://www.giannisarcone.com/Muller_lyer_illusion.html\n\n* https://twitter.com/seymiotics/status/971657723204063232" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "using Plots\ngr(legend=false)\nENV[\"PLOTS_TEST\"] = \"true\"\n\n# 線分を描く函数\nsegment(A, B; color=\"black\", kwargs...) = plot([A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)\nsegment!(A, B; color=\"black\", kwargs...) = plot!([A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)\nsegment!(p, A, B; color=\"black\", kwargs...) = plot!(p, [A[1], B[1]], [A[2], B[2]]; color=color, kwargs...)\n\n# 円周を描く函数\nfunction circle(O, r; a=0, b=2π, color=\"black\", kwargs...)\n t = linspace(a, b, 1001)\n x(t) = O[1] + r*cos(t)\n y(t) = O[1] + r*sin(t)\n plot(x.(t), y.(t); color=color, kwargs...)\nend\nfunction circle!(O, r; a=0, b=2π, color=\"black\", kwargs...)\n t = linspace(a, b, 1001)\n x(t) = O[1] + r*cos(t)\n y(t) = O[2] + r*sin(t)\n plot!(x.(t), y.(t); color=color, kwargs...)\nend\nfunction circle!(p, O, r; a=0, b=2π, color=\"black\", kwargs...)\n t = linspace(a, b, 1001)\n x(t) = O[1] + r*cos(t)\n y(t) = O[1] + r*sin(t)\n plot!(p, x.(t), y.(t); color=color, kwargs...)\nend\n\n# 表示用函数\nshowimg(mime, fn) = open(fn) do f\n base64 = base64encode(f)\n display(\"text/html\", \"\"\"<img src=\"data:$mime;base64,$base64\">\"\"\")\nend", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "A = [1.5, 0]\nB = [3.5, 0]\nC = [5.5, 0]\n\nN = 10\n\nθ₀ = 2π/(2N)\nR = [\n cos(θ₀) -sin(θ₀)\n sin(θ₀) cos(θ₀)\n]\n\nV(θ) = [cos(θ), sin(θ)]\nr = 1.55*2π/(2N)\n\n@time anim = @animate for a in [0.6:0.025:1.4; 1.375:-0.025:0.625]\n θ = a*2π/4\n p = plot(xlim=(-6.5, 6.5), ylim=(-6.5, 6.5))\n plot!(grid=false, legend=false, xaxis=false, yaxis=false)\n for k in 1:10\n RR = R^(2k-1)\n segment!(RR*A, RR*B, lw=2, color=:black)\n segment!(RR*B, RR*C, lw=2, color=:blue)\n segment!(RR*A, RR*(A+r*V(θ)), lw=2, color=:black)\n segment!(RR*A, RR*(A+r*V(-θ)), lw=2, color=:black)\n segment!(RR*B, RR*(B+r*V(π-θ)), lw=2, color=:black)\n segment!(RR*B, RR*(B+r*V(π+θ)), lw=2, color=:black)\n segment!(RR*C, RR*(C+r*V(θ)), lw=2, color=:black)\n segment!(RR*C, RR*(C+r*V(-θ)), lw=2, color=:black)\n end\n plot(p, size=(500, 500))\nend\n\ngifname = \"dynamic Muller-Lyer.gif\"\n@time gif(anim, gifname, fps = 15)\nsleep(0.1)\nshowimg(\"image/gif\", gifname)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "lw = 1.0 # 太さ\n\nA = [1.5, 0]\nB = [3.5, 0]\nC = [5.5, 0]\n\nN = 10\n\nθ₀ = 2π/(2N)\nR = [\n cos(θ₀) -sin(θ₀)\n sin(θ₀) cos(θ₀)\n]\n\nV(θ) = [cos(θ), sin(θ)]\nr = 1.55*2π/(2N)\n\n@time anim = @animate for a in [0.6:0.025:1.4; 1.375:-0.025:0.625]\n θ = a*2π/4\n p = plot(xlim=(-6.5, 6.5), ylim=(-6.5, 6.5))\n plot!(grid=false, legend=false, xaxis=false, yaxis=false)\n for k in 1:10\n RR = R^(2k-1)\n segment!(RR*A, RR*B, lw=lw, color=:black)\n segment!(RR*B, RR*C, lw=lw, color=:blue)\n segment!(RR*A, RR*(A+r*V(θ)), lw=lw, color=:black)\n segment!(RR*A, RR*(A+r*V(-θ)), lw=lw, color=:black)\n segment!(RR*B, RR*(B+r*V(π-θ)), lw=lw, color=:black)\n segment!(RR*B, RR*(B+r*V(π+θ)), lw=lw, color=:black)\n segment!(RR*C, RR*(C+r*V(θ)), lw=lw, color=:black)\n segment!(RR*C, RR*(C+r*V(-θ)), lw=lw, color=:black)\n end\n plot(p, size=(500, 500))\nend\n\ngifname = \"dynamic Muller-Lyer $lw.gif\"\n@time gif(anim, gifname, fps = 15)\nsleep(0.1)\nshowimg(\"image/gif\", gifname)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "julia-0.6", | |
"display_name": "Julia 0.6.2", | |
"language": "julia" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"toc_window_display": false, | |
"toc_section_display": true, | |
"sideBar": true, | |
"title_cell": "Table of Contents", | |
"number_sections": true, | |
"title_sidebar": "Contents", | |
"skip_h1_title": false, | |
"toc_position": {}, | |
"toc_cell": false | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/5058ebf89ba603361ac531558916cf86" | |
}, | |
"language_info": { | |
"mimetype": "application/julia", | |
"file_extension": ".jl", | |
"version": "0.6.2", | |
"name": "julia" | |
}, | |
"gist": { | |
"id": "5058ebf89ba603361ac531558916cf86", | |
"data": { | |
"description": "Sarcone's dynamic Muller-Lyer illusion no output", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment