I've gotten a lot further and have been able to greatly reduce the amount of code necessary which should make it easier to read.
My only problem at the moment is that the program only functions correctly in the upper left quarter. I think I need to alter the 'if' statement inside boolean overLine to correct this but I'm not sure of the math. Could someone please help.
I am currently using 'y = mx +b' to try and plot the line.
Code:
int numLines;
float radius;
int stro;
Lines[] ln;
void setup(){
size(500, 500);
background(0);
stroke(255);
smooth();
//the equation below will make the lines extend to the edges
radius = width/2-10; //sqrt(pow(width/2, 2)+pow(height/2,2));
numLines = round(degrees(TWO_PI)/3);
ln = new Lines[numLines];
for (int i = 0; i<ln.length; i++){
float angle = radians(i*3);
float x = width/2 +(cos(angle) * radius); //equation for the circle
float y = width/2 +(sin(angle) * radius); //that defines the lines.
ln[i] = new Lines(x, y, ln);
}
}
void draw(){
fill(0, 12);
rect(-1, -1, width+1, height +1);
fill(255);
stroke(255);
for (int i = 0; i <ln.length; i++){
ln[i].update();
ln[i].display();
}
}
class Lines{
float x, y, m;
Lines[] others;
boolean over;
boolean locked = false;
boolean otherslocked = false;
Lines(float xpos, float ypos, Lines[] o){
x = xpos;
y = ypos;
m = y/x;
others = o;
}
void update(){
for (int i = 0; i<others.length; i++){
if (others[i].locked == true){
otherslocked = true;
break;
}
else {
otherslocked = false;
}
}
if (otherslocked == false){
over();
}
}
void over(){
if (overLine(x, y, m)){
over = true;
stro = 3;
}
else{
over = false;
stro = 1;
}
}
void display(){
if (over) {
strokeWeight(stro);
line(x, y, width/2, height/2);
}
strokeWeight(1);
line(x, y, width/2, height/2);
}
}
boolean overLine(float x, float y, float m){
if (mouseX >= y/m && mouseY >= m*x){ //if I change the '>' for '<' I can change
return true; //which quadrant it will respond to the
} //mouse properly in
else {
return false;
}
}