Non-recursive js->clj in ClojureScript - clojurescript

I have a JavaScript array of JavaScript objects. I'd like to turn it into a vector of JavaScript objects. However, js->clj is recursive, such that the JavaScript objects themselves would be turned into CLJS maps.
How can I turn a JavaScript array into a CLJS vector without touching the elements inside the array?

(vec the-array) or (into [] the-array) will both turn the array into a vector and not touch the objects at all.

Related

Figwheel reloadable code with atom as local (lexical) state?

I'm evolving my way towards a suitable design for state with reagent given my project, and while still using distinct atoms (i'll probably switch to a single atom, but trying to explore the space of possibilities at present), I've tried to set up all state in the lexical context of the root component, as illustrated below. Idea is that this app-state is an ordinary clojure map where the value of each key is a reagent atom.
It receives an attrs map which is a prop (coming from data- attrs on the html element), and its job is to initialise an app-state map, which is not itself an r/atom, but contains r/atoms. The problem is, all of these r/atoms were defined with defonce when declared at the top of the file, which is what I've just switched from, and now the defonce semantics is lost & figwheel hot reloading is broken.
Is there a way to preserve reloadable code while setting up state in this style?
I cannot put a defonce inside a let, because subsequent times that is evaluated it will evaluate to nil.
Or is there some pattern I'm missing here.
(defn a-root-component [attrs]
(let [app-state {:some-state (r/atom (:some-state attrs))}]
(fn [attrs]
[some-component app-state])))
Technically you could use memoize, but I wouldn't. By using memoize your introducing hidden global state, cleverly hidden where no one will think to look for it. Better to defonce your state outside your main component and be explicit about it.
Given the direction your moving I'd look carefully at things like re-frame and Keemcha which provide established patterns and tooling for working with centralized state in a sane way.

Shadow-casting shaders in Stage3D

I've been working a lot with AGAL vertex and fragment shaders. I've got individual objects lit correctly (including specular shading) but I'd like to have objects cast shadows on OTHER objects. I have looked online, but I think most people working directly with AGAL have built custom Stage3D libraries and the shadow-casting solution doesn't seem to be in the public domain. Anyone willing to change that?
I'd like to know how to get an object to cast a shadow on another. I can't post what I've tried, because I can't get my head around where to begin on this problem. How would you pass the information (whether other objects are blocking the light) into another object's shader?
Thanks.
IT's called Deferred shading, you have to do 2 pass of vertex and fragment shaders.
In the first pass you accumulate informations about distances, normals, occlusion...
In the second pass you render and apply the informations of the first pass to make shadows.
Another options is ShadowMapping:
Basic shadowmap
The basic shadowmap algorithm consists in two passes. First, the scene is rendered from the point of view of the light. Only the depth of each fragment is computed. Next, the scene is rendered as usual, but with an extra test to see it the current fragment is in the shadow.
The “being in the shadow” test is actually quite simple. If the current sample is further from the light than the shadowmap at the same point, this means that the scene contains an object that is closer to the light. In other words, the current fragment is in the shadow.

SceneJS graphing examples

Are there any good open source SceneJS examples that can graph functions similar to those demonstrated in http://www.graphycalc.com/?
I haven't seen any but it should be relatively easy to simply use a custom vertex shader that transforms the vertices of a grid into your desired function: https://github.com/xeolabs/scenejs/wiki/shader
You can also use a data source plugin with a geometry node, to continually update it's mesh:
http://scenejs.org/examples.html?page=geometryPluginPullStream
http://scenejs.org/examples.html?page=geometryPluginPushStream
And here's the available vertex deformation examples (selected by tag, see left column, click one to load it):
http://scenejs.org/examples.html?tags=vertexDisplacement

actionscript library for interactive path drawing (or any other library for the equations

I am making a flash app where I want to have a user defined viewport like the stage in the flash IDE which the user can use to define objects that have a starting postition somerwhere off or on the stage and an ending position either or on or off the stage with the object then tweening between the two points.
My question is this: I want the user to be able to define a curved path for the object to tween along. Is there a library of code that I can use to define curved paths for the app?
Ideally I would like something similar to the functionality available in Flash, so a bezier curve sort of path that is subdivided into handles that can be dragged to define the path of the tween.
If there isn't an existing library, then do you know of the functions that I would need to define (mathematical equations related to drawing curves etc)?
Many thanks
You could use TweenMax with the BezierPlugin
Or define the path elsewhere and use LinePath2D

TweenLite does not work with object

I got the following problem:
I have an object called tempScore for my game.
This object is blitted to the canvas by a renderer via the copyPixels method. The object is NOT a display object. It's a Score-object (self made). The Score-object extends an object called BasicBlitArrayObject. The BasicBlitArrayObject extends an EventDispatcher (therefore no display object).
I tried to apply several different TweenLite-plugins to my tempScore-object (i.e. TransformAroundCenter, colorMatrixFilter, etc.). But nothing happens. Absolutely nothing.
Sometimes I get error messages (when a plugin requires a display object and my object is NOT a display object). So far so good.
According to Greensock (maker of Tweenlite) his engine can tween ANY numeric property of ANY object. So when a plugin like TransformAroundCenter requires a display object for tweening I have to modify the plugin to get it working for my non-display object (tempScore). Currently I can't do that because it's way too hard for me.
My game rests upon this code:
http://www.8bitrocket.com/book/ch11_blastermines.zip
Try to apply TweenLite with an object called tempMine inside the game class BlasterMines. It won't work. Any help, please?
Greensock's claim is correct, in it's exactness. You can tween any numeric property of any object. This statement does not include the application of plugin features.
The reason that the TransformAroundCenter and ColorMatrixFilter plugins don't work for you is that they each utilise some property or method of DisplayObject. In the case of transformAroundCenter that's DisplayObject.localToGlobal() and for ColorMatrixFiler it's DisplayObject.filters.
I have to ask why you're applying these plugins to something that is not a display object? In blitting (as it applies to AS3), the basic idea is that you read an area from a sprite sheet to a BitmapData object, which in turn you write to a Bitmap object on the stage. Both BitmapData and Bitmap extend DisplayObject, which is what you need. For higher compatibility you should target the Bitmap object that is actually on the stage, TransformAroundCenter will not work correctly with an object that is not on the stage.
For a better answer you will have to post some code, and possibly a screenshot from a debugger like Monster Debugger 3 which shows your expanded display tree.