We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, guys! I am new to Processing and I already was asking a question about this code before, but now I have another question. My code generates 20 circles positioned randomly and each one of them possesses one of the 10 available "interests". Those with the same interest are connected with each other with a line. Now I want to make each of the circles to increase their size by 5px with each line they have connected to them. The problem in my code is that instead of just becoming bigger, the circles keep growing with each void draw() How can I fix this? What should I use? Thanks a lot!
Bubble[] myBubble = new Bubble[20];
void setup() {
size(500, 500);
for (int i=0; i< myBubble.length; i++) {
int s = 20;
int x1 = int(random(20,480));
int y1 = int(random(20,480));
int z = int(random(3));
int interest = int(random(10));
color c1;
if ( z>=1) {
c1 = color(255, 0, 0);
} else {
c1= color(0, 0, 255);
}
myBubble [i] = new Bubble( x1, y1, c1, s, interest);
}
}
void draw() {
background(255);
for (int i = 0; i<myBubble.length; i++) {
myBubble [i] .display();
for (int j = 0; j<myBubble.length; j++) {
if( myBubble[i].inter == myBubble [j]. inter){
line(myBubble[i].x, myBubble[i].y, myBubble[j].x, myBubble[j].y);
myBubble[i].size_inc=myBubble[i].size_inc + 5;
myBubble[j].size_inc= myBubble[j].size_inc + 5;
}
}
}
}
class Bubble {
int x;
int y;
int size;
color cor;
int inter;
int size_inc;
Bubble() {
x=250;
y=250;
cor = color(255, 255, 0);
size =20;
inter = int (random(10));
size_inc = 0;
}
Bubble ( int _x, int _y, color _cor, int _size, int _inter) {
x= _x;
y= _y;
cor = _cor;
size=_size;
inter = _inter;
}
void display() {
ellipseMode(CENTER);
fill(cor);
ellipse(x, y, size+size_inc, size+size_inc);
}
}
Answers
Try moving lines 25 to 32 inclusive to line 17 so it only gets executed once.
I tried to do this, but I get a NullPointerException error every time
@bug_ugly === add some boolean, try this (if you only want 1 inc);