
(define (translate-point x y angle distance)
  (let* ((ang (* angle (/ (* 4 (atan 1.0)) 180)))
	 (nx (+ (* distance (cos ang)) x))
	 (ny (+ (* distance (sin ang)) y)))
    (list nx ny)
  )
)



(define (script-fu-ellipse-path-dn img drawable name)

  (gimp-image-undo-group-start img)
   
  (let* ((pathvector (car (gimp-vectors-new img name)))
     (x (/ (car (gimp-image-width img)) 2))
     (y (/ (car (gimp-image-height img)) 2))
     (rotation 0)
     (radiusx (/ (car (gimp-image-width img)) 2))
     (radiusy (/ (car (gimp-image-height img)) 2))
	 (kappa (* (/ (- (sqrt 2) 1) 3) 4))
	 (clengthx (* radiusx kappa))
	 (clengthy (* radiusy kappa))
	 (aone (translate-point x y (- rotation 90) radiusy))
	 (atwo (translate-point x y rotation radiusx))
	 (athree (translate-point x y (+ rotation 90) radiusy))
	 (afour (translate-point x y (+ rotation 180) radiusx))
	 (conea (translate-point (car aone) (cadr aone) (+ rotation 180) clengthx))
	 (coneb (translate-point (car aone) (cadr aone) rotation clengthx))
	 (ctwoa (translate-point (car atwo) (cadr atwo) (- rotation 90) clengthy))
	 (ctwob (translate-point (car atwo) (cadr atwo) (+ rotation 90) clengthy))
	 (cthreea (translate-point (car athree) (cadr athree) rotation clengthx))
	 (cthreeb (translate-point (car athree) (cadr athree) (+ rotation 180) clengthx))
	 (cfoura (translate-point (car afour) (cadr afour) (+ rotation 90) clengthy))
	 (cfourb (translate-point (car afour) (cadr afour) (- rotation 90) clengthy))
	 (strokeid (car (gimp-vectors-bezier-stroke-new-moveto pathvector (car aone) (cadr aone)))))
     (gimp-vectors-bezier-stroke-cubicto pathvector strokeid (car coneb) (cadr coneb) (car ctwoa) (cadr ctwoa) (car atwo) (cadr atwo))
     (gimp-vectors-bezier-stroke-cubicto pathvector strokeid (car ctwob) (cadr ctwob) (car cthreea) (cadr cthreea) (car athree) (cadr athree))
     (gimp-vectors-bezier-stroke-cubicto pathvector strokeid (car cthreeb) (cadr cthreeb) (car cfoura) (cadr cfoura) (car afour) (cadr afour))
     (gimp-vectors-bezier-stroke-cubicto pathvector strokeid (car cfourb) (cadr cfourb) (car conea) (cadr conea) (car aone) (cadr aone))
     (gimp-vectors-stroke-close pathvector strokeid)
     (gimp-image-add-vectors img pathvector -1)
     (gimp-image-set-active-vectors img pathvector)
     ;(stroke-fill-path img drawable pathvector strokepath scolor fillpath fcolor)
     (gimp-displays-flush)
  )

  (gimp-image-undo-group-end img))


(script-fu-register "script-fu-ellipse-path-dn"
		    _"<Image>/DNmodified/Shape Paths/_Ellipse..."
		    "Creates an elliptical path."
		    "Jonathan Stipe <JonStipe@prodigy.net>"
		    "Jonathan Stipe"
		    "December 2004"
		    ""
		    SF-IMAGE "Image" 0
		    SF-DRAWABLE "Drawable" 0
		    SF-STRING	"Name"	"Ellipse"
)
