We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I am following Pomax's guide to Processing.js and there is a great example to have the user types text in the webpage and it displays that text in the Processing sketch. I've got it working however I'm stuck when it comes to having anything other than a static sketch, no animation.
If you let the draw command loop it over writes the text in the next frame, is there a way to layer the sketch or have the text always at the top above the animation which refreshes every frame with the background(); ? I've been applying this example to test. How I am looking for it to operate is the user types in some text through the web page and as you move your mouse around the the size of the circles hide or reveal the text.
Answers
Yes; draw the text last.
So, every
draw()
frame:fill()
with backgroundtext()
on topThe trouble I'm finding on my end is the method described by Pomax only runs the 'draw' when the user enters the text in the web browser. If I add the array into this draw then it only runs for one frame when the user 'enters' the text. This is the code I'm running.
If run this through Processing with the text(); command yes it does work fine but using Pomax's method, see "making javascript see your sketch" it works slightly differently.
What might be a good way to get around this?
This is the html code:
Are you drawing the text last in that processing sketch, like I told you? It doesn't look like it. It looks like you draw the background, then the text, then draw ellipses on top.
However, I have not tested this in Processing JS -- so I don't know how your continuous run problem differs from running in Processing. Maybe try adapting a different example with continuous animation, and adding the button with onclick to that. Maybe somebody else with more JS experience will have another idea about how to help you.
I've updated the code to the below now. I've added different fills to make the text clearer too but on my test site you can see the effect this is having. Even though the text function is in the draw() it only refreshes when you click the 'place' button.
http://ProcessingJS.org/reference/draw_/
http://ProcessingJS.org/reference/
Thanks for the steer @GoToLoop, I've downloaded version 3.1.2 and installed Javascript mode to export the following sketch. I have uploaded the html to my test website and it runs but I can't get the text to show, at least for more than one frame still. I think what's missing is to do with the variable, in the Processing sketch I'm calling a String variable 't', but I think I'm missing the proper command in html to reference it? So I can push the value back to the sketch.
Sketch code: float max_distance; float factor = 20; String t; //this is the variable I want the website textfield to reference / push
Function from Pomax's guide(inserted into html code):
Is it the
Processing.getInstanceById(id);
line which I need to change? Or am I getting confused with Pomax's guide and it's actually much more simple when in Javascript mode?Thanks again for any help!