hello,
but you are a programmer now!
The error I spotted is rarely known even by the best so don't worry about this. It was not a obvious error.
new version
improved:
- once the random number for the array is set, it's not changed anymore (till we hit next sphere) - more stable text - achieved by: see isNearMouse
- only one sphere can have text, not two at the same time - no overwriting text - achieved by: method displayText does return a value and the for-loop breaks (exits) when the first text is dsplayed
- all spheres are drawn first, then all text - no sphere can be painted above text (so it looks better) - achieved by: two separate for-loops in draw, separate methods display and displayText
//
PFont font;
JitterBug[] bugs = new JitterBug[33];
String [] black;
void setup() {
size(1000, 500);
black = loadStrings("black.txt");
font= createFont("HelveticaNeue-Bold-22.vlw", 13);
textFont(font);
textSize(22);
smooth();
for (int i = 0; i < bugs.length; i++) {
float x= random(width);
float y= random(height);
int r = i + 2;
bugs[i] = new JitterBug(x, y, r);
}
}
//
void draw() {
background(#2F2C31);
for (int i = 0; i<bugs.length;i++) {
bugs[i].move();
bugs[i].display();
}
for (int i = 0; i<bugs.length;i++) {
if (bugs[i].displayText())
{
println("break");
break;
}
}
}
// ==================================
class JitterBug {
float x;
float y;
int diameter;
float speed =2.5;
int value =0;
boolean isNearMouse = false;
int index=0;
JitterBug(float tempX, float tempY, int tempDiameter) {
x = tempX;
y = tempY;
diameter = tempDiameter;
}
void move() {
x += random(-speed, speed);
y += random(-speed, speed);
}
void display() {
float d = dist(mouseX, mouseY, x, y);
fill(value);
ellipse(x, y, diameter, diameter);
}
//
boolean displayText() {
float d = dist(mouseX, mouseY, x, y);
fill(value);
// ellipse(x, y, diameter, diameter);
if (d < diameter) {
fill(255);
if (!isNearMouse) {
index=int(random(0, 3));
}
//text("what do I need to do to display random strings?? ", 100, height/2, 924, 768);
text(black[index], 100, height/2, 924, 768);
isNearMouse=true;
}
else {
isNearMouse=false;
}
return(isNearMouse);
} // method
//
} // class
// ==================================