Processing 2.0 changed how pixels works?
in
Programming Questions
•
10 months ago
I tried running an old sketch I made in an earlier version of Processing and it doesn't work anymore. If I replace the line highlighted in red with:
- pixels[i+j*width] = color(steps);
Then it works, but it used to work how it is in the code below. What changed?
- float minThreshold = 0.0001;
- int maxDepth = 800;
- float angle = 0;
- void setup() {
- size(400, 300, P2D);
- //noLoop();
- }
- void draw() {
- float x = cos(angle+HALF_PI)*50;
- float z = sin(angle+HALF_PI)*50;
- background(0);
- loadPixels();
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < height; j++) {
- float dx = (float)i/width-0.5;
- float dy = ((float)j/height-0.5)*(float)height/width;
- float dz = 1.0;
- float normVec = 1.0/sqrt(dx*dx+dy*dy+dz*dz);
- dx *= normVec;
- dy *= normVec;
- dz *= normVec;
- float rayX = 0;
- float rayY = 0;
- float rayZ = 0;
- float rayLength = 0;
- int steps = 255;
- while (steps > 0 && rayLength < maxDepth) {
- // Rotation Y-axis
- float rotX = rayX*cos(angle)-rayZ*sin(angle);
- float rotZ = rayZ*cos(angle)+rayX*sin(angle);
- // Sphere
- float sphereDist = sqrt(sq(rayX)+sq(rayY)+sq(rayZ-50))-5;
- // Cube
- //float cubeDist = max(abs(rayX)-5, max(abs(rayY-10)-5, abs(rayZ-50)-5));
- float cubeDist = max(abs(rotX-x)-5, max(abs(rayY-10)-5, abs(rotZ-z)-5));
- // Torus
- //float q = sqrt(sq(rayX)+sq(rayY+10))-3.33;
- //float torusDist = sqrt(sq(q)+sq(rayZ-50))-1.67;
- float q = sqrt(sq(rotX-x)+sq(rayY+10))-3.33;
- float torusDist = sqrt(sq(q)+sq(rotZ-z))-1.67;
- float smallestDist = min(sphereDist, min(cubeDist, torusDist))*0.5;
- if (smallestDist < minThreshold) {
- pixels[i+j*width] = (steps<<16)+(steps<<8)+steps;
- break;
- }
- else {
- rayLength += smallestDist;
- rayX = dx*rayLength;
- rayY = dy*rayLength;
- rayZ = dz*rayLength;
- steps--;
- }
- }
- }
- }
- updatePixels();
- angle += TWO_PI/36;
- }
1