float x, gamma, v; int frameCounter, t; ArrayList Waves; boolean relativity, startSimulation, pause; PFont font; byte colourPointer; //COLOURS color Background,Foreground,Outline,Hover,Attention; /*where:- Background is the background colour Foreground is the default fill colour for boxes Outline is the colour used for texts and borders for boxes Hover is the fill colour when the mouse is over a box Attention is the fill colour to give user attention */ //GUI NUMBER_INPUT V_INPUT; //user input for v/c NUMBER_INPUT LAMBDA_INPUT; //user input for lambda DROP_DOWN RELATIVITY_INPUT; //user choice of relativity BUTTON START; //button to start/stop the simulation BUTTON PAUSE; BUTTON CHANGE_COLOUR; void setup(){ size(950,490); frameRate(60); x = 0; v = 0.6; frameCounter = 0; colourPointer = 0; Waves = new ArrayList(); //Typography data font = loadFont("Calibri-24.vlw"); textFont(font,24); V_INPUT = new NUMBER_INPUT(2*width/3+5, 5, "v/c = ", "x10¯²", 40, 0, 99); /* Vo_INPUT is a number input GUI for the speed of the particle:- it is at coordinates (2*width/3+5,5) with heading "v/c = " with units "x10¯²" the initial value is 0.4 the lowest value is 1 the highest value is 9 */ LAMBDA_INPUT = new NUMBER_INPUT(2*width/3+5, 45, "λ = ", "m", 40, 5, 99); /* LAMBDA_INPUT is a number input GUI for the wavelength:- it is at coordinates (2*width/3+5,45) with heading "λ = " the initial value is 120 the lowest value is 1 the highest value is 999 */ String [] DATA; //the options in the drop down menu DATA = new String [2]; DATA [0] = "On"; DATA [1] = "Off"; relativity = true; RELATIVITY_INPUT = new DROP_DOWN(2*width/3+5, 85, 0, DATA, "Relativistic factor: "); /* RELATIVITY_INPUT is a drop down menu GUI:- it is at coordinates(2*width/3+5,85) the initial value is 1, ie on with these options: On, off the heading is "Relativity: "*/ START = new BUTTON(2*width/3+5, 230, "Start/Stop", 10+textWidth("Start/Stop")); startSimulation = false; /* START is a button GUI:- it is at coordinates (2*width/3+5, 230) "Start/Stop" is wrtten in the button it is as long as the string with 10 pixels padding initially the simulation is stopped */ PAUSE = new BUTTON(2*width/3+5, 270, "Pause", 10+textWidth("Pause")); pause = false; /* START is a button GUI:- it is at coordinates (2*width/3+5, 270) "Pause" is wrtten in the button it is as long as the string with 10 pixels padding initially the simulation is stopped */ CHANGE_COLOUR = new BUTTON(2*width/3+5, 330, "Change colour", 10+textWidth("Change colour")); colourPointer = 0; /* CHANGE_COLOUR is a button GUI:- it is at coordinates (2*width/3+5,380) "Change colour" is written in the button it is as long as the string with 10 pixels padding initially the colourPointer is pointing at 0 */ } void draw(){ //Update colour scheme colour_scheme(colourPointer); background(Background); if (startSimulation == true){ //Update v/c if (V_INPUT.acceptKeyboard == false){ v = float(V_INPUT.return_value()); v /= 100; } //Update t if (LAMBDA_INPUT.acceptKeyboard == false){ t = LAMBDA_INPUT.return_value(); } //Draw particle noStroke(); fill(0,255,0); ellipse(x,height/2,10,10); //Work out relativistic factor if (relativity == true){ gamma = 1/(sqrt(1-sq(v))); } else { gamma = 1; } //Make new waves fronts and move the particle if (pause == false){ if (frameCounter%(round(gamma)*t)==0){ Waves.add(new WAVE(x)); } x += v; frameCounter++; } //Display all wave fronts for (int i=Waves.size()-1; i>=0; i--){ WAVE OBJECT = (WAVE) Waves.get(i); OBJECT.display(); if (OBJECT.r > 2*width/3){ Waves.remove(i); } } //Restart the simulation when the particle travels all the way if (x>=2*width/3){ x = 0; frameCounter = 0; for (int i = Waves.size()-1; i>=0; i--){ Waves.remove(i); } } } //Create a square for user control panel stroke(Outline); fill(Background); strokeWeight(1); rectMode(CORNER); rect(2*width/3,-1,width+1,height+1); //Show v/c input V_INPUT.display(); //Show LAMBDA input LAMBDA_INPUT.display(); //Display delta lambda + lambda text("λ+Δλ = "+ t*gamma*(1+v) + " m", 2*width/3+5, 135+textDescent()+textAscent()); //Display gamma text("γ = "+ gamma, 2*width/3+5, 175+textDescent()+textAscent()); //Display relativity drop-down menu RELATIVITY_INPUT.display(); START.display(); PAUSE.display(); CHANGE_COLOUR.display(); status("Frame Rate: "+round(frameRate)); }