|
Author |
Topic: Pixel array problems? (Read 301 times) |
|
rgovostes
|
Pixel array problems?
« on: Sep 9th, 2003, 9:45pm » |
|
I decided to rewrite my Vine code to use a pixel array, which I read is much faster than using getPixel() and setPixel(). After a bit of work, I came up with that which is below. However, when I run it, it produces a very strange result - the image is multiplied a couple times across the screen. Code:// Vine v2 (Sep 09 '03) // by Ryan Govostes int branchX[] = new int[1]; int branchY[] = new int[1]; BImage image; void setup() { size(320, 240); noBackground(); colorMode(RGB, 201); fill(0, 0, 0); rect(0, 0, width, height); branchX[0] = width / 2; branchY[0] = height / 2; } void loop() { int index; color c; image = new BImage(pixels, width, height, RGB); for(int i = 0; i < branchX.length; i ++) { index = (branchY[i] * image.height) + branchX[i]; c = image.pixels[index]; c = color(0, green(c) + 20, 0); image.pixels[index] = c; if (green(c) == 201 && branchX.length < 10) { newBranch(branchX[i], branchY[i]); } moveRandom(i); } System.arraycopy(image.pixels, 0, pixels, 0, pixels.length); } void moveRandom(int i) { int r = int(random(8)); if (r == 0 || r == 3 || r == 5) { branchX[i] = branchX[i] - 1; } // 012 if (r == 2 || r == 4 || r == 7) { branchX[i] = branchX[i] + 1; } // 3 4 if (r == 0 || r == 1 || r == 2) { branchY[i] = branchY[i] - 1; } // 567 if (r == 5 || r == 6 || r == 7) { branchY[i] = branchY[i] + 1; } branchX[i] = max(branchX[i], 0); branchX[i] = min(branchX[i], width - 1); branchY[i] = max(branchY[i], 0); branchY[i] = min(branchY[i], height - 1); } void newBranch(int newx, int newy) { int tempx[] = new int[branchX.length + 1]; int tempy[] = new int[branchY.length + 1]; System.arraycopy(branchX, 0, tempx, 0, branchX.length); System.arraycopy(branchY, 0, tempy, 0, branchY.length); tempx[branchX.length] = newx; tempy[branchY.length] = newy; branchX = tempx; branchY = tempy; print("Branch " + branchX.length + " added.\n"); } |
| The effect is pretty cool though, looks like some sort of satellite scan or something.
|
« Last Edit: Sep 9th, 2003, 9:48pm by rgovostes » |
|
|
|
|
|