On Friday, October 24, 2014 11:14:56 AM UTC-4, Fluid Dynamics wrote: > > On Friday, October 24, 2014 10:42:37 AM UTC-4, Kasper Jordaens wrote: >> >> Hey, >> >> I've been experimenting with newtonian, I love it, but I have a simple >> question, because I'm stuck >> >> after adding some emitters >> >> [#newtonian.corporum.ParticleEmitter{:position >> #newtonian.utils.Vector2D{:x 23.0, :y 280.0}, :velocity >> #newtonian.utils.Vector2D{:x 0.0, :y 10.0}, :size 8, :life -1, :spread >> 0.09817477042468103, :emission-rate 4} >> #newtonian.corporum.ParticleEmitter{:position #newtonian.utils.Vector2D{:x >> 200.0, :y 280.0}, :velocity #newtonian.utils.Vector2D{:x 0.0, :y 10.0}, >> :size 8, :life -1, :spread 0.09817477042468103, :emission-rate 4}] >> >> >> I want to dynamically change them but this seems to be inaccessible as an >> atom? >> >> I can get to individual objects like >> >> (get (nth @newt/emitters 0) :position) ==> #newtonian.utils.Vector2D{:x >> 23.0, :y 280.0} >> >> >> but how can I swap the atom at Vector2D? >> >> >> (swap! (get (nth @newt/emitters 0) :position) :x 200) ==> java.lang. >> ClassCastException: newtonian.utils.Vector2D cannot be cast to clojure. >> lang.Atom core.clj:2233 clojure.core/swap! >> >> > What you want here is update-in. Try > > (swap! newt update-in [:emitters 0 :position] assoc :x 200) > > assuming that @newt is a map with an :emitters key. I'm not familiar with > the library and I'm not even sure what kind of object could be in the atom > newt that @newt/emitters makes sense, but when you want to "change" a thing > buried deep in a nested associative data structure the usual tool for that > is update-in. >
I looked briefly at the newtonian docs and it looks like newt/emitters is the atom, hmm, global vars? Anyway you just want (swap! newt/emitters update-in [0 :position] assoc :x 200) then, to replace the value of x in the first emitter. You could also use (swap! newt/emitters update-in [0 :position :x] + 100) and the like to "move" that emitter's x around relative to where it was, here 100 units further right one presumes. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.