Execute [js] in order to see a program made with Processing.
Hi,
I made a 3D graphic that i would like to see in max msp.
Chat Gpt says to put the program below in [js] but it doesn't work.
Can anyone tell me the good process?
Here what chat gpt says:
"This code still uses the Processing programming language, so you need to run it in a [js] (Javascript) object in Max MSP. Simply copy the code below and paste it into a [js] object in Max MSP, then activate it to display the graph. Note that you may need to adjust some parameters according to your needs and the configuration of your Max MSP environment.
import peasy.*;
float cubeSize = 100; // Cube size
float domeRadius = cubeSize / 2; // Radius of the dome (adjusted to match the cube radius)
float domeThickness = 0.05 * domeRadius; // Thickness of the dome (5% of the radius)
int numSegments = 30; // Number of segments to draw the dome
int numSegmentsVertical = 10; // Number of vertical segments for the half-sphere
int numScreens = 12; // Number of screens
float screenGap = 10; // Space between screens
float curveAmount = 50; // Vault curvature
PeasyCam cam; // PeasyCam object declaration
void setup() {
size(800, 600, P3D);
cam = new PeasyCam(this, 500); // Initialize PeasyCam with a default distance
}
void draw() {
background(255);
// Draw the cube
stroke(0);
noFill();
pushMatrix();
translate(0, 0, -cubeSize*PI/2); // Center the cube
box(cubeSize);
popMatrix();
// Draw the dome (half-sphere)
drawDome();
// Place the screens on the dome
for (int i = 0; i < numScreens; i++) {
float theta = map(i, 0, numScreens-1, 0, TWO_PI); // Angle according to the number of screens
float x = cos(theta) * domeRadius;
float y = sin(theta) * domeRadius;
float z = curveAmount * cos(PI/2 * x / domeRadius); // Vault curvature
drawScreen(x, y, z);
}
}
void drawDome() {
rotateX(PI);
for (int j = 0; j <= numSegmentsVertical / 2; j++) { // Draw only half of the dome
beginShape(QUAD_STRIP);
for (int i = 0; i <= numSegments; i++) {
float theta = map(i, 0, numSegments, 0, TWO_PI);
float phi = map(j, 0, numSegmentsVertical / 2, -HALF_PI, 0);
// Calculate coordinates for the dome interior (half-sphere)
float innerX = (domeRadius - domeThickness) * cos(phi) * cos(theta);
float innerY = (domeRadius - domeThickness) * cos(phi) * sin(theta);
float innerZ = (domeRadius - domeThickness) * sin(phi+PI/2) + cubeSize/2; // Dome center aligned with cube center
// Calculate coordinates for the dome exterior (half-sphere)
float outerX = domeRadius * cos(phi) * cos(theta);
float outerY = domeRadius * cos(phi) * sin(theta);
float outerZ = domeRadius * sin(phi+PI/2) + cubeSize/2; // Dome center aligned with cube center
// Draw dome sides
vertex(innerX, innerY, innerZ);
vertex(outerX, outerY, outerZ);
}
endShape();
}
rotateX(-PI);
}
void drawScreen(float x, float y, float z) {
pushMatrix();
translate(x, y, z);
fill(100);
box(20, 10, 1); // Screen size
popMatrix();
}
Feel free to use this code in your Max MSP environment. Let me know if you need any further assistance!
Here the graphic made with Processing 4. You can see this when you change the perspective by moving the mouse with the mouse pressed.

Chat GPT is wrong. JS is not Processing. Two different languages.
Please, please, stop using chat GPT for Max coding. It has never given somewhat correct answer.
Processing.js use ES6 version of javascript. Max javascript engine still use a previous version. Even if you use an old enough version of Processing, you could not display anything as the processing library wouldn't know how to display stuff in the context of Max.
You are limited to use either one of the already existing js drawing API inside of Max (MGraphics, OpenGL, Sketch) instead of Processing, or use node for Max to create a modern js context (nodejs) that can be compatible with Processing.
Or you draw using one of the Jitter options.
Plus the code it has given is from the plain Java-version and not even from P5.JS lol
(c74 should run chat gpt for automatically answer questions including chat gpt references, here in that forum)
So, I am just curious why nothing is showing up when pasting a code generated by chatGPT? Aside from whether chatGPT can produce a properly functioning code, what is missing in the code that prevents it from pasting even one object? I tried it with a simple patch that is supposed to blink an LED at 1hz and nothing was pasted. Is there a procedure to modify the code generated by chatGPT to make it paste something, working or not?
You need a better understing of how chatGPT works. Please someone correct me if I'm wrong, but from my understanding, chatGPT basically just randomly write a word and choose the next one that seems the most appealing regarding what you are asking, and it repeats that process again and again. It just writes one word after the other without having a sense of its full answer. The algorithm is so well made and its training data so exhaustive that it makes you believe that it trully knows what it says, but it's just a side effect, kind of an illusion.
It doesn't work with Max because, just by looking at the text, Max compressed code has no semantic meaning and can hardly be related to what the patch is supposed to do. chatGPT knows what Max compresseds code looks like, because there is some on the internet, and it knows how to write something that look like it, but has no idea which sequence of character is supposed to create which object or which feature.
I assume it could theoritically work with uncompressed max code (which is JSON formatted), but there is very few example of JSON Max code on the internet, compared to the massive amount of C, python, js, html, you name it. If you could train your own prediction model with a big database of uncompressed Max patches with a lot explanation about how they work, you might get some result that could work without too much correction. But it would most certainly be faster to just learn Max instead.
if you want to know which languages a chatbot can "code", just ask it, and it will tell you.
the ones listed are the laguages they are specifically trained to.
languages not listed there are usually just garbled garbage.
The main issue with chatGPT and Max's JSON files is that the JSON code for a visual representation and the visual representation itself tells how data flows between objects. It's a two step process and requires to create a 2D representation of the objects and their interactions to understand the code.
It is different from written language which is essentially linear (1D). We can point to other parts of the content, but essentially proximity is the most important information to parse the data. And that's why an algorithm trained to be a very smart autocomplete can write sentences that seemingly make sense and code that almost works.
HTH