minkPixel
YaBB Newbies
Offline
Posts: 1
Array lists and voids
Jun 8th , 2009, 9:01am
Hi, I wanted to create an array with a random call of void functions. However I get the error of can't convert void to ArrayList. I have tried reading up on array's but I'm still not sure how to execute this?? Any help would be greatly appreciated. After initially struggling with the basics, i'm just starting to get to grips with Processing and having fun with it! What is meant to happen is when Brightest Pixel enters the rectangle, a random effect is applied to the video. import processing.video.*; Capture video; ArrayList[] effects; int x,y,m,n,imageWidth,imageHeight,size2,size3,ranEffect; void setup() { size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height, 30); noStroke(); smooth(); x = width/2; y = height/2; imageWidth = width/2; imageHeight = height/2; size2 = 100; rectMode(CENTER); effects = new ArrayList [7]; effects[0] = tint(0, 153, 204); effects[1] = copy(brightestX,brightestY,imageWidth,imageHeight,brightestX,brightestY,width,he ight); effects[2] = filter(INVERT); effects[3] = filter(BLUR,4); effects[4] = filter(ERODE); effects[5] = filter(GRAY); effects[6] = filter(POSTERIZE,4); } void draw() { if (video.available()) { video.read(); translate(width, 0); //from Petra's 'how to mirror your cam' scale(-1, 1); image(video, 0, 0, width,height); // Draw the webcam video onto the screen int brightestX = 0; // X-coordinate of the brightest video pixel int brightestY = 0; // Y-coordinate of the brightest video pixel float brightestValue = 0; // Brightness of the brightest video pixel // Search for the brightest pixel: For each row of pixels in the video image and // for each pixel in the yth row, compute each pixel's index in the video video.loadPixels(); int index = 0; for (int y = 0; y < video.height; y++) { for (int x = 0; x < video.width; x++) { // Get the color stored in the pixel int pixelValue = video.pixels[index]; // Determine the brightness of the pixel float pixelBrightness = brightness(pixelValue); // If that value is brighter than any previous, then store the // brightness of that pixel, as well as its (x,y) location if (pixelBrightness > brightestValue) { brightestValue = pixelBrightness; brightestY = y; brightestX = x; } index++; } } fill(0,0,0,0);//makes rect invisible rect(x,y,imageWidth,imageHeight); if(brightestX-size2/2 < x+imageWidth/2 && brightestX+size2/2 > x-imageWidth/2 && brightestY+size2/2 > y-imageHeight/2 && brightestY-size2/2 < y+imageHeight/2) { fill(0,255,0); ranEffect = int(random(7)); ArrayList currEffect = effect[ranEffect]; currEffect.disableStyle(); }else{ fill(255,0,0); noTint(); } rect(brightestX,brightestY,100,100); } }