unexpected error
in
Programming Questions
•
3 years ago
Being new to processing I know that I have to pay extra attention to the punctuation and the case sensitiviness of the code.
Having done that I persistently get the following error. Found one too many { characters without a } to match it. in the attached piece of code. Honestly I don't know what went wrong and politely ask for some help. Many thanks in advance
// global variables and arrays
int boardWidth = 300; // boardwidth (px)
int boardOffsetX = 200; // horizontal offset of board from desk (0,0)
int boardOffsetY = 100; // horizontal offset of board from desk (0,0)
int boardWrap = 3; // # of cells wrapped around
int cellWidth = 20; // inclusive border (stoke)
int cells = int(boardWidth / cellWidth); // #number of cells/row
int steps = 0; // from play setup
int myStep = 0; // initialisation of steps
String [][]myImage; // image, declaration of the array (2d)
void setup() {
size(800,600); // desk
background(255); // color desk (white)
buttonFillBlack = new myButtons(10, 10, 1, 1, "buttonFillBlack"); // generate buttonFillBlack
}
/*String myFill = "0"; // default fill of image (white=0, black=1)
myImage = new String[cells][cells]; // composition of image array
for (int i = 0; i < cells; i++) { // horizontal loop
for (int j = 0; j < cells; j++) { // vertical loop
myImage[i][j] = myFill; // initialisation of image array
}
}
drawBoard(); // goto drawBoard
//drawButtons(); // goto drawButtons
}
void drawBoardBorder() { // draw the board border
noFill(); // transparant
stroke(0); // border black
rect(boardOffsetX,boardOffsetY,boardWidth,boardWidth); // board border
for (int i = 0; i < boardWrap * cellWidth; i++) { // transparency loop
int myTransparency = int(map(i, 0, boardWrap * cellWidth, 255,80)); // transparency values
fill(255,myTransparency); //set transparency
noStroke(); // draw 4 decreasing transparent rectangles
rect(boardOffsetX -boardWrap * cellWidth, i + boardOffsetY - boardWrap * cellWidth,
boardWidth + boardWrap * 2 * cellWidth, 1); // top rectangle
rect(boardOffsetX -boardWrap * cellWidth, -i + boardOffsetY + boardWidth + boardWrap * cellWidth,
boardWidth + boardWrap * 2 * cellWidth, 1); // bottom rectangle
rect(i + boardOffsetX -boardWrap * cellWidth, boardOffsetY - boardWrap * cellWidth,
1, boardWidth + boardWrap * 2 * cellWidth); // left rectangle
rect(-i + boardOffsetX + boardWidth + boardWrap * cellWidth, boardOffsetY - boardWrap * cellWidth,
1, boardWidth + boardWrap * 2 * cellWidth); // right rectangle
}
}
void drawBoard() { // draw the board
stroke(200); // border (stroke 1px) made less invisible
for (int i = 0 - boardWrap; i < cells + boardWrap; i++) { // horizontal draw loop
int n = i; // neglect wrap cells for fill check
if (n < 0) {
n += cells;
} else if (n >= cells) {
n -= cells;
}
for (int j = 0 - boardWrap; j < cells + boardWrap; j++) { // vertical draw loop
int m = j; // neglect wrap cells for fill check
if (m < 0) {
m += cells;
} else if (m >= cells) {
m -= cells;
}
if (myImage[n][m].charAt(myStep) == '0') { //check fill value
fill (255); // fill with white
} else {
fill (0); // fill with black
}
rect(i * cellWidth + boardOffsetX, j * cellWidth + boardOffsetY, cellWidth, cellWidth); //draw filled cells
}
}
drawBoardBorder(); // goto drawBoardBorder
}
*/
void draw() { }
int buttonUnit = 25; // button draw unit
int buttonBorder = 2; // button strokewidth in px
int buttonFill = 0; // button fill
int buttonFillPressed = #4B5096; // button fill when hovered over or pressed #4B5096 or RGB 75,80,150
myButtons buttonFillBlack; // declare buttonFillBlack
void drawButtons() {
buttonFillBlack.display(); // draw buttonFillBlack
}
class myButtons { // create class MyButtons
int x; // horizontal coordinate of button (left)
int y; // vertical coordinate of button (top)
int buttonShape; // shape of the button (0= round, 1= square, n= rectangle)
int buttonUse; // 0= Off, 1= active, 2= hovered, 3= pressed
String buttonText; // info on the use of the button
myButtons(int tempX, int tempY, int tempButtonShape, int tempButtonUse, String tempButtonText) { // constructor myButtons
x = tempX;
y = tempY;
buttonShape = tempButtonShape;
buttonUse = tempButtonUse;
buttonText = tempButtonText;
}
void display() {
smooth();
strokeJoin(BEVEL);
stroke(buttonFill);
strokeWeight(buttonBorder);
fill (buttonFill);
if (buttonUse = O) {
int(mytranparency) = 100;
} else if (buttonUse >= 1) {
int(mytranparency) = 255;
} else if (buttonUse >= 2) {
int(mytranparency) = 255;
fill (buttonFillPressed);
}
if (buttonShape = O) {
ellipse(x, y, buttonUnit , buttonUnit);
} else if (buttonShape >= 1) {
rect(x, y, buttonUnit * buttonShape, buttonUnit);
}
}
Having done that I persistently get the following error. Found one too many { characters without a } to match it. in the attached piece of code. Honestly I don't know what went wrong and politely ask for some help. Many thanks in advance
// global variables and arrays
int boardWidth = 300; // boardwidth (px)
int boardOffsetX = 200; // horizontal offset of board from desk (0,0)
int boardOffsetY = 100; // horizontal offset of board from desk (0,0)
int boardWrap = 3; // # of cells wrapped around
int cellWidth = 20; // inclusive border (stoke)
int cells = int(boardWidth / cellWidth); // #number of cells/row
int steps = 0; // from play setup
int myStep = 0; // initialisation of steps
String [][]myImage; // image, declaration of the array (2d)
void setup() {
size(800,600); // desk
background(255); // color desk (white)
buttonFillBlack = new myButtons(10, 10, 1, 1, "buttonFillBlack"); // generate buttonFillBlack
}
/*String myFill = "0"; // default fill of image (white=0, black=1)
myImage = new String[cells][cells]; // composition of image array
for (int i = 0; i < cells; i++) { // horizontal loop
for (int j = 0; j < cells; j++) { // vertical loop
myImage[i][j] = myFill; // initialisation of image array
}
}
drawBoard(); // goto drawBoard
//drawButtons(); // goto drawButtons
}
void drawBoardBorder() { // draw the board border
noFill(); // transparant
stroke(0); // border black
rect(boardOffsetX,boardOffsetY,boardWidth,boardWidth); // board border
for (int i = 0; i < boardWrap * cellWidth; i++) { // transparency loop
int myTransparency = int(map(i, 0, boardWrap * cellWidth, 255,80)); // transparency values
fill(255,myTransparency); //set transparency
noStroke(); // draw 4 decreasing transparent rectangles
rect(boardOffsetX -boardWrap * cellWidth, i + boardOffsetY - boardWrap * cellWidth,
boardWidth + boardWrap * 2 * cellWidth, 1); // top rectangle
rect(boardOffsetX -boardWrap * cellWidth, -i + boardOffsetY + boardWidth + boardWrap * cellWidth,
boardWidth + boardWrap * 2 * cellWidth, 1); // bottom rectangle
rect(i + boardOffsetX -boardWrap * cellWidth, boardOffsetY - boardWrap * cellWidth,
1, boardWidth + boardWrap * 2 * cellWidth); // left rectangle
rect(-i + boardOffsetX + boardWidth + boardWrap * cellWidth, boardOffsetY - boardWrap * cellWidth,
1, boardWidth + boardWrap * 2 * cellWidth); // right rectangle
}
}
void drawBoard() { // draw the board
stroke(200); // border (stroke 1px) made less invisible
for (int i = 0 - boardWrap; i < cells + boardWrap; i++) { // horizontal draw loop
int n = i; // neglect wrap cells for fill check
if (n < 0) {
n += cells;
} else if (n >= cells) {
n -= cells;
}
for (int j = 0 - boardWrap; j < cells + boardWrap; j++) { // vertical draw loop
int m = j; // neglect wrap cells for fill check
if (m < 0) {
m += cells;
} else if (m >= cells) {
m -= cells;
}
if (myImage[n][m].charAt(myStep) == '0') { //check fill value
fill (255); // fill with white
} else {
fill (0); // fill with black
}
rect(i * cellWidth + boardOffsetX, j * cellWidth + boardOffsetY, cellWidth, cellWidth); //draw filled cells
}
}
drawBoardBorder(); // goto drawBoardBorder
}
*/
void draw() { }
int buttonUnit = 25; // button draw unit
int buttonBorder = 2; // button strokewidth in px
int buttonFill = 0; // button fill
int buttonFillPressed = #4B5096; // button fill when hovered over or pressed #4B5096 or RGB 75,80,150
myButtons buttonFillBlack; // declare buttonFillBlack
void drawButtons() {
buttonFillBlack.display(); // draw buttonFillBlack
}
class myButtons { // create class MyButtons
int x; // horizontal coordinate of button (left)
int y; // vertical coordinate of button (top)
int buttonShape; // shape of the button (0= round, 1= square, n= rectangle)
int buttonUse; // 0= Off, 1= active, 2= hovered, 3= pressed
String buttonText; // info on the use of the button
myButtons(int tempX, int tempY, int tempButtonShape, int tempButtonUse, String tempButtonText) { // constructor myButtons
x = tempX;
y = tempY;
buttonShape = tempButtonShape;
buttonUse = tempButtonUse;
buttonText = tempButtonText;
}
void display() {
smooth();
strokeJoin(BEVEL);
stroke(buttonFill);
strokeWeight(buttonBorder);
fill (buttonFill);
if (buttonUse = O) {
int(mytranparency) = 100;
} else if (buttonUse >= 1) {
int(mytranparency) = 255;
} else if (buttonUse >= 2) {
int(mytranparency) = 255;
fill (buttonFillPressed);
}
if (buttonShape = O) {
ellipse(x, y, buttonUnit , buttonUnit);
} else if (buttonShape >= 1) {
rect(x, y, buttonUnit * buttonShape, buttonUnit);
}
}
1
