 |
Author |
Topic: Completely new to programming--help on alphaArray (Read 306 times) |
|
dabomb
|
Completely new to programming--help on alphaArray
« on: Oct 31st, 2004, 10:26am » |
|
Hi Guys, Hope you guys can explain this to me, give me code, whatever. I'm trying to make a program that parses HTML and looks for specific anti-Bush or anti-Kerry phrases, and keeps tracks of this via counters. Each time a specific phrase is found, I want to have the image react, namely the alpha channel fading out. I've read the documentation about the alpha() function and understand I can load in a blue channel image, but I wanted to use the whole alphaArray thing since I want this to be somewhat dynamic. Anyway, I have no idea how to write this. I am really new to programming, so please forgive me, This is what I have, know so far.... void setup() { size (225, 300); alphaArray = new int[image.pixels.length]; BImage img = loadImage("bush.jpg"); image(bush, 0, 0); int[] alphaArray=(pixels.length * pixels.height); img.alpha(alphaArray); } I also understand you can make an array of the pixels by void setup() { size (225, 300); alphaArray = new int[image.pixels.length]; BImage img = loadImage("bush.jpg"); image(bush, 0, 0); int[] alphaArray=(pixels.length * pixels.height); img.alpha(alphaArray); } I have no idea how to write this, pretty much. I want the respective alpha values to be: [0] = 214; [1] = 171; [2] = 130; [3] = 89; [4] = 55; Anyway, can someone please help? Please email at david_2662@hotmail.com when you reply. I never know how often to check. Thanks!!!!
|
|
|
|
TomC
|
Re: Completely new to programming--help on alphaAr
« Reply #1 on: Oct 31st, 2004, 11:11am » |
|
You have the right idea to set the alphaChannel using an array, but I'm not sure why you only have 5 values in your example array. The array method is best used if you are obtaining the values from another data source, or you have a procedure to generate them. You won't want to be writing out 225*300 integers in your code! Can you break your problem into smaller pieces? Perhaps once you have some working code, or some errors you don't understand, you could ask again? The rest of this message might seem overly negative - don't be dis-heartened, it sounds like an interesting project you have there. But maybe it's a case of running before you can walk? The code snippets you posted there don't make much sense... It's hard to see if they would even compile (I don't think they could). In the first one: Code: void setup() { size (225, 300); // [1] alphaArray = new int[image.pixels.length]; // [2] BImage img = loadImage("bush.jpg"); // [3] image(bush, 0, 0); // [4] int[] alphaArray=(pixels.length * pixels.height); // [5] img.alpha(alphaArray); // [6] } |
| I read that to mean something like: Code: // 1. Set the size to 225x300. // 2. Set alphaArray to be an integer array of the same length as image.pixels // 3. Let img be a BImage, and let it refer to "bush.jpg". // 4. Draw the BImage called bush. // 5. Let alphaArray be an integer array, and set it to pixels.length * pixels.height. // 6. Set the alpha channel of img to the values in alphaArray. |
| That won't work for lots of reasons. 2. You need to declare alphaArray as an array of integers before you initialise it (or at the same time). There also isn't an object called image anywhere. 4. You don't have an image called bush (you called it img in 3). 5. You won't be able to declare alphaArray here if you already declared it above, and you can't initialise it to the product of 2 integers (pixels.length will be equal to width*height, pixels is an array and doesn't have height). Maybe try using some of the example code in the reference section and learning section until you better understand what's happening? (NB: If you're posting code, it's a good idea to mark it up with code tags in BBCode - ie like html but with square brackets)
|
|
|
|
|