Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlling interactive ink-elements with a function #10

Closed
J2thearo opened this issue Mar 29, 2020 · 5 comments
Closed

Controlling interactive ink-elements with a function #10

J2thearo opened this issue Mar 29, 2020 · 5 comments

Comments

@J2thearo
Copy link

Hi there,

this is really an impressive library! I have already tried a lot with it and wonder whether it is also possible to change the value of the ink-var with a javascript function. By that I mean, if for example you can control the slider (ink-range) from the outside with a function call instead of the mouse.

Regards,
Jaro

@rowanc1
Copy link
Member

rowanc1 commented Mar 29, 2020

Thanks for the praise @J2thearo! Glad it is helping out, always curious to see what people are making if you want to share!

I actually just ran into this yesterday, and am planning to make some improvements over the coming weeks.

Right now you can do this like (e.g. on the https://components.ink/ main page):

const inkVar = document.getElementsByTagName('ink-var')[1];
inkVar.value = 10;
inkVar.dispatch();

The syntax might change in the future, or adding a method to allow you dispatch without needing access to the html element. I will keep this thread updated!

@J2thearo
Copy link
Author

Thank you @rowanc1, that helped me a lot. I'm really looking forward to your planned improvements.

A friend and I work on interactive animations to visualize scientific and mathematical concepts. We are always on the lookout for suitable technologies to implement our projects. Ink.js is an awesome new asset for us! If you're curious, check out one of our animations: https://j2thearo.github.io/ (its a prototype, suggestions for improvement are welcome)

We are currently still working on our website. It should be similar to brilliant.org, but much more interactive and playful.

Regards,
Jaro

@rowanc1
Copy link
Member

rowanc1 commented Mar 30, 2020

So awesome. Nice to see the ink-equations and dynamic text in there. :) Glad ink could help out!

On my side I am currently working on https://iooxa.com, which I am hoping will expand the number of people who can create interactive explorations. Basically it is a WYSIWYG wrapper around ink-components with some collaboration and publishing sprinkled in.

park-admission

I will try and push on the refactor of ink in the coming month, and might explore some better p5 integrations. I will keep this thread and #11 updated.

@lrq3000
Copy link

lrq3000 commented Apr 6, 2020

@rowanc1 Very impressive! This editor will indeed be very useful to quickly prototype things with ink-components!

@rowanc1
Copy link
Member

rowanc1 commented Apr 29, 2020

This has been added to v0.2.4

See the release notes here: https://github.com/iooxa/article/releases/tag/v0.2.4

You can:

>> const v = iooxa.createVariable('scope.name', 3);
>> v.get();
3
>> v.set(null, '5 * 2');
10
...
iooxa.getVariableByName('scope.name');

The other ways to access through the component itself can be accessed through:

>> $0 = document.getElementById(...); // or select in editor!
>> $0.value
3
>> $0.valueFunction = '5 * 2'
'5 * 2' // Note that this is the *component*
>> $0.value
null // The value was set to null in the above statement
>> $0.$runtime.get()
10 // as expected!

You can also set the attribute of the component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants