0

I'm trying to call the randomVector method from the Vec2D class found here http://toxiclibs.org/docs/core/

Here is my code:

(def particles (new ArrayList))


(defn add-particle []
  (dotimes [i 100]
    (doto particles
      ;(.add (new Vec2D (random (width)) (random (height))))
      (.add (Vec2D/randomVector))))

So far so good but I need to call other methods like scale and add from the same class, I have not idea how to do that in Clojure

Here is how I do it in Java:

Vec2D position = Vec2D.randomVector().scale( 60 ).add( canvasCenter );

Any help will be much appreciated

2

1 Answer 1

2

Try the following code, java static methods should be called like (ClassName/methodName arguments)

(defn add-particle []
  (dotimes [i 100]
    (doto particles
      (.add (Vec2D/randomVector)))))

For your second question, any way you need to define canvasCenter some where.

(defn add-particle []
      (dotimes [i 100]
        (doto particles
          (.add (.scale (Vec2D/randomVector) (float 60)) canvasCenter)))
Sign up to request clarification or add additional context in comments.

8 Comments

Oh thanks Kugathasan I found the answer on the other post someone point me as duplicate, but I edited the question wonder if you can help me
@RicardoSancher: Can you please check the answer now?
Not yet as I'm getting the following error "No matching method found: scale for class toxi.geom.Vec2D" ;)
@RicardoSanchez, just check, scale method accept float value.
@RicardoSanchez: use (float 60.0)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.