LoginSignup
2

More than 5 years have passed since last update.

素数夜曲の題材をISLispで試す

Last updated at Posted at 2017-06-10

2017-06-11_6-58-01.png

はじめに

Easy-ISLispのWindows版に簡易グラフィクスを加えました。これにより吉田武先生の「素数夜曲」の題材を試してみることができるようになりました。学習用開発環境Babbageに同梱されているver0.78以降でお試しいただけます。

使い方

REPLを起動し、(load "plot.o")によりライブラリを読み込みます。↓の黄金花のISLispコードを読み込みます。

(open-window)と入力するとグラフィクス用の画面が現れます。そこでREPLから
(repdec (lambda (x) (check1 1 2539 x)) 300)
と入力します。カラフルな図形が現れます。パラメータを変えると不思議な図形が楽しめます。詳細は吉田武先生の「素数夜曲」をご参照ください。
終わる時は(close-window)でグラフィクス画面が閉じます。

グラフィクスライブラリの詳細については下記を参照してください。
https://qiita.com/sym_num/items/9883da295fa5fefd795b

出典

吉田武先生 「素数夜曲」

コードに対する著作権は吉田武先生が有します。
原コードをISLisp用に一部修正させていただきました。

2017-12-17_9-45-44.png

コード

#|
;;Copyright (C) Takeshi Yoshida. All Rights Reserved. 
素数夜曲より p739
 使い方
(open-window)

(repdec (lambda (x) (check1 1 2539 x)) 300)
イロイロとパラメータを変えて遊ぶ。
(close-window)
 |#


(set-origin 300 300)
(set-zoom 20)

(defun check (a b i)
   (if (= i 0)
       (mod a b)
       (mod (* 10 (check a b (- i 1))) b)))

(defun check1 (a b i)
   (if (= i 0)
       (div a b)
       (div (* 10 (check a b (- i 1))) b)))

(defun colors (n)
   (case n
     ((0) 'blue)
     ((1) 'red)
     ((2) 'green)
     ((3) 'cyan)
     ((4) 'brown)
     ((5) 'purple)
     ((6) 'orange)
     ((7) 'yellow)
     ((8) 'magenta)
     ((9) 'black)))


(defun repdec (proc n)
   (let* ((num (quotient (+ 1 (sqrt 5)) 2))
          (ang (quotient (* 2 *pi*) (+ 1 num)))
          (size 0.1)
          (k (lambda (x) (* 10 (expt 0.998 x)))))
     (mapc (lambda (t1)
             (pen-color (colors (funcall proc t1)))
             (circle (* (k t1) (cos (* t1 ang)))
                     (* (k t1) (sin (* t1 ang)))
                     (* (k t1) size)
                     t))
           (iota (- n 1)))
     t))

(defun iota (n :rest opt)
  (let ((start (if (>= (length opt) 1) (elt opt 0) 1))
        (step (if (= (length opt) 2) (elt opt 1) 1)))
    (for ((m start (+ m step))
          (ls nil (cons m ls)))
         ((> m n)
          (reverse ls)))))


学習用開発環境Babbage

素数夜曲を試すなど学習用の簡易開発環境です。Easy-ISLispとO-Prologが同梱されています。
http://eisl.kan-be.com/babbage.html

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2