マンデルブロ集合を文字で組み立てて、デスクトップフォルダにRTF形式で保存して、テキストエディットでオープンして表示するAppleScriptです。
Courier Newはどの環境にも入っているフォントだと思っていますが、ない場合には別の等幅フォントのPostScript名に変更してください。また、フォントサイズや描画色を変更してみるといいかもしれません。
ちなみに、実用性はまっっっっったくありません。昔は計算に数分かかったのに、いまだとインタプリタ型の言語で動かしても1秒以下なんだ、へーという納得ができる程度です。
AppleScript名:マンデルブロ集合を描画してRTFとして組み立ててテキストエディットでオープン.scpt |
— – Created by: Takaaki Naganoya – Created on: 2023/08/06 — – Copyright © 2023 Piyomaru Software, All Rights Reserved — use AppleScript use framework "Foundation" use framework "AppKit" use scripting additions property NSFont : a reference to current application’s NSFont property NSUUID : a reference to current application’s NSUUID property NSColor : a reference to current application’s NSColor property NSString : a reference to current application’s NSString property NSDictionary : a reference to current application’s NSDictionary property NSLiteralSearch : a reference to current application’s NSLiteralSearch property NSMutableArray : a reference to current application’s NSMutableArray property NSMutableDictionary : a reference to current application’s NSMutableDictionary property NSFontAttributeName : a reference to current application’s NSFontAttributeName property NSMutableAttributedString : a reference to current application’s NSMutableAttributedString property NSForegroundColorAttributeName : a reference to current application’s NSForegroundColorAttributeName property NSDocumentTypeDocumentAttribute : a reference to current application’s NSDocumentTypeDocumentAttribute set outStr to generateMandel() of me set anAssrStr to makeRTFfromParameters(outStr, "CourierNewPSMT", 12) of me –結果のRTFをデスクトップ上に書き出す。ファイル名はUUID.rtf set thePath to (POSIX path of (path to desktop)) & (do shell script "uuidgen") & ".rtf" set aRes to my saveStyledTextAsRTF(thePath, anAssrStr) set targAlias to (POSIX file (thePath as string)) as alias tell application "TextEdit" activate open targAlias end tell –スタイル付きテキストを指定パス(POSIX path)にRTFで書き出し on saveStyledTextAsRTF(targPath, aStyledString) set targPathNSString to NSString’s stringWithString:targPath set bstyledLength to aStyledString’s |string|()’s |length|() set bDict to NSDictionary’s dictionaryWithObject:"NSRTFTextDocumentType" forKey:(NSDocumentTypeDocumentAttribute) set bRTF to aStyledString’s RTFFromRange:(current application’s NSMakeRange(0, bstyledLength)) documentAttributes:bDict return (bRTF’s writeToFile:targPath atomically:true) as boolean end saveStyledTextAsRTF –書式つきテキストを組み立てる on makeRTFfromParameters(aStr as string, aFontName as string, aFontSize as real) set aVal1 to NSFont’s fontWithName:aFontName |size|:aFontSize set aKey1 to (current application’s NSFontAttributeName) set aVal2 to NSColor’s cyanColor() set aKey2 to (current application’s NSForegroundColorAttributeName) set aVal3 to 0.0 set akey3 to (current application’s NSKernAttributeName) set keyList to {aKey1, aKey2, akey3} set valList to {aVal1, aVal2, aVal3} set attrsDictionary to NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList set attrStr to NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary return attrStr end makeRTFfromParameters –マンデルブロ集合を文字で描画して返す on generateMandel() set outStr to "" repeat with y from -12 to 12 by 1 repeat with x from -39 to 39 by 1 set ca to x * 0.0458 set cb to y * 0.08333 set a to ca set b to cb repeat with i from 0 to 15 by 1 set t to (a * a) – (b * b) + ca set b to (2 * a * b) + cb set a to t if ((a * a) + (b * b)) > 4 then exit repeat end repeat if ((a * a) + (b * b)) ≤ 4 then set outStr to outStr & " " else if i > 9 then set i to i + 7 set outStr to outStr & string id (48 + i) end if end repeat set outStr to outStr & return end repeat return outStr end generateMandel |
More from my site
(Visited 11 times, 1 visits today)