Please help! unexpected taken ; void on the "void draw()" line.
Hi. here I tried to have many circles by means of array but, now I have got an error : unexpected taken ; void on the "void draw()" line. I wounder how to fix this problem.
I want to increase the number of circles which have capability of being dragged by the mouse.
final color BACKGROUND = color (0, 0, 0) ; // the background colour(BLACK)
int numCircle = 3 ; // the number of memory
Memory[] circle = new Circle[numCircle] ; // declare and create the array
// -------------------------------------------------
void setup() {
size(960, 600) ; // set the mianpanel size as 960 * 600)
background(BACKGROUND) ; // set the background colour
smooth() ;
noStroke() ;
for(int i = 0; i < circle.length; i++){
float x = 20 + i * 10 ;
float y = 10 + i * 20 ;
circle[i] = new Circle(x, y, 50) ; // create each object
}
// ------------------------------------------------------------------------------ Main methods
// Display the elements
void draw() {
background(BACKGROUND) ;
for (int i = 0; i < circle.length; i++){
circle[i].paint() ; // draw the objects consist in the Memory paint() function
}
}
// -------------------------------------------------
void mousePressed() {
circle.dragPressed() ; // when the mouse is pressed, do the drawPressed() function
}
void mouseReleased() {
circle.dragReleased() ; // when the mouse is released, do the drawReleased() function
}
// -------------------------------------------------------------------------------------------------------------------------------------------------
class Circle {
// ----------------------------------------------------------------- Constants and variables
private float x, y ; // the x and y-coordinate of the circle(object)
private float dx, dy ; // the difference between the circle's position and the mouse position
private int radius ; // the radius of the circle
private boolean startDrag ; // prepare for drag signal
// ---------------------------------------------------------------------------- Constructors
Circle(float xPos, float yPos, int radi) {
this.x = xPos ;
this.y = yPos ;
this.radius = radi ;
}
// --------------------------------------------------------------------------- Public methods
public void paint() {
// when the mouse drag starts, starDrag turns "true" and implement the function
if (startDrag == true) {
x = mouseX + dx;
y = mouseY + dy;
}
// Draw the circle
fill(255) ;
ellipse(x, y, radius, radius) ;
}
// ------------------------------------------------------- Getters and setters
// ------------------------------------------------------- Setters
// ------------------------------------------------------ Other public methods
public void dragPressed(){
// if the centre of the cicle and the mouse position is less than the radius of the circle,
if (dist(x, y, mouseX, mouseY) <= radius) {
startDrag = true ; // the drag turns "true"
// calculate the distance between the circle's position and that of mouse
dx = x - mouseX;
dy = y - mouseY;
}
}
public void dragReleased(){
startDrag = false ; // the darg turns "false"
}
// -------------------------------------------------------------------------------------------
}
// -------------------------------------------------------------------------------------------