farebizarre
YaBB Newbies
Offline
Posts: 3
Germany
Re: Recognizing a line when mouse over
Reply #2 - Jul 18th , 2009, 8:58am
First of all, thanks a lot for the detailed explanation. You are right, it sounds like an easy task but actually is rather complex... I am trying to create, along with each line, a rectangle with the same starting point, same length, angle and minimum width, so I expect I can check the mouse rollover. Anyway, I would really like to see more of your idea, I'm sure it'll be more then helpful. This is the basic code that creates the lines, no mouse interaction considered: void setup() { size(600, 700); background(250); // Variables initialization float i = 0, x0 = 0, y0 = 0, alfa0 = 0, L0 = 0, t = 0, n = 0, j = 0, x = 0, y = 0, beta = 0, alfa = 0, a = 0, b = 0, Dt = 0, Da = 0, Db = 0, Dbeta = 0, Px = 0, Py = 0, Qx = 0, Qy = 0; int c = 0; // Collection of Brushes int[][] brushes = {{0, 0, 0, 1}, // Black Thin Stroke {0, 0, 0, 2}, // Black Thick Stroke {207, 118, 38, 2}}; // Orange Thick Stroke for (i = 1; i <= random(5, 20); i++){ // Control of the number of carriers i c = int(random(0, 3)); // Random index for the brushes matrix // Initial parameters of one carrier (a straight line) x0 = random(0.4 * width, 0.8 * width); // Origin point A0(x0, y0) y0 = random(0.5 * height, 0.7 * height); alfa0 = random(-PI, PI); // Angle(in radians) L0 = random(0.4 * width, 0.6 * width); // Length // Lenghts "a" and "b" of the first line (divided in two segments) of the bundle over the carrier. // They have the same angle "beta". a = random(0.2 * L0, 0.7 * L0); b = random(0.2 * L0, 0.7 * L0); beta = random(-PI, PI); n = random(5, 30); // Number of lines in the bundle t = 0; // First point in the carrier for (j = 0; j <= n ; j += 1){ // Bundle of lines t = t + Dt; // Next point in the carrier x = x0 + t * L0 * cos(alfa0); // Point (x,y) y = y0 + t * L0 * sin(alfa0); // Calculation of the parameters of the lines "a" and "b" a = a + Da; b = b + Db; beta = beta + Dbeta; // Next angle of "a" and "b" over the carrier alfa = PI - alfa0 - beta; // Next angle of "a" and "b" over the coordinates origin // P: ending point of "a" Px = x0 + t * L0 * cos(alfa0) + b * (- cos(alfa)); Py = y0 + t * L0 * sin(alfa0) + b * (sin(alfa)); // Q: ending point of "b" Qx = x0 + t * L0 * cos(alfa0) + a * (cos(alfa)); Qy = y0 + t * L0 * sin(alfa0) + a * (- sin(alfa)); smooth(); strokeWeight(brushes[c][3]); stroke(brushes[c][0], brushes[c][1], brushes[c][2]); line(x, y, Px, Py); // Paint line a line(x, y, Qx, Qy); // Paint line b // Random diferentials -> Next point Dt = random(0, 0.04); Dbeta = random(-0.05 * PI, 0.05 * PI); Da = random(- 0.2 * a, 0.2 * a); Db = random (- 0.2 * b, 0.2 * b); } } }