アスキーアート(数字と英小文字だけ)でマンデルブロ集合を描くとなぜか黒しか使ってないのに色が見える! (Excel VBAで計算)
このTweetみた。
Mathematics, computer programming.
— Cliff Pickover (@pickover) August 22, 2021
Mandelbrot Set in ASCII art.
An entire universe computed in 15 lines of code.
(I've magnified a portion, in the hopes you can see the characters of which the image is composed.) Full image and code, here: https://t.co/Yoo6E83dBN pic.twitter.com/CAoqtq4z2D
おお、これは昔、ラインプリンタでマンデルブロ集合(そのときは”*”のみ)を描いたのの拡張だな、、、
ということで早速やってみた。Pythonでもなんでもいいが、Excelをたまたま立ち上げていたのでExcel VBAで描いてみよう。
ソースはこちら。
Option Explicit
Option Base 0
Private Sub CommandButton1_Click()
Dim ix As Integer, iy As Integer, count As Integer, i As Integer
Dim size As Integer, limit As Integer
Dim letters(100) As String
Dim cx As Double, cy As Double
Dim x As Double, y As Double, x1 As Double, y1 As Double
Dim s As String
Application.ScreenUpdating = False '画面描画を停止
Application.Cursor = xlWait 'ウエイトカーソル
Application.EnableEvents = False 'イベントを抑止
Application.DisplayAlerts = False '確認メッセージを抑止
Application.Calculation = xlCalculationManual '計算を手動に
size = 400
limit = 1000
letters(0) = " "
For i = 1 To 9
letters(i) = Chr(48 + i)
Next i
For i = 10 To 10 + 26 - 1
letters(i) = Chr(87 + i)
Next i
letters(36) = "*"
For iy = 0 To size
s = ""
For ix = 0 To 3 * size
count = 0
cx = -2 + CDbl(ix) * 3.5 / CDbl(3 * size)
cy = 1.5 - CDbl(iy) * 3 / CDbl(size)
x = 0#
y = 0#
Do While (x * x + y * y) < 4 And count < limit
x1 = x
y1 = y
x = x1 ^ 2 - y1 ^ 2 + cx
y = 2# * x1 * y1 + cy
count = count + 1
Loop
If count >= limit Then
s = s + letters(0)
Else
If count >= 36 Then
s = s + letters(36)
Else
s = s + letters(count)
End If
End If
Next ix
Worksheets("mandel").Cells(iy + 1, 1) = s
Next iy
Application.StatusBar = False 'ステータスバーを消す
Application.Calculation = xlCalculationAutomatic '計算を自動に
Application.DisplayAlerts = True '確認メッセージを開始
Application.EnableEvents = True 'イベントを開始
Application.Cursor = xlDefault '標準カーソル
Application.ScreenUpdating = True '画面描画を開始
End Sub
やってみると?
確かに文字しかないのに、、、
あれ!色が見える!私だけ?
不思議!心理的な効果なのか、ディスプレイの色のにじみ的なものなのか、、、知ってる方がいたら教えてください。
« やよい軒で木須肉と鶏チリの定食を食す。 | トップページ | すき家でアボカドユッケサーモン丼(ご飯大盛)を食す。案外合ってる。 »
「日記・コラム・つぶやき」カテゴリの記事
- 高周波・RFニュース 2025年11月17日 Microwave Journalの特集は5G/6G/IoT, Special Focusも5G/6G、IDTechExの低損失材料レポート、6GHz帯の世界政策とWi-Fi 8についてのウェビナー開催、iFixitがPixel BUds 2aを分解、OnePlus15分解動画など(2025.11.17)
- RF Weekly Digest (Google AI Studio BuildによるAIで高周波・RF情報の週刊まとめアプリ) 2025/11/9-2025/11/16(2025.11.16)
- Visual Studio 2026がリリースされたので早速新しいPCにインストール。全面的にGitHub Copilotを使うようになっている。とりあえずC#でMath.NET numericsを使って連立方程式を計算するコードを書いてもらったら一発で動く。他の例として固有値や非線形計算もコードを出してくれた。(2025.11.14)
- 高周波・RFニュース 2025年11月13日 QorvoがTWTA置き換えの広帯域SSPA発表、iFixitがiPad Pro M5分解、KYOCERA AVXが0.9Vで動く超小型クロック発表、Mini-Circuitsが様々なBALUNやトランス解説、軍用5G解説、imecの110GHz可能な300mm GeSiウェハー(2025.11.13)
- 高周波・RFニュース 2025年11月12日 Qualcommが語る技術の標準化、STMicroelectronicsが語るシリコンフォトニクス、HuaweiがイノベーションとIPフォーラム開催、6G SummitでFCCのコミッショナーが米国が6Gをリードすべしと語る(2025.11.12)
« やよい軒で木須肉と鶏チリの定食を食す。 | トップページ | すき家でアボカドユッケサーモン丼(ご飯大盛)を食す。案外合ってる。 »




コメント