We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Array lists and voids
Page Index Toggle Pages: 1
Array lists and voids (Read 207 times)
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);

 }
 
}




Re: Array lists and voids
Reply #1 - Jun 8th, 2009, 9:15am
 
Ouch, what a salad! Wink
You are mixing up arrays and ArrayLists (different beast although related), you are trying to put function calls in variables, hoping they will remain callable function definitions, ...

In short, you just cannot do that! (in Java).

You have to define a class for each effect, each class having a method to call that will apply the effect. It is better that each class implements an interface defining the function to call.

I made something not so far of what you are trying to do: Re: searching arraylist. Hopefully it might inspire you.
Page Index Toggle Pages: 1