/** Alternative Relativity: Doppler Effect Demonstrator by Robert John Morton (Belo Horizonte-MG 27 September 2006, 02 May 2012) */ // WAVE INSTANCE GENERATOR import java.awt.*; //f or graphics operations (GUI) class wave { // THIS CLASS CREATES AND MANAGES THE LIFE CYCLE OF ONE WAVE private static boolean dm = false; // false = classical mode, true = alternative mode private static int RMAX = 500, // allow for maximum extent of fading waves /* 64 x-plots and y-plots respectively for the circular quadrant for each of 400 radii. */ CX[][] = new int[RMAX][64], CY[][] = new int[RMAX][64], Ymax = 95; // extremity hight limit of the display area private static double // one 256th part of a circle as fraction of a radian Angle = 0.024933275028490422527481296692694; private static Color // colour value for each 64th of a quadrant at each of 400 radii CB[][] = new Color[RMAX][64], // intensities for the blue/green and the red/green hemispheres CR[][] = new Color[RMAX][64], // radial intensity levels for the pure green circles CG[] = new Color[RMAX]; private int r = 3, // current radius of the wave circle X = 0, // x-coord of start of display area Y = 95, // y-coord of centre of display area ox = 0, // old value of the x-coordinate oy = 0; // old value of the y-coordinate private boolean mh = false, // true = signal to spawn the following wave pa = false, // true means wave has reached its extremity nl = false; // false means new wave not yet launched from this instance private String RT = "CGPI/DIREX/DPF-V429810-2CPF01681522667"; //colour fader wave(int x){X = x;} // set the horizontal starting position for the wave // these methods allow applet to access this class's flags boolean getmh(){return mh;} // returns true if wave has reached its final extremity boolean getah(){return pa;} // returns true if new succeeding wave has already been launched boolean getnl(){return nl;} // allows applet to set "new launch expedited" flag herein void setnl() { nl = true; } void atualizar(Graphics h) { if(r > 30) mh = true; // signal to spawn the following wave object if(r > 400) // maximum radius of an active wave pa = true; // signal to kill this wave else { // else if(r > 10) wipeWave(h,r-8); // erase the fifth previous circle if(dm) drawGreen(h,r++); // plot the next green circle else drawWave(h,r++); // plot the next multi-coloured circle } } /* The 3 following drawing methods are written separately to maximize processing speed in their central loops. */ void drawWave(Graphics h, int r) { ox = r; oy = 0; // old values of the x,y coordinates // for each of 64 angular increments in a quadrant for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // y-coordinate of the next primary plot // force top and bottom vertical limits on the y-coordinate if(ny > Ymax && oy <= Ymax) ny = Ymax; if(oy > Ymax && ny <= Ymax) oy = Ymax; int nx = CX[r][i], // x-coordinate of the next primary plot // For the forward and rear semicircles, compute the nX = X + nx, Xn = X - nx, // new x-coordinates oX = X + ox, Xo = X - ox, // old x-coordinates nY = Y + ny, Yn = Y - ny, // new y-coordinates oY = Y + oy, Yo = Y - oy; // old y-coordinates // set phased and faded colour for the blue/green quadrants h.setColor( CB[r][i] ); h.drawLine(oX,oY,nX,nY); // draw line in first blue/green quadrant h.drawLine(oX,Yo,nX,Yn); // draw line in second blue/green quadrant // set phased and faded colour for the red/green quadrants h.setColor( CR[r][i] ); h.drawLine(Xo,oY,Xn,nY); // draw line in first red/green quadrant h.drawLine(Xo,Yo,Xn,Yn); // draw line in second red/green quadrant ox = nx; // set the current x,y co-ordinates oy = ny; // as next time's old x,y coordinates end of 'for' loop } } void drawGreen(Graphics h, int r) { ox = r; oy = 0; // old values of the x,y coordinates // for each of 64 angular increments in a quadrant... for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // y-coordinate of the next primary plot // force top and bottom vertical limits on the y-coordinate if(ny > Ymax && oy <= Ymax) ny = Ymax; if(oy > Ymax && ny <= Ymax) oy = Ymax; int nx = CX[r][i], // x-coordinate of the next primary plot // For the forward and rear semicircles, compute the nX = X + nx, Xn = X - nx, // new x-coordinates oX = X + ox, Xo = X - ox, // old x-coordinates nY = Y + ny, Yn = Y - ny, // new y-coordinates oY = Y + oy, Yo = Y - oy; // old y-coordinates h.setColor( CG[r] ); // set radially-faded green colour h.drawLine(oX,oY,nX,nY); // draw line in first blue/green quadrant h.drawLine(oX,Yo,nX,Yn); // draw line in second blue/green quadrant h.drawLine(Xo,oY,Xn,nY); // draw line in first red/green quadrant h.drawLine(Xo,Yo,Xn,Yn); // draw line in second red/green quadrant ox = nx; // set the current x,y co-ordinates oy = ny; // as next time's old x,y coordinates } } void wipeWave(Graphics h, int r) { ox = r; oy = 0; // old values of the x,y coordinates h.setColor(Color.black); // colour black for a wipe pass only // for each of 64 angular increments in a quadrant for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // y-coordinate of the next primary plot // force top and bottom vertical limits on the y-coordinate if(ny > Ymax && oy <= Ymax) ny = Ymax; if(oy > Ymax && ny <= Ymax) oy = Ymax; int nx = CX[r][i], // x-coordinate of the next primary plot // For the forward and rear semicircles, computer the nX = X + nx, Xn = X - nx, // new x-coordinates oX = X + ox, Xo = X - ox, // old x-coordinates nY = Y + ny, Yn = Y - ny, // new y-coordinates oY = Y + oy, Yo = Y - oy; // old y-coordinates h.drawLine(oX,oY,nX,nY); // draw line in first blue/green quadrant h.drawLine(oX,Yo,nX,Yn); // draw line in second blue/green quadrant h.drawLine(Xo,oY,Xn,nY); // draw line in first red/green quadrant h.drawLine(Xo,Yo,Xn,Yn); // draw line in second red/green quadrant ox = nx; // set the current x,y co-ordinates oy = ny; // as next time's old x,y coordinates } } static void sineValues() { double angle = 0; // angle variable for forming the angles array // for each of 64 angular divisions of the primary quadrant for(int i = 0; i < 64; i++) { double s = Math.sin(angle), // compute the next sine value c = Math.cos(angle), // compute the next cosine value cc = 255 * c, // cosine -modified colour value ss = 255 * s; // sine-modified colour value // for each radius out as far as 400 pixels... for(int j = 0; j < 400; j++) { double r = (double)j; // radius of quarter-circle // At this angle at this radius... CX[j][i] = (int)(r * c); // x-coordinate CY[j][i] = (int)(r * s); // y-coordinate // From the radius, form the colour fading factor double k = 1 - r / 440; // Colour values phased by sine and faded by radius int g = (int)(ss * k), // green rb = (int)(cc * k), // red/blue q = (int)(255 * k); // green faded only by radius // Colour arrays for: CR[j][i] = new Color(rb,g,0); // the red/green quadrant CB[j][i] = new Color(0,g,rb); // the blue/green quadrant // Green intensity array for each of the 400 possible radii CG[j] = new Color(0,q,0); } angle += Angle; // increment the angle by one 64th of a quadrant } } static void setMode(int ds) { // set the "relativity mode" if(ds == 0) dm = false; // false = "classical relativity" else dm = true; // true = "alternative relativity" } }