/** Part of the Lissajous Figures demonstrator by Robert John Morton */ /* This class implements a sine table for sines of angles needed to create Lissajou's Figures. Finished 01 October 1997 */ class TabCoord { int a = 0; // main phase angle int d = 1; // main phase angle incrementer int Q = 0; // quadrant counter boolean s = true; // indicates the output sign boolean f = false; // flag to trigger start of wiper static int[] S = { // Sine Table giving sin(a) every half degree 0, 87, 175, 262, 349, 436, 523, 610, 698, 785, 872, 958, 1045, 1132, 1219, 1305, 1392, 1478, 1564, 1650, 1736, 1822, 1908, 1994, 2079, 2164, 2250, 2334, 2419, 2504, 2588, 2672, 2756, 2840, 2924, 3007, 3090, 3173, 3256, 3338, 3420, 3502, 3584, 3665, 3746, 3827, 3907, 3987, 4067, 4147, 4226, 4305, 4384, 4462, 4540, 4617, 4695, 4772, 4848, 4924, 5000, 5075, 5150, 5225, 5299, 5373, 5446, 5519, 5592, 5664, 5736, 5807, 5878, 5948, 6018, 6088, 6157, 6225, 6293, 6361, 6428, 6494, 6561, 6626, 6691, 6756, 6820, 6884, 6947, 7009, 7071, 7133, 7193, 7254, 7314, 7373, 7431, 7490, 7547, 7604, 7660, 7716, 7771, 7826, 7880, 7934, 7986, 8039, 8090, 8141, 8192, 8241, 8290, 8339, 8387, 8434, 8480, 8526, 8572, 8616, 8660, 8704, 8746, 8788, 8829, 8870, 8910, 8949, 8988, 9026, 9063, 9100, 9135, 9171, 9205, 9239, 9272, 9304, 9336, 9367, 9397, 9426, 9455, 9483, 9511, 9537, 9563, 9588, 9613, 9636, 9659, 9681, 9703, 9724, 9744, 9763, 9781, 9799, 9816, 9833, 9848, 9863, 9877, 9890, 9903, 9914, 9925, 9936, 9945, 9954, 9962, 9969, 9976, 9981, 9986, 9990, 9994, 9997, 9998, 10000, 10000 }; // FINDS VALUE OF CO-ORDINATE CORRESPONDING TO INCREMENTED ANGLE public int Advance(int p, int m, int b) { int x = S[a] >> 7; // get x or y co-ord corresponding to given angle if(s) // if the output should be positive x = b + x; // add it to the co-ordinate origin bias else x = b - x; // else, take it from the co-ordinate origin bias a += d << m; // Advance main angle by appropriate amount (can be > 1). if(a < 0) { // If, as a result, we're now at or below bottom of table> a = p - a; // Wrap back up table; add this quadrant's phase increment d = 1; // set main angle to move up the table Q++; // quadrant counter s = !s; // reverse sign for the next 2 quadrants } else if(a > 180) { // if, as a result, we're now at or above top of table a = 360 - a - p; // Wrap back down table; subtract this quadrant's Q++; // phase increment & increment the quadrant counter d = -1; // set to move angle DOWN the table } if(!f) // if wiper start flag is not set if(Q > 6) // if 3 quadrants + 80 degrees completed f = true; // set the wiper start flag return(x); // return new x or y co-ordinate } // RESET THE VALUES IN A CO-ORDIATE OBJECT public void Reset() { a = 0; // main phase angle d = 1; // main phase angle incrementer Q = 0; // clear the quadrant counter s = true; // indicates the output sign f = false; // wiper start flag } }