I sped up your code a bit. The problem isn't slow serial communication, but a horrendously slow graphics loop. A few items to note.
1) framerate(100000) or framerate(infinity) or whatever is a waste of time. The frames will go as fast as the frames want to go. With this code, you'll be lucky to get the default value, so omit this line.
2) If you want to loop through and color every pixel, drawing a bunch of tiny rects is the slowest way to do it. It's much faster to use loadPixels(), then set the values in the pixel[] array (which are RGBA integers) and then call updatePixels(). This is the main thing change I made to your code. I also:
3) Changed your loops so instead of <= height it's < height, so it loops through legal values for i and j. Otherwise, you get array out of bounds. The addresses of your pixels go from 0 to width-1 and 0 to height-1.
4) Changed your blah value to an integer, so I can do integer math on it, to convert it to an RGBA value. To convert 3 integers, r,g,b to an RGBA value, I use
int clr = r | (g << 8) | (b << 16) | 0xFF000000;
The last bit (0xFF000000) is used to set the opacity (alpha).
5) noise() is also quite slow, when calculated for every pixel. You might do better to render the pixels to a smaller offscreen image (say 1/4 the size of your screen) and then blow it up by rendering it 2 to 1.
- /* THE OLD CODE
- for(int i=0; i<=height; i+=y) {
- for(int j=0; j<=width; j+=x) {
- float blah = (int) noise(xnoise, ynoise, znoise)*256;
- pixels[n++] = (blah) || blah
- fill(blah);
- rect(j, i, x,y);
- if(key=='c' || key == 'C') {
- fill(i, blah, j);
- rect(j, i, x,y);
- }
- xnoise += 0.09;
- }
- ynoise += 0.09;
- }
- znoise += 0.09;
- */
- // THE NEW CODE
loadPixels(); - int n = 0;
- for(int i=0; i< height; i+=y) {
- for(int j=0; j< width; j+=x) {
- int blah = (int) (noise(xnoise, ynoise, znoise)*256);
- if(key=='c' || key == 'C') {
- pixels[n] = (i) | (blah << 8) | (j << 16) | 0xFF000000;
- }
- else {
- pixels[n] = (blah) | (blah << 8) | (blah << 16) | 0xFF000000;
- }
- n++;
- xnoise += 0.09;
- }
- ynoise += 0.09;
- }
- znoise += 0.09;
- updatePixels();