We are about to switch to a new forum software. Until then we have removed the registration on this forum.
ok, I know I talk a lot and I make no sense in my questions, but I need last question and I will try to be more clear. so, I've created a code which has 2 windows (multiple window) that I made with G4P library. In addition, I've tried to convert string to a code (it can be a method or whatever). And now here is my question: how Can I make the code which is converted from strings appear in the second window? For example: I write the string: "rect(100,100,100,100);" and I convert it to method (like usual), and I want this rect will be drawn on the multiple window. Here is my code (part of it):
Answers
I guess you're gonna need to put() another global variable into JS in order to represent your GWindow:
And create another customized eval() for it:
WARNING: Not tested yet! (:|
Please do not post the same question twice. I have deleted the duplicate.
After creating the window you must add a draw handler so after line 61 add
window.addDrawHandler(this, "windowDraw");
then modify your last function to
This should get you started :)
You might also look at this discussion for background info on multiple websites. Aloso my website gives more info.
Thank you both! I have 3 more questions: how do I eval strings to a function? Like:
How do I eval the setup and draw functions? That my question
And the second question-how can I eval the string "size(200,200)" for example and it will be control the size of the window?
And the last-when I wrote on the text area rect(100,100,100,100). And its works. But when I use mouseX,mouseY it doesn't work :( so how can I do it will work?
Processing doesn't allow us to re-issue size() unfortunately.
Most we can do is use the undocumented PSurface::setSize() method.
And we can call the undocumented function getSurface() in order to grab sketch's PSurface reference:
getSurface().setSize(300, 200);
Thank you! And how I can do with the setup and draw functions? (What I asked in the last comment)
It's not easy to fully reply those questions b/c it demands that you understand how the PDE (Processing's IDE) and its pre-processor hides/abstracts many things from us.
A sketch is basically the class PApplet methods modifying the canvas, which is a PGraphics object.
When we issue something like background() or rect(), we're actually modifying a PGraphics object, which at the end of draw() has its content finally rendered on sketch's PSurface.
The ScriptEngine is a clean slate, knowing nothing about PApplet or its PGraphics "canvas".
We need to transfer to ScriptEngine everything we intend to be accessed from it.
Most important thing is our sketch's PApplet reference:
js.put("p", this);
The statement above creates a global variable called p in JS and initialize it w/ sketch's
this
, which is a PApplet reference.That's exactly what we do w/ many other Processing's library. We pass
this
to them too.So they can also access sketch's canvas and other Processing's API.
Since variable p represents our sketch, we can finally use its members from JS.
For example, we can issue
p.background(0)
in order to fill sketch's canvas w/ black color from JS' ScriptEngine.I worte void setup(){ on line (in the text area after I compiled) and it showed me that try1=0. why? :((
Please format your code.
I tried but look it didn't work
I fixed your code. Make sure you have a blank line before and after the code, then select the code and hit Ctrl+O
try1 = 0 because it matches the first element in the array and tha is index value 0 i.e.
i == 0
the firstso how can I do that try1 will be the value of the line number?
Change line 75 to
try1 = i + 1;
but quark, it doesn't work if it is in line 2 or 3. it shows that try1=0; :(
I used
I put void setup(){ in the fourth line and I got the following output
for ever. So it worked for me
ok thanks! now I have last question (I think :-\" ) I added this to the function
<
pre> void windowDraw(PApplet app,GWinData data){ String lines[]= txa1.getTextAsArray(); for(int i=0; i<lines.length; i++){ if(lines[i].equals("void setup(){")==true) try1=i + 1; if(lines[i].equals("}")==true) try2=i + 1; println("setup"+try1); println("closeSet"+try2); } } and I wrote it on the text box and it showed that now try2 is 0! why? :( (please add a global int "try2" if you want to add this code).
someone: please edit and format my code because my computer decided to do problems about formating the code. X( thank you :)