We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. I am working on a sketch based on the "Solar system generator" (video link below).
I modified the code such that it retrieves the number of moons and the appropriate image file from a .csv, and managed to get it working.
However, I have trouble embedding it to a html file. Below are the contents of the html and processing code. I also attached an image of the working directory.
Any pointers on what's going wrong is greatly appreciated. (I have a feeling it has something to do with the *@pjs preload command of the .pde ..., but not sure)
Many thanks in advance.
-----html code--------
<html>
<head>
<title> My first webpage</title>
<script src="Processing.js"></script>
</head>
<body>
Hello World!
<marquee> this is a test!</marquee>
<canvas data-processing-sources="solargenerator_sunrotate_ver6.pde planet.pde"></canvas>
</body>
</html>
-----sketch code solargenerator_sunrotate_ver6--------
import peasy.*;
Planet[] sun;
PeasyCam cam;
PImage sunTexture;
PImage[] textures = new PImage[3];
Table holidaytable;
int nrows;
void setup() {
size(900, 700, P3D);
Table holidaytable=loadTable("test.csv", "header");
textures[0] = loadImage("earth.jpg");
textures[1] = loadImage("cmb.jpg");
textures[2] = loadImage("sky.jpg");
cam = new PeasyCam(this, 1000);
int nrows =holidaytable.getRowCount();
sun = new Planet[nrows];
for (int i = 0; i < nrows; i++) {
TableRow row = holidaytable.getRow(i);
int ID = row.getInt("no");
int holiday = row.getInt("holidays");
String picture = row.getString("image");
sunTexture= loadImage(picture);
sun[i]= new Planet(50, 450, 0, true, ID, sunTexture);
sun[i].spawnMoons(holiday,1);
}
}
void draw() {
background(0);
lights();
for (Planet sun2 : sun) {
sun2.show();
sun2.orbit();
}
}
OS: windows 10 Processing version: 3.3.4
Answers
Do not use any libraries if you need your sketch to be transpiled into JS via Pjs. [-X
Also it's advisable to use
/* @pjs */
directives for images: L-)http://ProcessingJS.org/reference/pjs directive/
Thanks for the pointers. I did the following: 1. commented out lines 1, 5, and 21 (Peasy library related) 2. included the
/* @pjs */
directive/* @pjs preload="earth.jpg, cmb.jpg, sky.jpg, IMG_A.jpg, IMG_B.jpg, test.csv"; crisp="true"; */
However, I still cannot get the sketch to work on the test webpage.
Is there anything else I am doing incorrectly?
Much thanks.
Can you post your current sketch code? You can also host it here:
https://OpenProcessing.org/sketch/create
Select Mode Processing.js. And upload your images there too. O:-)
I uploaded my sketch to OpenProcessing. Obviously it doesn't work... :-S
Thank you for your time.
https://openprocessing.org/sketch/440364#
Just remembered it: Functions which arrived along w/ Processing 2 weren't converted to Pjs yet! #-o
Neither createShape() nor loadTable() are available in Pjs! :-S
You can use loadStrings() in place of loadTable():
http://ProcessingJS.org/reference/loadStrings_/
For createShape(), you may try out loadShape() and beginShape():
http://ProcessingJS.org/reference/loadShape_/
http://ProcessingJS.org/reference/beginShape_/
And for setTexture(), there's texture(): :\">
http://ProcessingJS.org/reference/texture_/
If everything fails, you still can convert your sketch to p5.js: #:-S
https://p5js.org/reference/
https://GitHub.com/processing/p5.js/wiki/Processing-transition