hi,
|'m trying to write a code that demonstrates a spread of infected pixels that appear from and after the user draws a line in processing (I added a picture that demonstrates the stages that code makes).
But my code is stuck. I’ve been able to start it but the picture is frozen.
Nekuda [] nekudot = new Nekuda [5000];
int total = 0;
void core() {
stroke(255);
if (mousePressed == true) {
line(mouseX, mouseY, pmouseX, pmouseY);
}
setup();
draw();
}
void setup () {
size (600, 600);
background (0);
for (int i = 0; i< nekudot.length; i++) {
nekudot [i] = new Nekuda ();
}
}
void draw () {
background (0);
for (int i = 0; i< nekudot.length; i++) {
if (isEmpty(nekudot[i].getX(), nekudot[i].getY()) && hasNeighbor(nekudot[i].getX(), nekudot[i].getY())) {
nekudot[i].reset ();
}
nekudot[i].step ();
nekudot[i].display ();
}
}
boolean isEmpty(int x, int y) {
color c = get(x, y);
if (c == 0) {
return true;
} else {
return false;
}
}
boolean hasNeighbor(int x, int y) {
for (int i=x-1; i<x+2; x++) {
for (int j=y-1; j<y+2; y++) {
if (isEmpty(i, j)) {
return true;
}
}
}
return false;
}
class Nekuda {
int x;
int y;
public Nekuda () {
x = (int)random (0, 600);
y = (int)random (0, 600);
}
private void reset () {
x = (int)random (0, 600);
y = (int)random (0, 600);
}
public int getX(){
return x;
}
public int getY(){
return y;
}
void display () {
point (x, y);
stroke (255, 0, 0);
}
void step () {
int choice = int(random(4));
if (choice == 0) {
x++;
} else if (choice == 1) {
x--;
} else if (choice == 2) {
y++;
} else {
y--;
}
}
}
any ideas?
thanks