タイルは、歩道の境界の長さと幅、およびユーザが指定したタイルの半径と間隔に基づいて、庭園の歩道の境界内に描画されます。
庭園の歩道の境界の計算と描画に使用する関数を定義したら、次の手順は、庭園の歩道の境界内のタイルの計算と配置に使用する関数を定義することです。タイルの描画関連のタスクを完了するためには、次の 3 つのカスタム関数を使用します。
庭園の歩道のタイルの計算と描画に使用する関数を、gpdraw.lsp ファイルに追加します。このファイルには、庭園の歩道の境界の計算と描画に使用される関数も含まれます。次に、gpdraw.lsp ファイルを開く方法を説明します。
次のいずれかの操作を行います。
[すべてのプログラム]
[アクセサリ]
[メモ帳]をクリックします。[ファイル]メニュー、[開く]の順に選択します。[ファイルの種類]ドロップ ダウンリストから[すべてのファイル(*.*)]を選択します。gpdraw.lsp ファイルを参照して選択し、[開く]を選択します。 次の手順では、gp: calcTiles という名前の関数を定義できます。この関数は、庭園の歩道の境界に沿った列数を計算します。
gp:calcTiles 関数は、次の単一の引数を受け入れます。
gp:calcTiles 関数は、庭園の歩道の境界に追加されるすべてのタイルのリストを返します。
(defun gp:calcTiles (boundaryData /
pathLength tileSpace tileRadius
spaceFilled spaceToFill rowSpacing
offsetFromCenter rowStartPoint
pathWidth pathAngle tileList
)
(setq
;;; Get values from the BoundaryData list
pathLength (cdr (assoc 41 boundaryData))
tileSpace (cdr (assoc 43 boundaryData))
tileRadius (cdr (assoc 42 boundaryData))
spaceToFill (- pathLength tileRadius)
rowSpacing (* (+ tileSpace (* tileRadius 2.0))
(sin (Degrees->Radians 60))
)
spaceFilled rowSpacing
offsetFromCenter 0.0
offsetDistance (/ (+ (* tileRadius 2.0) tileSpace) 2.0)
rowStartPoint (cdr (assoc 10 boundaryData))
pathWidth (cdr (assoc 40 boundaryData))
pathAngle (cdr (assoc 50 boundaryData))
)
;; Compensate for the very first Start Point!
(setq rowStartPoint
(polar rowStartPoint
(+ pathAngle pi)
(/ tileRadius 2.0)
)
)
;; Draw each row of tiles
(while (<= spaceFilled spaceToFill)
;; Get the list of tiles created, adding them to our list
(setq tileList (append tileList
(gp:calcTileRow
boundaryData
(setq rowStartPoint
(polar rowStartPoint
pathAngle
RowSpacing
)
)
offsetFromCenter
)
)
;; Calculate the distance along the path for the next row
spaceFilled (+ spaceFilled rowSpacing)
;; Alternate between a zero and a positive offset
;; (causes alternate rows to be indented)
offsetFromCenter (if (= offsetFromCenter 0.0)
offsetDistance
0.0
)
)
)
;; Return the list of tiles created
tileList
)
次の手順では、gp:calcTileRow という名前の関数を定義できます。この関数は、gp calcTiles 関数によって計算された列のタイル数を計算します。
gp:calcTileRow 関数は、次の 3 つの引数を受け入れます。
gp:calcTileRow 関数は、庭園の歩道の境界内の 1 つの列に追加されるすべてのタイルのリストを返します。
(defun gp:calcTileRow (boundaryData startPoint offsetFromCenter /
halfWidth tileSpacing angp90 angm90
firstCenterPt tileCenterPt tileList
pathWidth pathAngle tileRadius tileSpace
tileShape
)
; Extract values from the list boundaryData
(setq pathAngle (cdr (assoc 50 boundaryData))
pathWidth (cdr (assoc 40 boundaryData))
tileRadius (cdr (assoc 42 boundaryData))
tileSpace (cdr (assoc 43 boundaryData))
tileShape (cdr (assoc 5 boundaryData))
)
; Calculate values for placing tiles along in the garden path boundary
(setq halfWidth (- (/ pathWidth 2.00) tileRadius)
tilespacing (+ (* TileRadius 2.0) tileSpace)
angp90 (+ pathAngle (Degrees->Radians 90))
angm90 (- pathAngle (Degrees->Radians 90))
firstCenterPt (polar startPoint angp90 offsetFromCenter)
tileCenterPt firstCenterPt
)
; Draw the circles to the left of the center
(while (< (distance startPoint tileCenterPt) HalfWidth)
; Add each tile to the list to return
(setq tileList
(cons (gp:drawTile tileCenterPt tileRadius tileShape pathAngle)
tileList
)
)
; Calculate the center point for the next tile
(setq tileCenterPt (polar tileCenterPt
angp90
tileSpacing
)
)
)
; Draw the circles to the right of the center
(setq tileCenterPt (polar firstCenterPt
angm90
tileSpacing
)
)
(while (< (distance startPoint tileCenterPt) HalfWidth)
; Add each tile to the list to return
(setq tileList (cons (gp:drawTile tileCenterPt tileRadius tileShape pathAngle)
tileList
)
)
; Calculate the center point for the next tile
(setq tileCenterPt (polar tileCenterPt
angm90
tileSpacing
)
)
)
; Return a list containing the tiles drawn
tileList
)
次の手順では、gp:drawTile という名前の関数を定義できます。この関数は、gp:calcTileRow によって計算されたタイルを描画します。
gp:drawTile 関数は、次の 3 つの引数を受け入れます。
gp:drawTile 関数は、描画される円オブジェクトまたはポリライン オブジェクトの図形名を返します。
(defun gp:drawTile (centerPoint tileRadius tileShape tileRotation / )
(if (= (strcase tileShape) "CIRCULAR")
(command "._CIRCLE" centerPoint tileRadius)
(progn
(command "._POLYGON" 6 centerPoint "_I" tileRadius)
(command "._ROTATE" (entlast) "" centerPoint (Radians->Degrees tileRotation))
)
)
(entlast)
)