We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
So my code was exported to an index.html using the JS Mode and the script runs in Mozilla. I know this because when I click on the script my test print statements println("Mouse True")
appear in the browser. However, the shapes and .svg's aren't displaying. It's just a black screen that when I click on it it says "Mouse True" in the browser.
Does anyone have the slightest clue as to what is going on? I could upload my code with generic svg paths if need be.
Thanks so much!
Answers
Does anyone have the slightest clue as to what is going on?
Processing.JS's framework is @ v1.4.1 (stable) & v1.4.8 (dev). And thus lacks latest Processing 2+ series API!
I believe it's only capable of loading ".svg" files, and can't create them on-the-fly:
http://processingjs.org/reference/PShape/
http://processingjs.org/reference/loadShape_/
Also make sure you're using
/* @pjs */
directives likepreload
:http://processingjs.org/reference/pjs directive/
http://processingjs.org/reference/preload/
Although I dunno whether loadShape() demands
preload
like loadImage() does! :-??http://processingjs.org/reference/loadImage_/
Yes, thank you for reiterating what I already knew.
All the .svgs were already preloaded and were created using
PShape
andloadShape
. The actual code isn't the problem- that runs outside of the browser perfectly. It's when it's in the browser is when the problems occur, like the graphics not showing up, but the code is compiling and running.By outside the browser you mean Java Mode, right?
By in the browser you mean JavaScript mode, is it?
Be aware that transpilation (https://en.wikipedia.org/wiki/Transpile) from Java to JS is prone to errors! :(|)
Yes sir to both of the questions. Alright I'll give you the example. Here is the
test.html
file that came with processing-js-1.4.8This works perfectly in both Chrome and Firefox. Now, if I add my simplified program instead of theirs:
Just the background shows up. There is supposed to be 2 arcs, that when clicked the inner one forms a circle and the outer one rotates. But in the browser, nothing, just the background.
Like I said before: "And thus lacks latest Processing 2+ series API!"
Function clear() is Processing 2: https://processing.org/reference/clear_.html
You won't find it in Processing.JS' reference page: http://processingjs.org/reference/ [-X
We gotta code in Java Mode as if we were still using the old Processing v.1.5.1 if we want it to transpile into JS!
Well shame on me, that was my mistake. Thank you kind man for your patience and your knowledge.
@GotoLoop: Have a look at http://processingjs.nihongoresources.com/vector/
And no, you don't need to preload SVG.
Also you can do things like this in PJS:
So if one can parse an SVG string, one can also build one.