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 › store info in a two-dimensional array
Page Index Toggle Pages: 1
store info in a two-dimensional array (Read 499 times)
store info in a two-dimensional array
Mar 29th, 2009, 6:51am
 
In the processing book there is a example of a two dimensional array,
Only in the peace of code it get's declared, created and assigned in 1 line:

int[][] points = { {50,18}, {61, 37}, {83, 43}};

I'm wondering if it's possible to have something like this:

int[][] points; //declare
points = new int[img.width][img.height]; //create

And now my problem how can assign multiple values to that array?
points[4][12] = {255, 180, 100}; //doesnt work like some other things I tried
Re: store info in a two-dimensional array
Reply #1 - Mar 29th, 2009, 10:31am
 
clankill3r wrote on Mar 29th, 2009, 6:51am:
I'm wondering if it's possible

Just try!  Wink (I suppose you have, already, since you ask the next question.)

First, I don't see how you can assign three values to an int.
Second, the { 1, 2, 3 } syntax is usable only at declaration time.
I think you want to do:

points[4][12] = 255;
points[4][13] = 180;
points[4][14] = 100;

or something similar.
Re: store info in a two-dimensional array
Reply #2 - Mar 29th, 2009, 11:27am
 
I want to store the rgb values that's why.
so [4][12] = the x and y coardinate and then I want to assign the rgb.
That's why I wanted [4][12] = 255, 180, 100

So maybe I must make a imageColorRed, imageColorGreen and imageColorBlue array.

Code:

PImage img;

color[][] imageColors;

void setup(){
size(50, 100);
img = loadImage("D:/_PhiLhoSoft/Processing/earth.png");
noLoop();
imageColors = new color[img.width][img.height];
for (int y = 0; y < img.height; y++) {
for (int x = 0; x < img.width; x++) {
imageColors[x][y] = img.get(x, y);
}
}
println(imageColors);
DumpColors();
}

void DumpColors()
{
for (int y = 0; y < img.height; y++) {
for (int x = 0; x < img.width; x++) {
println("x=" + x + " y=" + y + " : " + hex(imageColors[x][y]));
}
}
}

Page Index Toggle Pages: 1