How should I draw a path from points

42 views
Skip to first unread message

lihui guo

unread,
Jan 9, 2019, 1:09:49 AM1/9/19
to seesaw-clj
There is a macro `path`:

(def star 
  (path [] 
    (move-to 0 20) (line-to 5 5) 
    (line-to 20 0) (line-to 5 -5)
    (line-to 0 -20) (line-to -5 -5)
    (line-to -20 0) (line-to -5 5)
    (line-to 0 20)))

But when I has some points, How should I do?

(def points [[0 20] [20 20] [20 0] [0 0]])
(dean my-path [points]
  ?)

Because `path` is a macro, so I only use java interop to implementation it. How did I do without using java interop?

abacus

unread,
Jan 9, 2019, 5:36:15 AM1/9/19
to seesaw-clj
You would like to (move-to ... the first point, right?

And then you would like to (line-to ... each additional point?

I think you will need (first points),  (rest points),  and a loop.  The fundamental loop is (loop...) and it would definitely suffice, but (doseq...) would be easier.  See https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/doseq

lihui guo

unread,
Jan 10, 2019, 2:57:08 AM1/10/19
to seesaw-clj
but move-to, line-to is not function. So I only use java interop:

(let [p (path [])]
 
(.moveTo p 0, 0)
 
(doseq [[x y] points]
   
(.lineTo p x y)))



在 2019年1月9日星期三 UTC+8下午6:36:15,abacus写道:
Reply all
Reply to author
Forward
0 new messages