We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My script runs just fine in Processing under the JavaScript mode. But when I Export for Web, the index HTML doesn't work. The web page opens without error and I can see the header and footer stuff that is standard. But the script is just blank. I even tried it with processing.js sample code (below) and the same thing. What am I missing? Is there a setting in processing or something?
Sample code:
/**
PROCESSINGJS.COM - BASIC EXAMPLE
Delayed Mouse Tracking
MIT License - Hyper-Metrix.com/F1LT3R
Native Processing compatible
*/
// Global variables
float radius = 50.0;
int X, Y;
int nX, nY;
int delay = 16;
// Setup the Processing Canvas
void setup(){
size( 200, 200 );
strokeWeight( 10 );
frameRate( 15 );
X = width / 2;
Y = width / 2;
nX = X;
nY = Y;
}
// Main draw loop
void draw(){
radius = radius + sin( frameCount / 4 );
// Track circle to new destination
X+=(nX-X)/delay;
Y+=(nY-Y)/delay;
// Fill canvas grey
background( 100 );
// Set fill-color to blue
fill( 0, 121, 184 );
// Set stroke-color white
stroke(255);
// Draw circle
ellipse( X, Y, radius, radius );
}
// Set circle's next destination
void mouseMoved(){
nX = mouseX;
nY = mouseY;
}
Answers
Have you tried with another browser? (You don't tell which one you used, BTW.)
Some browsers don't want to run a JS script from the file system, so you can allow such run, you can change for another browser, or you upload the sketch on a Web server (can be local to your computer!).
Nowadays, only Firefox and derivative browsers directly allow JS & plugins from ".html" files w/o a server.
Some other browsers may allow it as well if you are able to find & disable the corresponding protection option.
I am using IE10. The above code works when I open http://processingjs.org/learning/ But when I try to export the code it doesn't. The HTML produced by processing looks like this. I am assuming it is standard.
Dunno why you didn't understand my answer! Gonna re-phrase it below:
If you wanna use a non-Firefox browser, you gotta run the ".html" file via a server!
P.S.: When posting a code text, highlight it and hit CTRL+K in order to format it for the forum!
In other words: if you double-click on an HTML file (like the one exported) and if it opens in your default browser, it will have an URL like file://
As said, most browsers will deactivate the JavaScript in such file. In IE, you might have to lower the security or something similar to get it to work (unless it asks you if you want to activate it).
The alternative is to upload the file(s) to a real Web server (after all, that's the final purpose of such export, no?). Or to run a server on your computer, something like Wamp for example. Then you can load it with an http://localhost address.
"JS Mode" already creates a local server and opens up the default browser!
Besides WAMP, I've heard it's pretty easy to get a local server via http://NodeJS.org/ too!
But i believe it's more practical to simply post your code at some Processing host site:
http://studio.sketchpad.cc/sp/pad/newsketch
http://openprocessing.org/sketch/create
Or do some tests here:
http://processingjs.org/tools/processing-helper.html
Thank you