subpixel
Re: Help with increasing speed & changing color SLOWLY
Reply #5 - Apr 28th , 2009, 11:33am
With regards to spheres in place of ellipses... Open your window with size(300, 900, P3D) or size(300, 900, OPENGL). Processing will complain if you have included the OPENGL library, which you can do by one of the menu options. The sphere(radius) function draws a sphere at the current "origin", that is, at (0,0,0). To "move" it away from the origin the trick is to move the origin using translate(). You'll then want to "put the origin back" so you don't lose track of where you are (translate() moves relative to the current state). eg pushMatrix(); // save the 3D state translate(xPosition[i], yPosition[i], zPosition[i]); sphere(sphereSize[i]); popMatrix(); // restore the 3D state If you don't want to use z positions, just use 0 for the z-coordinate. Another thing you might want to consider is a change in coordinates. Your program uses x values from 0 to width, y values from 0 to height. In "3D", it's not so easy to know the exact pixel coordinates (on the screen) for 3D coordinates, so it is often helpful to start off with your 3D coordinates centred on the screen and use coordinates from -something to +something, where you might need to experiment as to how big the something should be. To do this, just move the origin somewhere near the top of the draw() function (before you do any of your drawing). translate(width / 2, height / 2); // move the origin to the middle of the screen The coordinates of the screen are now something like... (-w/2, -h/2, 0) --- (0, -h/2, 0) --- (w/2, -h/2, 0) | | (-w/2, 0, 0) -------- (0, 0, 0) ----- (w/2, 0, 0) | | (-w/2, h/2, 0) ---- (0, h/2, 0) --- (w/2, h/2, 0) where w represents the width and h represents the height (and you have to excuse the dodgy text diagram!). Changing the z values from 0 will give the apparent effect of making things bigger or smaller relative to the centre of the screen (perspective). -spxl