We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've been trying to export my code from Processing 3 into Processing 2 for quite a while now. I think I finally managed to make it work and all. I can't embed it into an HTML blog page. I've tried several methods. I tried to simply pull it in through
<script type="text/javascript" src=""></script>
And the page accepts the code but nothing happens. Perhaps I don't understand how to correctly reference it. The code has a dropbox URL that I'm trying to plug in.
I've tried directly inputting js code inbetween the
<script>
tags. Didn't work either. Here is the code. It works fine by itself.
<script>
static final int NUM_X = 15, NUM_Y = 15, NUM_Z = 15;
int x, z, y;
float xPos, yPos, zPos;
float r_x, r_y;
float hh;
void setup() {
size(400, 400, P3D);
colorMode(HSB, 360, 100, 100);
background(0);
}
void draw() {
camera(-200, -200, 200, 0, 0, 0, 0, 1, 0);
float h = hh += .8;
for (x = 0; x < NUM_X; x++)
for (z = 0; z < NUM_Z; z++)
for (y = 0; y < NUM_Y; y++) {
xPos = x * 20;
yPos = y * 20;
zPos = z * -20;
fill(h = (h + .361) % 360, 100, 100);
pushMatrix();
translate(xPos, yPos, zPos);
rotateY(r_y += 2e-5);
rotateX(r_x += 2e-5);
box(10);
popMatrix();
}
}
<script>
Thanks
Answers
Before deploying, you should 1st checks whether the transpilation from Java to JS was successful:
http://www.OpenProcessing.org/sketch/create
Afterwards, you can find some instructions about web deploying here:
http://ProcessingJS.org/articles/p5QuickStart.html
If you got JavaScript Mode installed, just follow the generated ".html" file. *-:)
It all works separately. The HTML files that was generated works by itself. The js code works fine in both processing and the online version that you linked as well as the HTML generated page. However once I try to copy that HTML code and put it on my blog page it stops displaying the animation. The page with all the written stuff like: "created with processing" appears. But not the animation itself. My assumption is that in this line
it tries to pull the .pde file from my computer. When I replace the source "" with a URL nothing changes. What am I doing wrong.
For errors like this, your first stop should be the JavaScript console. Navigate to your page (the one that's not working correctly) and then press F12, then go to the JavaScript console tab. You might have to refresh.
Here you'll see any errors you're encountering. My guess is that there's an error with loading JavaScript from different domains, or that you aren't actually running a server. (Does the url start with
file:
? If so you aren't running a server.)Is "Cube_of_cubes_2_0_mode.pde" in the same folder as your posted ".html" file?
Are you closing your 2
<div>
tags as well? Sorry dunno what else could be wrong there. :-<To answer everything. My .pde file is located on a dropbox server so it's not local. The URL is that of a dropbox.
https://www.dropbox.com/home?preview=Cube_of_cubes_2_0_mode.pde
I don't have an HTML in the same folder because I just opened that generated HTML file with a script reader and pulled the code out and pasted it into my page. Then I referenced the URL.
Here's the code
This is the other way I tried solving the problem. Instead of referencing it I tired to input the code in. Doesn't work either. This one almost works. The page recognizes processing code and sets the size of the window. However it just leaves it black. But I feel like this is a closer shot.
That sketch doesn't even compile in Processing's IDE (PDE)!
Why don't you paste my version from your other post instead or some other compilable version?
I currently feel like a complete retard which saddens me a lot but everything works. There was indeed a problem with my code. I created an extra variable that I haven't referenced. Everything is embedded and works! Thank you very much for all the extensive help! The direct embedding of the js code worked once I fixed the issue with the code.
Glad you've made it. Don't forget we can see the execution logs by hitting F12 in our browsers! ~O)
Like I said in a previous post:
For errors like this, your first stop should be the JavaScript console. Navigate to your page (the one that's not working correctly) and then press F12, then go to the JavaScript console tab. You might have to refresh.
Glad you got it figured out though.