Array error
in
Programming Questions
•
20 days ago
Hi folks,
new to developping in Processing. Coming from full procedural environments, not quite used to OOP. Aaaaanyway.
I get an ArrayIndexOutOfBoundsException: 2 when interpreting this piece of code (sorry it's 91 lines long). The error occurs on line 57 as soon as I try to assign a value to a cell of the array:
new to developping in Processing. Coming from full procedural environments, not quite used to OOP. Aaaaanyway.
I get an ArrayIndexOutOfBoundsException: 2 when interpreting this piece of code (sorry it's 91 lines long). The error occurs on line 57 as soon as I try to assign a value to a cell of the array:
- // Declaring letter points matrix array
- float[][][] let_mtrx = new float[2][2][1];
- // General text angle
- float ngl = 33.333;
- // Letter dimensions
- float let_w = 64;
- float let_h = 96;
- // Finding the angles of the letter's diagonals afer ngl, let_w and let_h
- float let_ngl_1 = (atan(let_h/let_w))+ngl;
- float let_ngl_2 = (PI-let_ngl_1)+ngl;
- float let_ngl_3 = (PI+let_ngl_1)+ngl;
- float let_ngl_4 = (PI*2-let_ngl_1)+ngl;
- // Finding the angles of the letter's orthogonals afer ngl
- float let_ngl_ortho_1 = ngl;
- float let_ngl_ortho_2 = ngl+PI/2;
- float let_ngl_ortho_3 = ngl+PI;
- float let_ngl_ortho_4 = ngl+PI*1.5;
- // Finding the different lengths from center (horizontal, vertical and diagonal)
- float len_diag = (sqrt(sq(let_w)+sq(let_h)))/2;
- float len_w = let_w/2;
- float len_h = let_h/2;
- void setup() {
- size(displayWidth/2, displayHeight/2);
- background(0);
- stroke(255, 255, 255);
- strokeWeight(8.0);
- strokeCap(ROUND);
- }
- void draw() {
- findPoints(100, 100, let_w, let_h);
- point(let_mtrx[0][0][0], let_mtrx[0][0][1]);
- point(let_mtrx[1][0][0], let_mtrx[1][0][1]);
- point(let_mtrx[2][0][0], let_mtrx[2][0][1]);
- point(let_mtrx[0][1][0], let_mtrx[0][1][1]);
- point(let_mtrx[1][1][0], let_mtrx[1][1][1]);
- point(let_mtrx[2][1][0], let_mtrx[2][1][1]);
- point(let_mtrx[0][2][0], let_mtrx[0][2][1]);
- point(let_mtrx[1][2][0], let_mtrx[1][2][1]);
- point(let_mtrx[2][2][0], let_mtrx[2][2][1]);
- }
- // There are 9 points in the matrix
- // Each has two coords (X and Y)
- // The last dimension in the let_mtrx array designates coord X or Y for the specific point
- // For instance, the X of point 9 would be let_mtrx[2][2][0], the Y let_mtrx[2][2][1]
- // let_mtrx[0][0] is the top-left point, let_mtrx[2][2] is the bottom-right
- void findPoints(float f_letxc, float f_letyc, float f_letw, float f_leth) {
- // Point 9
- let_mtrx[2][2][0] = f_letxc+(cos(let_ngl_1)*len_diag);
- let_mtrx[2][2][1] = f_letyc+(sin(let_ngl_1)*len_diag);
- // Point 7
- let_mtrx[0][2][0] = f_letxc+(cos(let_ngl_2)*len_diag);
- let_mtrx[0][2][1] = f_letyc+(sin(let_ngl_2)*len_diag);
- // Point 1
- let_mtrx[0][0][0] = f_letxc+(cos(let_ngl_3)*len_diag);
- let_mtrx[0][0][1] = f_letyc+(sin(let_ngl_3)*len_diag);
- // Point 3
- let_mtrx[2][0][0] = f_letxc+(cos(let_ngl_4)*len_diag);
- let_mtrx[2][0][1] = f_letyc+(sin(let_ngl_4)*len_diag);
- // Point 6
- let_mtrx[2][1][0] = f_letxc+(cos(let_ngl_ortho_1)*len_w);
- let_mtrx[2][1][1] = f_letyc+(sin(let_ngl_ortho_1)*len_w);
- // Point 8
- let_mtrx[1][2][0] = f_letxc+(cos(let_ngl_ortho_2)*len_h);
- let_mtrx[1][2][1] = f_letyc+(sin(let_ngl_ortho_2)*len_h);
- // Point 4
- let_mtrx[0][1][0] = f_letxc+(cos(let_ngl_ortho_3)*len_w);
- let_mtrx[0][1][1] = f_letyc+(sin(let_ngl_ortho_3)*len_w);
- // Point 2
- let_mtrx[1][0][0] = f_letxc+(cos(let_ngl_ortho_4)*len_h);
- let_mtrx[1][0][1] = f_letyc+(sin(let_ngl_ortho_4)*len_h);
- // Point 5
- let_mtrx[1][1][0] = f_letxc;
- let_mtrx[1][1][1] = f_letyc;
- }
1