Loading...
Logo
Processing Forum
Hi list, I need to ad a pattern of points as background of my processing.js canvas.
I can do it with processing.js for example:

Copy code
  1.    for (int i=0;i< 32; i++){
  2.         for (int j=0;j< 56; j++){
              point(j * 30, i * 30 ) ;
        
            }
       }

The problem is that i need to do it inside draw{} and it consumes a lot of cpu, so i was wondering that instead of doing it with code , using a pic with my point pattern as background in my processing.js canvas.


which should be the best approach for this?



S.

Replies(3)

You actually draw a simple rectangle with the code you show...
That said, in classical Processing, using loadPixels() / pixels[] / updatePixels() is generally faster than using point() calls.
And, yes, if the pattern doesn't change, using an image is much more efficient.
Hi philo, and how can i create the same rectangle of points but using loadPioxels and updatePixels?

this:

Copy code
  1.    for (int i=0;i< 32; i++){
  2.         for (int j=0;j< 56; j++){
              point(j * 30, i * 30 ) ;
        
            }
       }
Something like:
Copy code
  1.    loadPixels();
  2.    for (int i = 0; i < 32; i++) {
  3.         for (int j = 0; j < 56; j++) {
  4.           pixels[(j * 30) * 32 + i * 30] = c;
  5.         }
  6.    }
  7.    updatePixels();
where c is the color you want to set.