Why does the locator look semi-transparent in this Dynamic graphic? - wolfram-mathematica

I want a position a locator on a graphic, and update its position based on the mouse position. Here is some sample code:
Show[{
Graphics[{Yellow, Rectangle[]}],
Graphics[Dynamic[
With[{pt = MousePosition[{"Graphics", Graphics}]},
{ If[pt===None, ,Locator[pt^2]], Text[pt, {0,0}, {-1,-1}] }
]
]]
}, PlotRange -> {{-.2, 1.2},{-.2, 1.2}}]
The weird thing is that sometimes the locator displays normally, sometimes it displays at what looks like half opacity. It flips from normal to half-opacity as I move the mouse around.
Why is this, and what can I do to fix it?
I'm using Mathematica 8 on OSX.

Related

gsap Flip.fit svg element not moving to expected coordinates because of { duration: x }

I am confused with gsap's Flip.fit moving to coordinates.
I have a game board with 182 tiles and 182 playing tiles.
The goal
When the user clicks the bag, a random playing tile is selected and is "supposed" to move over the tile on the board.
If you change
Flip.fit(PTILE[tileArray], TILE[tileArray], {duration: 1 , scale: true});
when changing { duration: 0, ... } the move works as expected, however no animation. When duration is above zero, the final location is very random.
codepen
I'm not sure how the duration affects the final position, however, I found a way to get the positions right. That is reset the transform of your PTILE before telling GSAP to do the Flip animation.
// reset transform value
gsap.set(PTILE[tileArray], { transform: "" });
// animate with new transform value
Flip.fit(PTILE[tileArray], TILE[tileArray], {
duration: 1,
scale: true
});
My reason is that PTITLE and TITLE are placed in different <g> tags which means their transform systems are inconsistent. Plus, Flip.fit() will act like gsap.to() with new TITLE position is the to object, GSAP will try to calculate the from object from your original transforms which are already set in the SVG as transform:matrix(). This process, somehow, is messing up. So what I did is give GSAP an exact transform value for the from object, which is empty.
Ok, I found out that Inkscape stores the SVG with inline transforms that threw the animation off. I tried saving in plain or optimised, but still had no luck.
So there are two solutions.
Use SVGOMG an online SVG cleaner.
Use Affinity Designer application which can export and flatten transforms.
The key to rule out other factors is to use relative coordinates and flatten transforms.
I have included a screenshot of Affinity exporting options.
Affinity Export screenshot

How do i animate on mouse over in Elm-UI?

I would like a simple wipe when hovering over a button. I figured out to use mouseOver to change the background on hover, but I am not sure how to create a wipe from one background to another.
I am aware of elm-simple-animation, but I am too new to Elm to understand the docs..
Thanks!
This is surprisingly involved and part of it is I suspect that a proper transition library specifically designed around elm-ui is (AFAICT) still missing.
The basics steps are like this:
Define properties for the start and mouseOver states.
Figure out which properties these correspond to in elm-simple-animation.
Add a transition for those.
Element.Input.button
[ Background.color (Element.rgb 0.5 0.5 0.6)
, Element.mouseOver
[ Background.color (Element.rgb 0.7 0.7 1)
]
, Transition.properties
[ Transition.backgroundColor 500 []
]
|> Element.htmlAttribute
]
{ onPress = Nothing
, label = Element.text "Hello"
}
You can see a working example here.

Eventhandler won't let me select graphic when MouseClicked is assigned

I'm trying to digitize points in an image and I would like to use KeyDown events to clear selected points.
For the KeyDown to work the image must be selected by clicking it (orange border shows around the image).
When the MouseClicked is assigned it will register the point in my image, but the image won't be selected, and so the KeyDown won't work.
I've figured out that I can select the image using the right mouse button instead.
I was hoping to find a way to have the code automatically select the image for me as soon as the document is created.
Does anybody know how to do this?
This is for my research so that I can digitize the location of features within an ultrasound image.
I've tried using the SelectionMove[] function in a couple of different ways, but it doesn't work.
CreateDocument[
DynamicModule[
{pnts = {}},
EventHandler[
Show[
img,
Epilog -> {Red, Point[Dynamic[pnts]]}
],
{
{"MouseClicked",
1} :> {AppendTo[pnts, MousePosition["Graphics"]]},
"EscapeKeyDown" :> {pnts = {}}
}
]
]
];
It opens the image, and I can place points. However, I can't clear them with the EscapeKeyDown.
my image -> https://imgur.com/a/qgksuBP
It looks like the problem is vaguely answered in the docs: "For mouse events, EventHandler[expr, ...] handles events for which the mouse is within the rectangular region defined by the display of expr." Implying that keyboard events work differently.
You could use something like this.
pnts = {};
SetOptions[CreateDocument[
EventHandler[Show[img, Epilog -> {Red, Point[Dynamic[pnts]]}],
{"MouseClicked", 1} :> AppendTo[pnts, MousePosition["Graphics"]]]],
NotebookEventActions :> {"EscapeKeyDown" :> (pnts = {})}]

How to change the source anchor starting position in JsPlumb?

I'm developing an app using jsPlumb. Currently, if I create a shape, it puts the shape in the top left corner of the canvas. And If I connect from source to target point, it is working.
Now, I want to create the shape on the position where I right clicked and connect from source to target. I'm able to create the shape in the position where i right clicked.
But, if I drag from source to target, the source anchor is not starting from the source. Instead, it starts from the top left corner. In the screenshot below, I want to drag from 'Project' to 'No status' shape.
One more thing is, if I drag the 'Project' shape, endpoint is starting from source correctly.
I have figured the problem. Earlier, ,the if block (1) in the code was below the code (2). That's why even thought the shape moved to the new location, the starting location of the anchor didnt move. As soon as I move the if block(1) above (2), jsPlumb understands the shape's location as well as the anchor's starting point location.
So, if you are moving the shape, you should do it before you tell the shapes location to Jsplumb.
if (!!shape.location) { ------------------------------------> 1)
domEl.style.left = shape.location.left + 'px';
domEl.style.top = shape.location.top + 'px';
}
this.jsPlumbInstance.draggable(domEl, {
// to contain the shape within the canvas
// containment: true
});
this.jsPlumbInstance.makeSource(domEl, { ----------------------2)
filter: '.cp',
anchor: ['AutoDefault'],
connectorStyle: {
stroke: '#181919',
strokeWidth: 2,
outlineStroke: 'transparent',
outlineWidth: 4
}
});

How to give control back to animation in Unity3D once altering objects location

I have a character made of up child objects that are animated using Unity3D's animation system.
While the player is walking, I can programmatically move the hand object up to catch a ball using the following code.
hand.position.y = ball.transform.position.y;
I need the hand object to go back to following the walk animation after it touches the ball, but instead it just stays at the exact position since it was set.
You want to use inverse kinematics and let Unity do the work of figuring out positioning for you. Here's a quick-and-dirty (untested) example for catching a ball (it's in C#, but it should be pretty similar for UnityScript):
// in a script on the same GameObject as your animation controller
bool isCatching;
Transform ball;
void OnAnimatorIK (int layer) {
if (isCatching) {
// set position and rotation weights for your catching hand
animator.SetIKPosition(AvatarIKGoal.RightHand, ball.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, ball.rotation);
} else {
// return your position and rotation weights back to their defaults (probably 0f?)
}
}
You'll need to do some work (possibly raycasting or just checking distance and direction) to determine when to set the isCatching flag to true, and you'll want to play with the weights for position and rotation to make it look natural. The IK manual entry has more detailed information.

Resources