/** Alternative Relativity: Doppler Effect Demonstrator by Robert John Morton UK-YE572246C (Belo Horizonte-MG 27 September 2006, 02 May 2012) */ // WAVE INSTANCE GENERATOR import java.awt.*; //for graphics operations (GUI) class wave { // THIS CLASS CREATES AND MANAGES THE LIFE CYCLE OF ONE WAVE //false = classical mode, true = alternative mode private static boolean dm = false; private static int RMAX = 500, //allow for maximum extent of fading waves /* These arrays contain the 64 x-plots and 64 y-plots for the circular quadrant for each of 400 radii. */ CX[][] = new int[RMAX][64], //64 x-plots CY[][] = new int[RMAX][64], //64 y-plots Ymax = 95; //extremity hight limit of the display area // a 256th part of a circle as fraction of a radian private static double Angle = 0.024933275028490422527481296692694; private static Color /* Colour value for each 64th of a quadrant at each of 400 radial intensities for the blue/green and the red/green hemispheres. */ CB[][] = new Color[RMAX][64], 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"; // Constructor: set the horizontal starting position for the wave. wave(int x) {X = x;} /* These methods allow the applet to access this class's flags. They return true if, respectively, if ... */ boolean getmh() { return (mh); } //the following wave has been spawned boolean getah() { return (pa); } //wave has reached its final extremity boolean getnl() { return (nl); } //new succeeding wave has already been // launched // 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 wave has now reached beyond maximum radius, kill it; else ... if(r > 400) pa = true; else { // if radius > 10, erase the fifth previous multi-coloured circle if(r > 10) wipeWave(h, r - 8); /* if "alternative relativity' mode, plot the next green circle, otherwise, plot the next multi-coloured circle. */ if(dm) drawGreen(h, r++); else drawWave(h, r++); } } /* 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, compute the y-coordinate of the next primary plot. Then ... */ for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // 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], //compute x-coordinate of next primary plot // Compute for the forward and rear semicircles ... 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 then draw lines in first and second blue/green quadrants. */ h.setColor(CB[r][i]); h.drawLine(oX, oY, nX, nY); h.drawLine(oX, Yo, nX, Yn); /* Set phased and faded colour for the red/green quadrants then draw lines in first and second red/green quadrants. */ h.setColor(CR[r][i]); h.drawLine(Xo, oY, Xn, nY); h.drawLine(Xo, Yo, Xn, Yn); //set the current x,y co-ordinates as next time's old x,y coordinates ox = nx; oy = ny; } //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, compute the y-coordinate of the next primary plot, then ... */ for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // 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], //compute x-coordinate of next primary plot // for the forward and rear semicircles ... 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 radially-faded green colour then draw lines in first and second blue/green quadrants and also in the first and second red/green quadrants. */ h.setColor( CG[r] ); h.drawLine(oX, oY, nX, nY); h.drawLine(oX, Yo, nX, Yn); h.drawLine(Xo, oY, Xn, nY); h.drawLine(Xo, Yo, Xn, Yn); //set the current x,y co-ordinates as next time's old x,y coordinates ox = nx; oy = ny; } } 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 compute the y-coordinate of the next primary plot. */ for(int i = 0; i < 64; i++) { int ny = CY[r][i]; // 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], //compute x-coordinate of next primary plot // For the forward and rear semicircles set ... 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 /* Draw lines in first and second blue/green quadrants and in first and second red/green quadrants. */ h.drawLine(oX, oY, nX, nY); h.drawLine(oX, Yo, nX, Yn); h.drawLine(Xo, oY, Xn, nY); h.drawLine(Xo, Yo, Xn, Yn); 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 the 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 // x and y coordinates at this angle and at this radius CX[j][i] = (int)(r * c); CY[j][i] = (int)(r * s); // form the colour fading factor from the radius double k = 1 - r / 400; //green colour value phased by sine and faded by radius int g = (int)(ss * k), //red/blue colour values phased by cosine and faded by radius rb = (int)(cc * k), //green colour value solely faded by radius q = (int)(255 * k); // Colour array for the ... CR[j][i] = new Color(rb, g, 0); //red/green quadrant CB[j][i] = new Color(0, g, rb); //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 } } // Set which "relativity" mode: "classical" or "alternative". static void setMode(int ds) { if(ds == 0) dm = false; else dm = true; } }