Mystical 公式ガイドに沿ってプログラムから魔法陣の画像を作成する手順

PostScript 言語で作成したプログラムを魔法陣の画像に変換する Mysticle公式 GitHub のイントロのページに書かれている用例を、実際に行って、プログラムから魔法陣の画像をファイル出力する手順を紹介します。
PostScript の実行には、 Ghostscript (Windows 版の gswin64c) の ps2pdf を使用します。

Mystical.ps で魔法陣画像の生成1

※ gs10.05.1 を使用します。
※ 2025 年 05 月 24 日に GitHub で公開されている mystical_ps, dmmlib リポジトリの複製を使用しています。

Mysticle 実行環境の構築

Mystical を実行するために、以下が必要です。

  • mystical_ps リポジトリの取得
  • dmmlib リポジトリの取得(シンボリックリンク対応)
  • GhostScript (Windows 版) の導入と Path 環境変数の追加

これらについては、以下の記事を参照してください。

Mysticle 公式のイントロの手順

前章で、Mystical を実行する環境構築をした後は、公式のイントロに従って簡単に魔法陣の画像を出力できます。

denismm/mystical_ps の ReadMe に記述されていたリンク先「mystical_ps/docs/intro.md at main · denismm/mystical_ps」のイントロの手順をもとに、実際に画像を作成します。

The function mystical takes a PostScript object (an xarray, array, or dict) and renders it centered on the origin, fitting in a unit circle. To see it on a letter-sized or A4 page, making the unit 4 inches wide and putting it in the middle of the page is a good start.

関数 mystical は、PostScript オブジェクト (xarray、配列、または dict) を受け取り、それを原点を中心にして単位円に収まるようにレンダリングします。レター サイズまたは A4 ページで表示するには、ユニットの幅を 4 インチにしてページの中央に配置するのが良いスタートです。
mystical_ps/docs/intro.md at main · denismm/mystical_ps と Google 翻訳

以下の first.ps をテキストファイルとして保存します。

%!PS

(mystical.ps) run

72 dup scale    % make the unit 1 inch
4.25 5.5 translate      % move to the center of an 8.5x11 page
4 dup scale     % make the unit 4 inches
{
    0 0 1 0 360 arc stroke
    0 -0.25 0.5 180 360 arc fill
    -0.5 1 0.5 {
        0.25 0.125 0 360 arc fill
    } for
} mystical

showpage

コマンドプロンプトで、gstoppdf の引数に first.ps を渡してコマンドを実行します。
Windows 版の GhostScript では、 gstoppdf のかわりに、 ps2pdf を使用します。

Render this with gstopdf first.ps or whatever renderer you are using. You should see something like this:

これを gstoppdf first.ps または使用しているレンダラでレンダリングします。次のようなものが表示されるはずです。
mystical_ps/docs/intro.md at main · denismm/mystical_ps と Google 翻訳

ps2pdf の確認

ps2pdf は GhostScript をインストールしたフォルダ内の lib フォルダの中に同梱されています。

GhostScript ps2pdf の場所

GhostScript の bin, lib の 2 個のフォルダのパスは、Path 環境変数に追加しておくと便利です。
Path 環境変数への追加の手順は以下の記事を参照してください。

-dNOSAFER オプションが必要

以下のコマンドを実行すると Error: /invalidfileaccess in –run– というエラーが発生します。

ps2pdf first.ps
G:\Dev\Mistical\mystical_ps>ps2pdf first.ps
Error: /invalidfileaccess in --run--
Operand stack:
   (mystical.ps)   (r)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   run   --nostringval--   2   %stopped_push   --nostringval--   run   run   false   1   %stopped_push   1949   1   3   %oparray_pop   1948   1   3   %oparray_pop   1933   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   run   --nostringval--   2   %stopped_push   --nostringval--   1949   1   3   %oparray_pop   run
Dictionary stack:
   --dict:751/1123(ro)(G)--   --dict:0/20(G)--   --dict:85/200(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 27
GPL Ghostscript 10.05.1: Unrecoverable error, exit code 1

G:\Dev\Mistical\mystical_ps>ps2pdf -dNOSAFER first.ps

G:\Dev\Mistical\mystical_ps>

これは、 GhostScript 9.50 以降にデフォルトになったファイルアクセス制御が原因です。
そのファイルアクセス制御を抑制する -dNOSAFER オプションを追加して実行することで、そのエラーを回避できます。

I use gv, which requires X and is only available on homebrew through a nonstandard cask, because I like its functionality much more than gsview, but in any case it’s useful to be able to interpret ps without generating a pdf. You will need to add the -dNOSAFER option to “gs options” in whatever tool you use.

私は gv を使用します。これは X を必要とし、非標準カスクを介して homebrew でのみ利用可能です。これは、その機能が gsview よりもはるかに気に入っているためです。しかし、いずれにせよ、pdf を生成せずに ps を解釈できるのは便利です。  どのツールを使用する場合でも、「gs options」に「-dNOSAFER」オプションを追加する必要があります。
mystical_ps/INSTALL.md at main · denismm/mystical_ps

Ghostscript 9.50 以降ではデフォルトでファイルアクセス制御が有効となったため,-dNOSAFER オプションが必要となりました. オプションを付けないと,PBM への変換処理に失敗して警告ダイアログボックスが表示されます.

USBメモリ活用講座【dviout for Windowsポータブル化】

テスト

コマンドプロンプトを起動して、first.ps ファイルのあるフォルダで、以下のコマンド実行します。

ps2pdf -dNOSAFER first.ps

特に何もメッセージが表示されなければ成功です。
pdf ファイルが同じフォルダに作成されていることを確認しましょう。

Microsoft Windows [Version 10.0.19045.5854]
(c) Microsoft Corporation. All rights reserved.

G:\Dev\Mistical\mystical_ps>ps2pdf -dNOSAFER first.ps

G:\Dev\Mistical\mystical_ps>

カレントディレクトリに ps ファイルと同じ名前first.pdf が作成され、PDF Acrbat Reader で開くと以下のような魔法陣の画像が表示されました。

Mystical ps2pdf でイントロに書かれていたfirst.psの画像のpdfを作成

作成した PDF の魔法陣のベクター画像の編集

作成した PDF の魔方陣のベクター画像編集については以下の記事を参照してください。

まとめ

今回は、PostScript 言語で作成したプログラムを魔法陣の画像に変換する Mysticle公式 GitHub のイントロのページに書かれている用例を、実際に行って、プログラムから魔法陣の画像をファイル出力する手順を紹介しました。
PostScript の実行には、 Ghostscript (Windows 版の gswin64c) の ps2pdf を使用しました。

参照サイト Thank You!

記事一覧 → Compota-Soft-Press

コメント

Ads Blocker Image Powered by Code Help Pro

お願い - Ads Blocker Detected

このサイトは広告を掲載して運営しています。

ポップアップを閉じて閲覧できますが、よろしければ

このサイト内の広告を非表示にする拡張機能をオフにしていただけませんか?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

タイトルとURLをコピーしました