Using hyperlinks to trigger Processing events, an example. Thoughts?
in
Integration and Hardware
•
1 year ago
I'm building a graph visualisation for teaching/learning about time series, and have been looking for a way to allow a learner/user to click on html links and immediately see the result I want in the applet window. Aside from actually building a text and link system into the visualisation itself, I've been playing with posting data to the URL and, on reload, using the getDocumentBase() method to grab that info.
Here is the example I just knocked together on top of an old sketch, with three html links reloading the page and telling the sketch to rotate in different ways. Of course, using keys within Processing is better for this example (you can use arrow keys and A+S to rotate, in this case). All I wanted to do here was proof of concept: posting data to the URL and catching it in Java on the reload. I used two java URL methods to parse the URL itself: getQuery() and getRef(). They just pluck out the text after "?" and "#", so that's a convenient way to set a particular variable. The code is linked to: the only odd thing there is the try-catch block so it can be run as a non-browser sketch.
For the tool I'm working on, that should allow a user to click a link, and I can use that to set up the graph data and view in exactly the right way for the particular point I'm trying to get across, without having to ask them to set it up themselves via the Processing window.
So, firstly: did it load at all? I'm worried it's being temperamental on my machine. It seems to be working, but it also seemed to be doing some slightly odd things...
Secondly, are the links working? They work for me, but if the Processing project was too large, long reload times could be a pain.
Thirdly, has anyone else got ideas on how to do this better? Either some other really obvious method of feeding info to the Applet I've missed, or - well, I guess the alternative is just to have a series of numbered links in the Processing sketch itself and ask people to click each when they're at that particular point.
Thoughts gratefully received! Cheers...
Here is the example I just knocked together on top of an old sketch, with three html links reloading the page and telling the sketch to rotate in different ways. Of course, using keys within Processing is better for this example (you can use arrow keys and A+S to rotate, in this case). All I wanted to do here was proof of concept: posting data to the URL and catching it in Java on the reload. I used two java URL methods to parse the URL itself: getQuery() and getRef(). They just pluck out the text after "?" and "#", so that's a convenient way to set a particular variable. The code is linked to: the only odd thing there is the try-catch block so it can be run as a non-browser sketch.
For the tool I'm working on, that should allow a user to click a link, and I can use that to set up the graph data and view in exactly the right way for the particular point I'm trying to get across, without having to ask them to set it up themselves via the Processing window.
So, firstly: did it load at all? I'm worried it's being temperamental on my machine. It seems to be working, but it also seemed to be doing some slightly odd things...
Secondly, are the links working? They work for me, but if the Processing project was too large, long reload times could be a pain.
Thirdly, has anyone else got ideas on how to do this better? Either some other really obvious method of feeding info to the Applet I've missed, or - well, I guess the alternative is just to have a series of numbered links in the Processing sketch itself and ask people to click each when they're at that particular point.
Thoughts gratefully received! Cheers...
1