Unexpected Token [ when using Arrays
in
Programming Questions
•
7 months ago
Hi all-
I'm writing a program that puts new instances of a class into an array. As far as I can tell, my syntax are correct, but I'm getting an unexpected token error on line 2. The main body of the program is copied below, with the class definition below it.
Thank you in advance for any help!
I'm writing a program that puts new instances of a class into an array. As far as I can tell, my syntax are correct, but I'm getting an unexpected token error on line 2. The main body of the program is copied below, with the class definition below it.
Thank you in advance for any help!
Main Program:
Grid[] grids = new Grid[2];
grids[0] = new Grid (color (244, 50, 63));
grids[1] = new Grid(color (237, 7, 184));
void setup () {
size (500, 500);
background (255);
grid [1];
grid [0];
}
void draw () {
gridtwo.drawGridbottomright ();
gridone.drawGridbottomleft ();
gridone.drawGridtopright ();
gridtwo.drawGridtopleft ();
}
Class
class Grid {
color strokecolor;
Grid (color tempstrokecolor) {
strokecolor = tempstrokecolor;
}
void drawGridtopleft () {
int counterX, counterY, counter1, counter2, counter3, counter4;
for (counterX = 0 ; counterX < width/2; counterX = counterX + 50)
{
for (counterY = 0 ; counterY < height/2 ; counterY = counterY + 50)
{
for (counter1 = 50 ; counter1 > 0 ; counter1 = counter1 - 3)
{
stroke (strokecolor);
rect (counterX, counterY, counter1, counter1); // bottomright
}
for (counter2 = 50 ; counter2 > 0; counter2 = counter2 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter2, counter2*-1);
}
for (counter3 = 50 ; counter3 > 0; counter3 = counter3 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter3*-1, counter3*-1);
}
for (counter4 = 50 ; counter4 > 0; counter4 = counter4 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter4*-1, counter4);
}
}
}
}
void drawGridtopright ( ) {
int counterX, counterY, counter1, counter2, counter3, counter4;
for (counterX = 0 ; counterX < width; counterX = counterX + 50)
{
for (counterY = 0 ; counterY < height/2 ; counterY = counterY + 50)
{
for (counter1 = 50 ; counter1 > 0 ; counter1 = counter1 - 3)
{
stroke (strokecolor);
rect (counterX, counterY, counter1, counter1); // bottomright
}
for (counter2 = 50 ; counter2 > 0; counter2 = counter2 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter2, counter2*-1);
}
for (counter3 = 50 ; counter3 > 0; counter3 = counter3 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter3*-1, counter3*-1);
}
for (counter4 = 50 ; counter4 > 0; counter4 = counter4 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter4*-1, counter4);
}
}
}
}
void drawGridbottomleft () {
int counterX, counterY, counter1, counter2, counter3, counter4;
for (counterX = 0 ; counterX < width/2; counterX = counterX + 50)
{
for (counterY = 0 ; counterY < height ; counterY = counterY + 50)
{
for (counter1 = 50 ; counter1 > 0 ; counter1 = counter1 - 3)
{
stroke (strokecolor);
rect (counterX, counterY, counter1, counter1); // bottomright
}
for (counter2 = 50 ; counter2 > 0; counter2 = counter2 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter2, counter2*-1);
}
for (counter3 = 50 ; counter3 > 0; counter3 = counter3 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter3*-1, counter3*-1);
}
for (counter4 = 50 ; counter4 > 0; counter4 = counter4 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter4*-1, counter4);
}
}
}
}
void drawGridbottomright ( ) {
int counterX, counterY, counter1, counter2, counter3, counter4;
for (counterX = 0 ; counterX < width; counterX = counterX + 50)
{
for (counterY = 0 ; counterY < height ; counterY = counterY + 50)
{
for (counter1 = 50 ; counter1 > 0 ; counter1 = counter1 - 3)
{
stroke (strokecolor);
rect (counterX, counterY, counter1, counter1); // bottomright
}
for (counter2 = 50 ; counter2 > 0; counter2 = counter2 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter2, counter2*-1);
}
for (counter3 = 50 ; counter3 > 0; counter3 = counter3 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter3*-1, counter3*-1);
}
for (counter4 = 50 ; counter4 > 0; counter4 = counter4 -3)
{
stroke (strokecolor);
rect (counterX, counterY, counter4*-1, counter4);
}
}
}
}
}
1