Skip to content

Instantly share code, notes, and snippets.

@yamasushi
Last active May 25, 2019 11:12
Show Gist options
  • Select an option

  • Save yamasushi/e89afba00640e939e3d6d180945045e2 to your computer and use it in GitHub Desktop.

Select an option

Save yamasushi/e89afba00640e939e3d6d180945045e2 to your computer and use it in GitHub Desktop.
module DynamicalSystem
using ColorTypes
export make_seq , push_points!
struct Seq{P}
initial::P
fn::Function
end
Base.iterate(ds::Seq, pt=ds.initial ) = (pt, ds.fn(pt) )
function make_seq(initial::P , fn::Function ;
ndrop::Int64 = 0,
ntake::Int64 = 0) where{P}
Iterators.take(
Iterators.drop(Seq{P}(initial,fn ),ndrop ) , ntake)
end
function make_seq(init_x::T,init_y::T,fn::Function ;
ndrop::Int64 = 0,
ntake::Int64 = 0) where{T<:Number}
make_seq((init_x,init_y),
p->fn(p...),ndrop=ndrop,ntake=ntake)
end
function make_seq(init_x::T,init_y::T,init_z::T,fn::Function ;
ndrop::Int64 = 0,
ntake::Int64 = 0) where{T<:Number}
make_seq((init_x,init_y,init_z),
p->fn(p...),ndrop=ndrop,ntake=ntake)
end
# push points
function push_points!( pts::Array{P,1} ;
initial_seq::Base.Generator ,
fn::Function ,
ndrop::Int64 ,
ntake::Int64 ) where {P}
for initial in initial_seq
for pt in make_seq(initial,fn,ndrop=ndrop,ntake=ntake)
push!(pts,pt)
end
end
end
# push points with color
function push_points!( pts::Array{P,1} , rgbs::Array{RGB{U},1} ;
make_color::Function ,
initial_seq::Base.Generator ,
fn::Function ,
ndrop::Int64 ,
ntake::Int64 ) where {P,U}
for initial in initial_seq
rgb::RGB{U}=make_color(initial)
for pt in make_seq(initial,fn,ndrop=ndrop,ntake=ntake)
push!(pts,pt)
push!(rgbs,rgb)
end
end
end
end # module DynamicalSystem
# https://gist.github.com/yamasushi/e89afba00640e939e3d6d180945045e2
# https://qiita.com/yamasushi/items/aa401d4667e9b66c7dcb
using Colors
using FixedPointNumbers
using Plots
# my modules
import DynamicalSystem
import GumowskiMira
#
function calc_points(param::NamedTuple)
function make_hsv(initial::Tuple{T,T}) where{T}
hue= ( hypot(initial...) * 360 ) % 360
HSV(hue,1,1)
end
initial_seq=DynamicalSystem.make_initial_seq(
density=param.initial_density,
radius =param.initial_radius)
plot_x=Float16[]
plot_y=Float16[]
rgbs=RGB{N0f8}[]
if param.with_rgb
DynamicalSystem.push_points!(plot_x,plot_y,rgbs,
make_color =make_hsv ,
initial_seq =initial_seq ,
map =param.map ,
ndrop =param.ndrop ,
ntake =param.ntake )
param,plot_x,plot_y,rgbs
else
DynamicalSystem.push_points!(plot_x,plot_y,
initial_seq =initial_seq ,
map =param.map ,
ndrop =param.ndrop ,
ntake =param.ntake )
param,plot_x,plot_y,nothing
end
end
function plot_points(param::NamedTuple ,
plot_x::Array{T,1} ,
plot_y::Array{T,1} ,
rgbs::Union{Array{RGB{U},1},Nothing}
) where{ T<:AbstractFloat , U }
param.backend()
if !isnothing(rgbs)
scatter(plot_x,plot_y
,background_color=:black
,aspect_ratio=:equal
,size=param.size
,markerstrokewidth=0
,markeralpha=param.markeralpha
,markersize=param.markersize
,markercolor=rgbs)
else
scatter(plot_x,plot_y
,background_color=:black
,aspect_ratio=:equal
,size=param.size
,markerstrokewidth=0
,markeralpha=param.markeralpha
,markersize =param.markersize
,markercolor=:white)
end
end
gm_map_1=GumowskiMira.gmmap(GumowskiMira.f2g1,α=0.008 , σ=0.05, μ=-0.496) # 「神話の鳥 (mythic bird)」3枚羽の翼
gm_map_2= GumowskiMira.gmmap(GumowskiMira.f2g1,α=0.009 , σ=0.05, μ=-0.80) #「神話の鳥 (mythic bird)」5枚羽の翼
gm_map_3= GumowskiMira.gmmap(GumowskiMira.f2g2,α=0.0083, σ=0.1 , μ=-0.38 ) #
gm_map_4= GumowskiMira.gmmap(GumowskiMira.f2g2,α=0.01 , σ=0.1 , μ=0.8 ) #
gm_map_5= GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.39 ) #
gm_map_6= GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.365) #
gm_map_7= GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.34 ) #
gm_map=gm_map_2
param_0_0=(
backend = pyplot ,
map = gm_map ,
size = (700,700),
with_rgb = true ,markeralpha =1 , markersize =1 ,
initial_density= 5.0 ,initial_radius =3.0 ,
ndrop=0 , ntake=1 )
param_0_1=(
backend = unicodeplots ,
map = gm_map ,
size = (700,700),
with_rgb = false ,markeralpha =1 , markersize =1 ,
initial_density= 5.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=1 )
param_1=(
backend = pyplot ,
map = gm_map ,
size = (700,700),
with_rgb = false ,markeralpha =0.5 , markersize =1 ,
initial_density= 5.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=100 )
param_2=(
backend = pyplot ,
map = gm_map ,
size = (700,700),
with_rgb = false ,markeralpha =0.1 , markersize =1 ,
initial_density= 5.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=100 )
plot_points(calc_points( param_1 )...)
# https://gist.github.com/yamasushi/e89afba00640e939e3d6d180945045e2
# https://qiita.com/yamasushi/items/aa401d4667e9b66c7dcb
using Colors
using FixedPointNumbers
using Plots
# my modules
import DynamicalSystem
import GumowskiMira
#
function make_initial_seq(;
density::Float64,radius::Float64=1.0) ::Base.Generator
length =2*Int(round(density*radius))
range_x=range(-radius,radius,length=length)
range_y=range(-radius,radius,length=length)
((x,y) for x in range_x,y in range_y)
end
function calc_points(param::NamedTuple)
function make_hsv(initial::Tuple{T,T}) where{T}
hue= ( hypot(initial...) * 360 ) % 360
HSV(hue,1,1)
end
initial_seq=make_initial_seq(
density=param.initial_density,
radius =param.initial_radius)
pts =Tuple{Float16,Float16}[]
rgbs=RGB{N0f8}[]
if param.with_rgb
DynamicalSystem.push_points!(pts,rgbs,
make_color =make_hsv ,
initial_seq =initial_seq ,
fn =param.fn ,
ndrop =param.ndrop ,
ntake =param.ntake )
param,pts,rgbs
else
DynamicalSystem.push_points!(pts,
initial_seq =initial_seq ,
fn =param.fn ,
ndrop =param.ndrop ,
ntake =param.ntake )
param,pts,nothing
end
end
function plot_points(param::NamedTuple ,
pts::Array{Tuple{T,T},1} ,
rgbs::Union{Array{RGB{U},1},Nothing}
)::Plots.Plot where{ T<:AbstractFloat , U }
if !isnothing(rgbs)
scatter(pts , markercolor=rgbs ,
markeralpha=param.markeralpha ,
title =param.title)
else
scatter(pts ,
markeralpha=param.markeralpha ,
title =param.title)
end
end
param_f2g1_1=(
title="f2g1:α=0.008,σ=0.05,μ=-0.496" ,
fn=GumowskiMira.gmmap(GumowskiMira.f2g1,
α=0.008 , σ=0.05, μ=-0.496) ,
# 「神話の鳥 (mythic bird)」3枚羽の翼
with_rgb = false ,markeralpha =0.3 ,
initial_density= 10. ,initial_radius =1. ,
ndrop=1000 , ntake=50 )
param_f2g1_2=(
title="f2g1:α=0.009,σ=0.05,μ=-0.80" ,
fn=GumowskiMira.gmmap(GumowskiMira.f2g1 ,
α=0.009 , σ=0.05, μ=-0.80) ,
#「神話の鳥 (mythic bird)」5枚羽の翼
with_rgb = false ,markeralpha =0.3 ,
initial_density= 10. ,initial_radius =1. ,
ndrop=1000 , ntake=50 )
param_f2g2_1=(
title="f2g2:α=0.0083,σ=0.1,μ=-0.38" ,
fn=GumowskiMira.gmmap(GumowskiMira.f2g2,
α=0.0083, σ=0.1 , μ=-0.38 ) ,
with_rgb = false ,markeralpha =0.3 ,
initial_density= 10. ,initial_radius =1. ,
ndrop=1000 , ntake=50 )
param_f2g2_2=(
title="f2g2:α=0.01,σ=0.1,μ=0.8" ,
fn=GumowskiMira.gmmap(GumowskiMira.f2g2,
α=0.01 , σ=0.1 , μ=0.8 ) ,
with_rgb = false ,markeralpha =0.3 ,
initial_density= 10. ,initial_radius =1. ,
ndrop=1000 , ntake=50 )
param_f1g1_1=(
title="f1g1:μ=0.39" ,
fn=GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.39 ) ,
with_rgb = false ,markeralpha =0.1 ,
initial_density= 10.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=10 )
param_f1g1_2=(
title="f1g1:μ=0.365" ,
fn=GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.365) ,
with_rgb = false ,markeralpha =0.1 ,
initial_density= 10.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=10 )
param_f1g1_3=(
title="f1g1:μ=0.34" ,
fn=GumowskiMira.gmmap(GumowskiMira.f1g1,μ=0.34 ) ,
with_rgb = false ,markeralpha =0.1 ,
initial_density= 10.0 ,initial_radius =3.0 ,
ndrop=1000 , ntake=10 )
pyplot()
plot(
plot(
plot_points(calc_points( param_f2g1_1 )...) ,
plot_points(calc_points( param_f2g1_2 )...) ,
layout=(1,2)
),
plot(
plot_points(calc_points( param_f2g2_1 )...) ,
plot_points(calc_points( param_f2g2_2 )...) ,
layout=(1,2)
),
plot(
plot_points(calc_points( param_f1g1_1 )...) ,
plot_points(calc_points( param_f1g1_2 )...) ,
plot_points(calc_points( param_f1g1_3 )...) ,
layout=(1,3)
),
layout=(3,1),
aspect_ratio=:equal,
markercolor=:black ,
markerstrokewidth=0 ,
markersize =1 ,
size=(700,800)
)
module GumowskiMira
export gmmap,GMType
@enum GMType f1g1 f1g2 f2g1 f2g2
function g1(x::Float64 ; μ::Float64) ::Float64
μ*x + (2.0(1.0-μ)x^2 )/(1.0 + x^2)
end
function g2(x::Float64 ; μ::Float64) ::Float64
μ*x + (1.0-μ)x^2*exp((1.0 - x^2)/4.0)
end
function f1(g::Function,pt::Tuple{Float64,Float64};
μ::Float64) ::Tuple{Float64,Float64}
xx = pt[2] + g(pt[1],μ=μ)
yy = -pt[1] + g(xx ,μ=μ)
(xx,yy)
end
function f2(g::Function,pt::Tuple{Float64,Float64};
α::Float64,σ::Float64,μ::Float64)::Tuple{Float64,Float64}
xx = pt[2] + α*pt[2]*( 1.0 - σ*pt[2]^2 ) + g(pt[1],μ=μ)
yy = -pt[1] + g(xx,μ=μ)
(xx,yy)
end
function gmmap(gmtype::GMType;
α::Float64=0.,σ::Float64=0.,μ::Float64) ::Function
if (gmtype==f1g1) pt->f1(g1,pt,μ=μ)
elseif (gmtype==f1g2) pt->f1(g2,pt,μ=μ)
elseif (gmtype==f2g1) pt->f2(g1,pt,α=α,σ=σ,μ=μ)
elseif (gmtype==f2g2) pt->f2(g2,pt,α=α,σ=σ,μ=μ)
else
error("gmtypeが不正")
end
end
end # module GumowskiMira
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment