here is another data structure to represent
- an array that takes gray scales as an index and contains objects of type class ListOfPermuts
- In the class ListOfPermuts there is an ArrayList of the permutations for this brightness, stored as an ArrayList of type class Field
- The class Field is a field of 3x4. It can make the animation
Chrisir
// list uses gray scales as index. The list contains the different permuts for this gray scale (number of permuts can vary).
ListOfPermuts[] permuts = new ListOfPermuts[256];
void setup() {
size(1600, 800);
noSmooth();
// fill permuts
// i represents gray value
for (int i=0; i<256; i++) {
permuts[i] = new ListOfPermuts( i );
}//for
background(0);
// make the rects in the upper area
for (int i=0; i<100; i++) {
fill(random(255), random(255), random(255));
rect(i*32, 3,
30, 30);
}//for
//
}//setup
void draw() {
fill(0);
rect(0, 33,
width, height);
color c1 = get(mouseX, mouseY);
fill(255, 0, 0);
text("Please place the mouse on the rects to test different brightness values \nbrightness "
+ brightness(c1),
100, 100);
permuts[int(brightness(c1))].display();
//
} // func
//================================================================
class ListOfPermuts {
// class holds all permutations for ONE brighntness
// length can vary (therefore ArrayList)
ArrayList<Field> listOfPermutations = new ArrayList();
int brightnessOfField;
// counter or permut for display as an animation
int permutNum;
//constr
ListOfPermuts (int brightnessOfField_) {
brightnessOfField =
brightnessOfField_;
// random number of permuts for this brightness.....
// replace by something that gives the permuts for the brightnessOfField_
for (int i=0; i<random (1, 24); i++) {
Field f1 = new Field(brightnessOfField);
listOfPermutations.add(f1);
} //for
} // constr ---------
void display() {
int xoffset=330;
int yoffset=500;
// text
text("Brightness "
+brightnessOfField
+" has "
+listOfPermutations.size()
+" permutations (these are not real data but made up).",
xoffset, yoffset-33);
// make a horizontal list
for (Field f1 : listOfPermutations) {
f1.display(xoffset, yoffset);
xoffset+=40;
}//for
// Animation
Field f1 = listOfPermutations.get(permutNum%listOfPermutations.size());
f1.display(330, height-139);
permutNum++;
//
} // func
//
} //class
//================================================================
class Field {
// ONE 3x4 Field
boolean [][] field = new boolean [3][4];
//constr
Field (int brightnessOfField_) {
// replace by something that gives the permuts for the brightnessOfField_
for (int x = 0; x < field.length; x++) {
for (int y = 0; y < field[0].length; y++ ) {
field[x][y] = false;
if (random(100)>50)
field[x][y] = true;
}
}
}//constr ---------
void display( int xoffset, int yoffset) {
//
for (int x = 0; x < field.length; x++) {
for (int y = 0; y < field[0].length; y++ ) {
//
// noStroke();
stroke(255);
noFill();
fill(#F0F507); // Yellow
//rect( xoffset-1, yoffset-1,
// 10, 20);
noStroke();
fill(0);
if (field[x][y])
fill(255); // WHITE
rect(xoffset + x*5, yoffset + y*5,
4, 4);
}
}
}//func
//
}//class
//