2d array animation problem
in
Programming Questions
•
2 years ago
Hi,
This is part of a larger script, that's why I need the array plus the class (it may seem too much in this script).
What I'm trying to do here is to move the black circle down, but I can't get why there are two circles...
I'm sure it should be very simple, but I just can't solve it.
The main script:
The class:
This is part of a larger script, that's why I need the array plus the class (it may seem too much in this script).
What I'm trying to do here is to move the black circle down, but I can't get why there are two circles...
I'm sure it should be very simple, but I just can't solve it.
The main script:
- Move objMove;
int cols = 11;
int rows = 11;
int[][] dotMatrix = new int[cols][rows];
void setup() {
frameRate(30);
size(200,200);
noStroke();
smooth();
objMove = new Move(9);
}
void draw() {
matrix();
objMove.display();
}
void matrix() {
background(200);
for (int i = 0; i <= 9; i = i+1) {
for (int j = 0; j <= 9; j = j+1) {
if (dotMatrix[i][j] == 1) {
fill(50);
ellipse(20*i+10, 20*j+10, 18, 18);
} else {
fill(255);
ellipse(20*i+10, 20*j+10, 18, 18);
}
}
}
}
The class:
- class Move {
float pX = random(0,10);
int posX = int(pX);
int num;
int posY = 0;
boolean stop = false;
Move(int number) {
num = number; // balls
}
void display() {
if (stop == false) {
dotMatrix[posY][posX] = 1;
if (dotMatrix[posY][posX] == 1) {
fill(50);
ellipse(20*posX+10, 20*posY+10, 18, 18);
if (keyPressed) {
dotMatrix[posY][posX] = 0;
posY = posY + 1;
dotMatrix[posY][posX] = 1;
if (posY >= 10) {
stop = true;
}
}
}
}
}
}
1