Draggable Balls to any cell..
in
Programming Questions
•
4 months ago
Hello ladies and gentlemen, im trying to get a ball to draggable to any cell in the grid. Ive got my grid and the balls set up. but i think my implementation is wrong since i cannot find any method to drag them
Here is what i have so far!
Ball[][] grid; // 2D Array of objects
int cols = 15; // Number of columns and rows in the grid
int rows = 15;
int increment;
void setup() {
size(600, 600);
grid = new Ball[cols][rows];
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
grid[i][j] = new Ball(i*40, j*40, 40, 40, i + j);
grid[i][j].display();
}
}
for (int i = 0; i < cols; i ++ ) {
for (int j = 14; j < rows; j ++ ) {
grid[i][j].greyscale();
//fill(greyscale);
grid[i][j].drawc();
}
}
}
void draw() {
}
void mousePressed() {
rect (mouseX, mouseY, 30, 30);
}
void keyPressed() {
}
And the Cell Code is :
class Ball { // Cell object
float x, y; // x,y location
float w, h; // width and height
Ball(float tempX, float tempY, float tempW, float tempH, float tempAngle) { // Cell Constructor
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void greyscale() {
increment=230 ;
}
void drawc() {
ellipse(x+20, y+20, w/2, h/2);
increment=increment-20;
}
void display() {
//stroke(0);
rect(x, y, w, h);
}
}
Here is what i have so far!
Ball[][] grid; // 2D Array of objects
int cols = 15; // Number of columns and rows in the grid
int rows = 15;
int increment;
void setup() {
size(600, 600);
grid = new Ball[cols][rows];
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
grid[i][j] = new Ball(i*40, j*40, 40, 40, i + j);
grid[i][j].display();
}
}
for (int i = 0; i < cols; i ++ ) {
for (int j = 14; j < rows; j ++ ) {
grid[i][j].greyscale();
//fill(greyscale);
grid[i][j].drawc();
}
}
}
void draw() {
}
void mousePressed() {
rect (mouseX, mouseY, 30, 30);
}
void keyPressed() {
}
And the Cell Code is :
class Ball { // Cell object
float x, y; // x,y location
float w, h; // width and height
Ball(float tempX, float tempY, float tempW, float tempH, float tempAngle) { // Cell Constructor
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void greyscale() {
increment=230 ;
}
void drawc() {
ellipse(x+20, y+20, w/2, h/2);
increment=increment-20;
}
void display() {
//stroke(0);
rect(x, y, w, h);
}
}
1