Arrays and error messages, assistance woul be appreciated
in
Programming Questions
•
11 months ago
Greetings;
Working on an assignment and seem to have hit a roadblock. The following code draws a number of triangles in hexagon shapes and are supposed to fade out randomly.
However, I am getting the error message: Syntax error, insert "AssignmentOperator Expression" to complete Expression
with relation to line 18 of the second tab. If I comment this line out one of my hexagons will display and run properly.
Suggestions?
Working on an assignment and seem to have hit a roadblock. The following code draws a number of triangles in hexagon shapes and are supposed to fade out randomly.
However, I am getting the error message: Syntax error, insert "AssignmentOperator Expression" to complete Expression
with relation to line 18 of the second tab. If I comment this line out one of my hexagons will display and run properly.
Suggestions?
Hexagon[] hs = {
new Hexagon(175, 150),
new Hexagon(175, 50),
new Hexagon(250, 100),
new Hexagon(325, 50),
new Hexagon(325, 150),
new Hexagon(250, 200),
new Hexagon(175, 250),
new Hexagon(250, 300),
new Hexagon(325, 250),
new Hexagon(325, 350),
new Hexagon(175, 350),
new Hexagon(100, 100),
new Hexagon(100, 200),
new Hexagon(100, 300),
new Hexagon(250, 100)
};
void setup(){
size (400, 400);
background(255);
noStroke();
}
void draw(){
for(int i = 0; i < hs.length; i++){
hs[i].update();
hs[i].display();
}
}- class Hexagon {
int x;
int y;
float[] opacities = {
random(50, 300),
random(50, 300),
random(50, 300),
random(50, 300),
random(50, 300),
random(50, 300)
};
Hexagon(int x, int y) {
this.x = x;
this.y = y;
opacities[i];
}
void display() {
background(255);
fill(255, 0, 0, opacities[0]);
triangle(x+25, y-50, x-25, y-50, x, y);
fill(255, 0, 0, opacities[1]);
triangle(x, y, x+25, y-50, x+50, y);
fill(255, 0, 0, opacities[2]);
triangle(x, y, x+50, y, x+25, y +50);
fill(255, 0, 0, opacities[3]);
triangle(x, y, x+25, y+50, x-25, y+50);
fill(255, 0, 0, opacities[4]);
triangle(x, y, x-25, y+50, x-50, y);
fill(255, 0, 0, opacities[5]);
triangle(x, y, x-50, y, x-25, y-50);
}
void update() {
for (int i = 0; i < opacities.length; i++) {
if (random(100) < 50) {
opacities[i] -= 1;
}
}
}
}
My thanks
1