Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : P2D and set() behave strange

$
0
0
I can reproduce your problem with 2.0b7 so it seems there is indeed something buggy with P2D/P3D and the set() method. However using the pixel array directly is better anyway when setting large amounts of pixels. When you adapt the code to use the pixel array, there are no problems with P2D/P3D. Note that line 13 in your original code does nothing because you declare another local color c, besides it's not needed because the id starts as 0. Calculating the ix, iy and total number of pixels isn't needed either. The first two not, because you can use the index directly in the pixel array. The last because this is already a calculated number that you can get with pixels.length. See the adapted code below.

Adapted Code
  1. int sz = 512;
  2. int n = 1000;
  3. int npoints;
  4. color c;
  5.  
  6. void setup() {
  7.   size(sz, sz, P2D);
  8.   background(255);
  9. }
  10.  
  11. void draw() {
  12.   loadPixels();
  13.   for (int i=0;i<n; i++) {
  14.     int id = npoints % pixels.length;
  15.     if (id==0) { c = color(random(255), random(255), random(255)); }
  16.     pixels[id] = c;
  17.     npoints++;
  18.   }
  19.   updatePixels();
  20. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles