view.interval({
width: 1,
items: 1,
channels: 3,
expr: function (emit, x, i, t) {emit(Math.sin(t), 0, 0);}})
.point({
color: 0x5555FF,
size: 10,
});
On May 3, 2016, at 14:11, Steven Wittens <steven....@gmail.com> wrote:
There's no simpler way to do this, no. We could add a .one() primitive to address this case, but it wouldn't simplify use that much, it would basically just let you drop the "width" prop. Internally this would avoid some machinery, but I doubt it would be a noticeable difference in performance, most of the cost is set up.
--
You received this message because you are subscribed to the Google Groups "MathBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathbox+u...@googlegroups.com.
To post to this group, send email to mat...@googlegroups.com.
Visit this group at https://groups.google.com/group/mathbox.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathbox/ae1adfaf-a048-47fc-9bd5-b04f9753828e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(Note that later on I'll want to change the ball's behaviour to something other than Math.sin(t).)
// define some functions with the proper signature
functionWithSin = function (emit, x, i, t) {emit(Math.sin(t), 0, 0);};
functionWithCos = function (emit, x, i, t) {emit(Math.cos(t), 0, 0);};
// create a presentation from a mathbox view.
view = view.present({index: 1}).slide({steps: 2});
// create the data
view.interval({
id: 'myPoint',
width: 1,
items: 1,
channels: 3,
expr: functionWithSin
})
// alternatively, call .step here to change expression of '#myPoint'? Didn't work for me.
.point({
color: 0x5555FF,
size: 10,
})
// animate the "drawable" thing with properties that can be "smoothly" transitioned
.step({
script: [{size:10}, {size: 20}]
});
var currentSlide = 1;
var maxSlides = 2;
function TriggerAnimation() {
// Call this function from deck.js or a button, etc?
currentSlide++;
if(currentSlide > maxSlides) currentSlide = 1;
var myPoint = mathbox.select("#myPoint");
var present = mathbox.select("present");
switch(currentSlide) {
case 1:
myPoint.set("expr", functionWithSin);
// Other non-interpolated "dynamic" behavior
break;
case 2:
myPoint.set("expr", functionWithCos);
break;
}
present.set("index", currentSlide);
}
I'm curious about the significance of named arguments provided to expr — or are they parameters? I'm curious because to pull a reference to an element's index value, sometimes it's sufficient to simply supply an "i" parameter like
.text({
font: 'Helvetica',
style: 'bold',
width: vocab.length,
height: 1,
expr: function (emit, i) {
emit(
vocab[i]
);
}
})
which I'd like to understand better. There are a lot of parameters (i, j, delta, time, t, x, y, to name a few) that are regularly passed as varargs to that applicative expr function even though they're not explicitly defined in the userspace. Where do they come from – are they scoped to the parent? Do all collections have an implicit index variable, or just certain types? Is there a specific API that describes these "implicit" properties of mathbox objects?