; -----------------------------------------------------------------------------
; (jp_wikiwiki_aiou_layoutInstancesYIchimatsu instances rows basePoint pitches startsByCorner)
; -----------------------------------------------------------------------------
; 与えられたインスタンス列 instances の要素を市松模様に配置する。
; 配置の順番は「N」の字の筆順。※一筆書きの場合ですよ~。(*´∀`*)
; ※ インスタンスの向き(R0、MY 等)は変更しない。
; instances : 配置させたいインスタンス群
; rows : 市松模様の仮想格子の行数。
; basePoint : 市松模様の仮想格子の基準点。
; pitches : 市松模様の仮想格子の1列の幅、1行の高さを要素とするリスト。要素は負数でも良い。
; startsByCorner : 開始点を格子の角とする場合は t、その上隣(下隣)の位置とする場合は nil。
;
; 《例1》 (1.5, 3.75) の位置を基準に X方向ピッチ 13.5、Y方向ピッチ 7.25、
; 行数 6 の格子に、角を開始点として 8 個のインスタンスを配置する。
;
; (setq instances (list ~8個のインスタンス~))
; (jp_wikiwiki_aiou_layoutInstancesYIchimatsu instances 6 '(1.5 3.75) '(13.5 7.25) nil)
;
; |-|5|-|
; |2|-|-|
; |-|4|-|
; |1|-|7|
; |-|3|-|
; |0|-|6|
;
; ※「0」の位置が (1.5, 3.75) である。
;
; 《例2》 例1と同様だが、角の上隣を開始点とする。
;
; (jp_wikiwiki_aiou_layoutInstancesYIchimatsu instances 6 '(1.5 3.75) '(13.5 7.25) t)
;
; |2|-|-|
; |-|5|-|
; |1|-|7|
; |-|4|-|
; |0|-|6|
; |-|3|-|
;
; ※「0」の位置が (1.5, 3.75+7.25) である。
;
; 《例3》 例1と同様だが、Y方向ピッチを -7.25 とする。
;
; (jp_wikiwiki_aiou_layoutInstancesYIchimatsu instances 6 '(1.5 3.75) '(13.5 -7.25) nil)
;
; |0|-|6|
; |-|3|-|
; |1|-|7|
; |-|4|-|
; |2|-|-|
; |-|5|-|
;
; ※「0」の位置が (1.5, 3.75) である。
; -----------------------------------------------------------------------------
(define (jp_wikiwiki_aiou_layoutInstancesYIchimatsu instances rows basePoint pitches startsByCorner)
(setq instances (setof o instances (equal "inst" o~>objType)))
(mapcar
(lambda (i p) (i~>xy = (mapcar 'plus basePoint (mapcar 'times pitches p))))
instances
(Points_generateUnitYIchimatsu rows (length instances) startsByCorner)
)
)
; -----------------------------------------------------------------------------
; (Points_generateUnitYIchimatsu rows points_length startsByCorner)
; -----------------------------------------------------------------------------
; 仮想格子幅・高さが 1 の 市松模様 点列 を生成する汎用の関数。
; 点の順番は「N」字の筆順の。
; rows : 市松模様の仮想格子の行数。
; points_length : 生成する点の個数。
; startsByCorner : 開始点を角にする場合は t、その右隣(左隣)にする場合は nil。
;
; (現在の実装は generateUnitXIchimatsu の結果を X/Y 転置したものです。)
; -----------------------------------------------------------------------------
(define (Points_generateUnitYIchimatsu rows points_length startsByCorner)
(mapcar 'reverse (Points_generateUnitXIchimatsu rows points_length startsByCorner))
)
; -----------------------------------------------------------------------------
; (Points_generateUnitXIchimatsu columns points_length startsByCorner)
; -----------------------------------------------------------------------------
; 仮想格子幅・高さが 1 の 市松模様 点列 を生成する汎用の関数。
; 点の順番は「Z」字の筆順の Y 方向反転。
; columns : 市松模様の仮想格子の列数。
; points_length : 生成する点の個数。
; startsByCorner : 開始点を角にする場合は t、その右隣(左隣)にする場合は nil。
; -----------------------------------------------------------------------------
(define (Points_generateUnitXIchimatsu columns points_length startsByCorner)
(let
(
(offset (if startsByCorner 0 1))
(buffer nil)
)
(if (evenp columns)
(let
((halfColumns (xquotient columns 2)))
(for n 0 (sub1 points_length)
(letseq
(
(y (xquotient n halfColumns))
(x (xplus (modulo (xtimes 2 n) columns) (modulo (xplus y offset) 2)))
)
(setq buffer (cons (list x y) buffer))
)
)
)
; else
(for n 0 (sub1 points_length)
(letseq
(
(_2n_plus_offset (plus (xtimes 2 n) offset))
(x (modulo _2n_plus_offset columns))
(y (xquotient _2n_plus_offset columns))
)
(setq buffer (cons (list x y) buffer))
)
)
)
(reverse buffer)
)
)