Function: artist-draw-sline

artist-draw-sline is a byte-compiled function defined in artist.el.gz.

Signature

(artist-draw-sline X1 Y1 X2 Y2)

Documentation

Draw a straight line from X1, Y1 to X2, Y2.

Straight lines are vertical, horizontal or diagonal lines. They are faster to draw and most often they are what you need when drawing a simple image.

Output is a straight line, which is a list on the form
(END-POINT-1 END-POINT-2 SHAPE-INFO).

END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y]. SHAPE-INFO is a vector [START-X START-Y LENGTH-OF-LINE DIRECTION
                        ORIGINAL-CHAR-1 ORIGINAL-CHAR-2 ... ].

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/artist.el.gz
;;
;; Drawing and undrawing straight lines
;;

(defun artist-draw-sline (x1 y1 x2 y2)
  "Draw a straight line from X1, Y1 to X2, Y2.
Straight lines are vertical, horizontal or diagonal lines.
They are faster to draw and most often they are what you need
when drawing a simple image.

Output is a straight line, which is a list on the form
\(END-POINT-1 END-POINT-2 SHAPE-INFO).

END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
SHAPE-INFO is a vector [START-X START-Y LENGTH-OF-LINE DIRECTION
                        ORIGINAL-CHAR-1 ORIGINAL-CHAR-2 ... ]."
  (let* ((line (artist-save-chars-under-sline (artist-sline x1 y1 x2 y2)))
	 (x (aref line 0))
	 (y (aref line 1))
	 (length (+ (aref line 2) 4))
	 (direction (aref line 3))
	 (line-char (artist-direction-char direction))
	 (i 4)
	 (endpoint1 (artist-make-endpoint x y))
	 (endpoint2 nil))
    (while (< i length)
      (artist-move-to-xy x y)
      (if artist-line-char-set
	  (artist-replace-char artist-line-char)
	(artist-replace-char (artist-intersection-char
			      line-char
			      (aref line i))))
      (if (not (< (1+ i) length))
	  ;; This is the last element. Set the second endpoint
	  (setq endpoint2 (artist-make-endpoint x y)))
      (setq x (+ x (artist-direction-step-x direction)))
      (setq y (+ y (artist-direction-step-y direction)))
      (setq i (1+ i)))
    (artist-make-2point-object endpoint1 endpoint2 line)))