ASCII ARTで円を塗りつぶすAppleScriptです。(デモ用の)文字で表現するゲームを作る場合に、基礎ルーチンを整備しておく必要性を感じて、書いておきました。
AppleScript名:ASCII ARTで円を塗る.scpt |
— – Created by: Takaaki Naganoya – Created on: 2025/07/04 — – Copyright © 2025 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions — 円の半径 (この数値を変更すると円の大きさが変わります) set radiusNum to 12 — キャンバスのサイズ set canvasWidth to 80 set canvasHeight to 40 — 円の中心座標 set centerX to canvasWidth / 2 set centerY to canvasHeight / 2 — 全角文字のアスペクト比補正係数 set aspectRatio to 0.7 set aaRes to aaFillCircle(radiusNum, canvasWidth, canvasHeight, centerX, centerY, aspectRatio) of me on aaFillCircle(radiusNum, canvasWidth, canvasHeight, centerX, centerY, aspectRatio) script spd property outputText : "" end script — 描画結果を格納する変数 set (outputText of spd) to "" — 描画処理 (1行ずつ文字を生成) repeat with y from 1 to canvasHeight set currentLine to "" repeat with x from 1 to canvasWidth — 円の方程式を使い、中心からの距離を計算 set distSquared to ((x – centerX) * aspectRatio) ^ 2 + (y – centerY) ^ 2 — 現在の座標が円の内側または円周上にあるか判定 if distSquared ≤ radiusNum ^ 2 then set currentLine to currentLine & "■" else set currentLine to currentLine & " " end if end repeat — 1行分の文字列と改行を出力に追加 set (outputText of spd) to (outputText of spd) & currentLine & " " end repeat return contents of (outputText of spd) end aaFillCircle |
More from my site
(Visited 1 times, 1 visits today)