We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I made a P3D planetary model that I'm trying to convert to JS. The first issue I came across was that createShape didn't seem to work, so I replaced instances like
sun = createShape(SPHERE, 100);
with sun = sphere(100);
This seems to get me a step further, though I don't exactly understand why (does this cause a problem with PShape?). However, when I run my code now my browser's inspector tells me "Uncaught TypeError: Cannot call method 'isVisible' of undefined". 'isVisible' appears here in the JS:
PShape.prototype = {
isVisible: function() {
return this.visible
},
setVisible: function(visible) {
this.visible = visible
},
Any idea what's going wrong here? Thank you!
Answers
According to its reference: http://processingjs.org/reference/sphere_/ , sphere() returns nothing!
Therefore, sun would be
undefined
after that assignment I believe! :@)Well,
undefined
isn't neither an object nor a function reference! Moreover, it's simply as nothing asnull
! :O)Pretty much, doing the above would place your code in JavaScript native territory rather than JS Mode! 8-|
You'd completely lose Java Mode compatibility along too! :-<
Hope it's just your browser's JS inspection and not your actual code! 8-X
Thanks for your reply! You've picked up on my deep confusion about this. Yes, the PShape.prototype bit was from my browser's inspector.
Here's my original code before the sphere() changes. Any idea why it's not displaying?
It showed this in the browser console:
uncaught exception: Processing.js: Unable to execute pjs sketch: ReferenceError: createShape is not defined
I believe createShape() is Processing 2+ exclusive. Processing/JS is still v1.4.1 and is very similar to Processing/Java v1.5.1.
I believe the Old v1 was only able to load ".svg" files, but not create 1 itself! :-&
Perhaps you should try to run your code under Processing 1.5.1, since it's much closer to ProcessingJS 1.4.1. (~~)
Ah, that's too bad. I just tried it in 1.5.1 and once I get rid of all the setFill() and setStroke()s that apparently didn't exist at the time I get the following error:
I take it that I won't get this to work in PJS either then?
P1.5.1 got 4 distinct renderers -> JAVA2D, P2D, P3D & OPENGL.
From those 4, only OPENGL uses OpenGL. To try that mode out, you gotta import it!