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.
Page Index Toggle Pages: 1
Mode array? (Read 1048 times)
Mode array?
Nov 21st, 2009, 1:00pm
 
I want to make a image mode array to pick randomly from an image filter mode (BLEND, SCREEN, MULTIPLY, etc.....) but I don't know what datatype to make that array. I tried a string array , but the image transform won't accept the string as a parameter. Any ideas?

Also- is there an easier way to turn down the alpha of an image (rather than screen?) Thanks.
Re: Mode array?
Reply #1 - Nov 21st, 2009, 1:20pm
 
You can not put them in an array. so i would do it with a switch http://processing.org/reference/switch_.html

so you create a random number, lets say

int num = (int)random(5);

switch(num) {
 case 0:
   filter(GRAY);
   break;
 case 1:
  filter(BLEND) ...
...
Re: Mode array?
Reply #2 - Nov 21st, 2009, 7:26pm
 
The method Cedric showed is probably best, but if you really wanted to use an array you should be able to use an array of ints.  BLEND, SCREEN, MULTIPLY, etc. are all PApplet integer constants.
Re: Mode array?
Reply #3 - Nov 21st, 2009, 8:13pm
 
Thx. but i am just curious. What do you mean and how would you do it.
Re: Mode array?
Reply #4 - Nov 21st, 2009, 9:28pm
 
Sure.  Here's a link showing all of the Processing constants:

http://dev.processing.org/reference/core/javadoc/processing/core/PConstants.html

The constants used in the filter method are all of the type "static final int" (as opposed to the newer Java enum types).  Here's the (developer) documentation for PApplet.filter():

http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html#fi...

It shows that filter() just takes an int as the first parameter: "public void filter(int kind)" or "public void filter(int kind, float param)".  When you pass "MULTIPLY" to filter(), for example, you're just passing it a predefined integer.

If you wanted to make an array containing the different integers that correspond to the filter modes, you just use an array of integers:

Code:
int[] modes = new int[8];
modes[0] = THRESHOLD;
modes[1] = GRAY;
modes[2] = INVERT;
modes[3] = POSTERIZE;
modes[4] = BLUR;
modes[5] = OPAQUE;
modes[6] = ERODE;
modes[7] = DILATE;

int randomIndex = int(random(0, modes.length));
int randomMode = modes[randomIndex];


You can then use "randomMode" as the first argument when you call filter().

I still think your solution is better, because it's likely that you'd want to pass filter() a different second argument ("level") depending on which mode is randomly chosen.  It's easier to do that with a switch statement.
Re: Mode array?
Reply #5 - Nov 21st, 2009, 10:10pm
 
Thank you for your explanation. Its still good to know. This was new to me and we didnt had this solution when we discussed the same question in another threat  earlier.
Re: Mode array?
Reply #6 - Nov 22nd, 2009, 1:00am
 
brewthom11 wrote on Nov 21st, 2009, 1:00pm:
is there an easier way to turn down the alpha of an image (rather than screen)

Whatever you do on the screen, in general it can be done on a PGraphics, ie. on an image.
Beside looping on pixels[] array to alter the alpha, apparently you can use tint() to do that too.
Re: Mode array?
Reply #7 - Nov 22nd, 2009, 3:56pm
 
THANKS to ALL replies. EXTREMELY helpful. I'll use the switch! Cheesy
Page Index Toggle Pages: 1