We are about to switch to a new forum software. Until then we have removed the registration on this forum.
(In Processing) Can I convert a string to a code? For example: The user write on a text box "rect(100,100,20,50)". And the computer convert it to a line of code and on the screen the rect will be drawn. How can I do that?
Answers
maybe when you use p5 ....
https://forum.processing.org/two/discussions/tagged/p1?Tag=eval()
https://forum.Processing.org/two/discussion/13311/using-a-string-as-an-if-evaluation#Item_4
https://forum.Processing.org/two/discussion/7147/some-simple-pulse-equations-using-trig-#Item_8
GoToLoop Thank you! But I dont need boolean statement, I need a line of code! And methods :)
as I discussed with gotoloop in the other thread: gotoloop thinks put can do rectangles too
and he's right - see below
I posted an example based on the QScript example QSCriptIDE by @quark
the whole java / put is by @gotoloop
I killed most of the functionality of the QScript
but you can press "start" to get an rectangle or whatever
you can edit the sketch
you can write e.g.
OR with 2 lines
OR
and hit "start"
Lines
the important lines are 90 to 100
279 to 282
342 to 355
and I added line 334
remark
I am not sure though how to make a separate window where the rectangles are actually drawn
I would be happier if I could pass a String array (my array
code
) to@Chrisir, don't you think your code was a lil' too big for @Raz? :-\"
Anyways, here's my own attempt w/ lotsa tricks I've learnt today about Nashorn JS + P5: :-bd
Now's a more advanced version which includes CompiledScript for better script performance: ;;)
http://docs.Oracle.com/javase/8/docs/api/javax/script/Compilable.html
http://docs.Oracle.com/javase/8/docs/api/javax/script/CompiledScript.html