引用此筆記本
引用此筆記本
Recamán 數列、半圓與詭異的聲音
作者:Shenghui Yang
本篇文章是使用大型語言模型(#LLM)工具所創建的 #繁體中文譯本
原文出自 Wolfram 社群精選推薦,2025 年 10 月 26 日:Recamán’s sequence, semi circles and spooky sound
作者:Shenghui Yang
本篇文章是使用大型語言模型(#LLM)工具所創建的 #繁體中文譯本
原文出自 Wolfram 社群精選推薦,2025 年 10 月 26 日:Recamán’s sequence, semi circles and spooky sound
Recamán 序列、半圓與詭異音效
Recamán 序列、半圓與詭異音效
In[]:=
(*MikkHeidema'sRecamanSeqfromOEISA005132*)RecamanSeq[i_Integer]:=Fold[With[{lst=Last@#,len=Length@#},Append[#,If[lst>len&&!MemberQ[#,lst-len],lst-len,lst+len]]]&,{0},Range@i];
定義一個根據相鄰項目的字典序,用半圓連接其函數:
In[]:=
semiCircularPath[{u_Integer,v_Integer}]:=Withmid=Midpoint[{{u,u},{v,v}}],r=
2
Abs[u-v]2,If[u>v,Circle[mid,r,{-3π/4,π/4}],Circle[mid,r,{π/4,5*π/4}]]用對應的半圓連接所有相鄰的配對:
In[]:=
paths=semiCircularPath/@Partition[RecamanSeq[800],2,1];
使用 AxisObject 在圖形的對角線上加一條座標軸。將所有內容繞回在 Manipulate 函數中:
In[]:=
Manipulate[Graphics[{AxisObject[Line[{{0,0},2*{n,n}}],{0,2*n}],StandardOrange,paths[[1;;n]]},PlotRange->{{-.15n,2n},{-.15n,2*n}},ImagePadding->8,ImageSize->600,Background->Black],{n,1,500,1},SaveDefinitions->True]
Out[]=
建立動畫並儲存為本機「.mov」檔案:
In[]:=
LaunchKernels[];
In[]:=
frames=ParallelTable[Image@Graphics[{AxisObject[Line[{{0,0},2*{n,n}}],{0,2*n}],StandardOrange,paths[[1;;n]]},PlotRange->{{-.15n,2n},{-.15n,2*n}},ImagePadding->8,ImageSize->400],{n,1,400}];
In[]:=
Export["rq.mov",frames]
Out[]=
rq.mov
點擊按鈕,播放這些數字帶來的詭異音效:
In[]:=
keys=Mod[RecamanSeq[1000],48];
In[]:=
SeedRandom["Recaman"];
In[]:=
so=Sound[{SoundNote[#,RandomChoice[{0.1,0.2,0.05,0.06,0.07}],SoundVolume->RandomReal[{.5,1}]]&/@keys}]
Out[]=
允許聲音的音符重疊:
In[]:=
SeedRandom["Recaman"];duration=RandomChoice[{0.1,0.2,0.05,0.06,0.07},1001];tInit=Accumulate[duration];Sound[MapThread[SoundNote[#,{#2,#2+#3}+RandomReal[{-0.1,0.05}],SoundVolume->RandomReal[{.3,1}]]&,{keys,tInit,duration}]]
Out[]=