// This example shows the basic // structure of most Processing programs: // using "setup" and "draw". This program // resembles the previous example very much. // In contrast however, it never stops // drawing lines. // // Example I.4 float P1x, P1y; float P2x, P2y; float P3x, P3y; float P4x, P4y; float P5x, P5y; float P6x, P6y; float P7x, P7y; float P8x, P8y; int xint, yint, x2int, y2int; float x, y; float x2, y2; float Aang = 0.0; float Bang, Cang; float Aang2, Bang2, Cang2; float totang; float d1, d2, d3; float a, b, c; float radius = 20; int center = 250; // Everything inside this function is done // once, at the start of program execution. void setup() { size(500, 500); background(102); } // law of sines // sin(Aang)/a == sin(Bang)/b // Aang = asin((a * sin(Bang))/b) // law of cosines // sq(c) == sq(a) + sq(b) - 2*a*b*cos(Cang) // 2*a*b*cos(Cang) == sq(a) + sq(b) - sq(c) // cos(Cang) == (sq(a) + sq(b) - sq(c))/(2*a*b) // Cang == acos((sq(a) + sq(b) - sq(c))/(2*a*b)) // // Everything inside this function is done // continuously and without stopping, after // setup() is done. // In this example it keeps on drawing // lines with an orientation (a) that // changes slowly towards zero degrees. void draw() { background(102); // refreshes the screen P1x = (float) (center); P1y = (float) (center); ellipseMode (CENTER); ellipse (P1x, P1y, 2*radius, 2*radius); P2x = P1x + (radius * cos(Aang)); P2y = P1y + (radius * sin(Aang)); line(P1x, P1y, P2x, P2y); P3x = (P1x + 80); P3y = P1y; line(P1x, P1y, P3x, P3y); line(P2x, P2y, P3x, P3y); // Now compute P4 d1 = dist(P2x, P2y, P3x, P3y); Cang = acos((sq(radius) + sq(d1) - sq(80))/(2*radius*d1)); Bang = PI - (Aang + Cang); // this is the angle between the length P1 P3 and P2 P3 if (Aang > PI) Bang = PI - (((2*PI) - Aang) + Cang); // Bang will be // above the horizontal. Cang2 = acos((sq(d1) + sq(60) - sq(70))/(2*d1*60)); totang = Bang + Cang2; if (Aang > PI) totang = Cang2 - Bang; // after PI, need to subtract Bang P4x = ((P3x) - (60 * cos(totang))); P4y = (int) ((P3y ) + (60 * sin(totang))); d2 = dist(P4x, P4y, P2x, P2y); if ((d2 <= 71) && (d2 >= 69)) Aang += PI/180; line(P4x, P4y, P2x, P2y); line(P4x, P4y, P3x, P3y); if(Aang >= 2 * PI) Aang = Aang - (2*PI); } void mousePressed() { loop(); }