This is the web version of EJS interface
EJS version 4.2.7
1. Title=Moon Phases
2. Author=Todd Timberlake remix by lookang
3. Keywords=moon, phase, earthlight
5. Language=english
6. Abstract=original by Todd Timberlake http://www.compadre.org/OSP/document/ServeFile.cfm?ID=9308&DocID=1247 remix by lookang http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1927.0
7. CaptureTools=false
8. DataTools=false
9. LanguageTools=true
10. EmersionSupport=false
11. UseInterpreter=true
12. AuxiliaryFiles=./MoonPhases/;

## Moon Phases

nPhases/MoonPhases
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
//set polygons for bright and dark sides of Earth for (int i = 0; i < np; i++) { theta = i*Math.PI/(np-1) - Math.PI/2.0; el[i][0] = rE*Math.cos(theta); el[i][1] = rE*Math.sin(theta); ed[i][0] = rE*Math.cos(theta + Math.PI); ed[i][1] = rE*Math.sin(theta + Math.PI); }
for(int i=0;i<nm;i++){ // xm[i]=x2+zerox+i*dxm; //Initizlize Tab: xm=x2+zerox+i*dxm; drawing the top scale // if(i%10==0){ xm[i] = 1.25*rE*Math.cos(i/24.0*2*pi); ym[i] = 1.25*rE*Math.sin(i/24.0*2*pi); dxm[i]= 0.25*rE*Math.cos(i/24.0*2*pi); dym[i]= 0.25*rE*Math.sin(i/24.0*2*pi); // xmt[i/10]=xm[i]; // numbers position // tmt[i/10]=i+""; // texts for upper scale if(i%6==0){ dxm[i]= 0.5*rE*Math.cos(i/24.0*2*pi); dym[i]= 0.5*rE*Math.sin(i/24.0*2*pi); // else dym[i]=y2/4; } } //text for(int i=0;i<nmt;i++){ xmt[i] = 2.25*rE*Math.cos(i/4.0*2*pi); ymt[i] = 2.25*rE*Math.sin(i/4.0*2*pi); } tmt[0] = "noon"; tmt[1] = "sunset"; tmt[2] = "midnight"; tmt[3] = "sunrise";

### MoonPhaseEvol

//set x and y coordinates of Moon's position in orbit x = d*Math.cos(ang); y = d*Math.sin(ang); //set polygons for bright and dark sides of Moon for (int i = 0; i < np; i++) { theta = i*Math.PI/(np-1) - Math.PI/2.0; pl[i][0] = x + rM*Math.cos(theta); pl[i][1] = y + rM*Math.sin(theta); pd[i][0] = x + rM*Math.cos(theta + Math.PI); pd[i][1] = y + rM*Math.sin(theta + Math.PI); } //set polygon for shadow in Moon View if (y > 0) { for (int i = 0; i < np; i++) { theta = i*Math.PI/(np-1) - Math.PI/2.0; pv[i][0] = Math.cos(ang)*Math.cos(theta); pv[i][1] = Math.sin(theta); } for (int i = np; i < 2*np; i++) { theta = Math.PI/2.0 - (i-np)*Math.PI/(np-1); pv[i][0] = -Math.cos(theta); pv[i][1] = Math.sin(theta); } } else { for (int i = 0; i < np; i++) { theta = i*Math.PI/(np-1) + Math.PI/2.0; pv[i][0] = -Math.cos(theta); pv[i][1] = Math.sin(theta); } for (int i = np; i < 2*np; i++) { theta = 3.0*Math.PI/2.0 - (i-np)*Math.PI/(np-1); pv[i][0] = Math.cos(ang)*Math.cos(theta); pv[i][1] = Math.sin(theta); } } //set polygon for Light Cone //0 earth bottom by lookang // 1 moon bottom // 2 moon top // 3 eath top cone[0][0] = rE*Math.cos(ang-Math.PI/2.0); cone[0][1] = rE*Math.sin(ang-Math.PI/2.0); cone[1][0] = x + rM*Math.cos(ang-Math.PI/2.0); cone[1][1] = y + rM*Math.sin(ang-Math.PI/2.0); cone[2][0] = x - rM*Math.cos(ang-Math.PI/2.0); cone[2][1] = y - rM*Math.sin(ang-Math.PI/2.0); cone[3][0] = -rE*Math.cos(ang-Math.PI/2.0); cone[3][1] = -rE*Math.sin(ang-Math.PI/2.0); //compute earth-moon-sun angle in degrees angle = 180.0*ang/Math.PI; //compute angular position of observer on Earth at time tang = (time-12.0)*Math.PI/12.0; //compute x and y coordinates of observer xobs = rE*Math.cos(tang); yobs = rE*Math.sin(tang); //computer coordinates for horizon line h1x = xobs/60 - 12*Math.cos(tang+Math.PI/2.0); h1y = yobs/60 - 12*Math.sin(tang+Math.PI/2.0); lhx = 24*Math.cos(tang+Math.PI/2.0); lhy = 24*Math.sin(tang+Math.PI/2.0); //change transparency of darknessPolygon to emulate Earthlight transp = 230-(int)(20*Math.cos(ang)); color = new Color(0,0,0,transp);
// added by lookang // ang sun-earth-moon angle // angle sun-earth-moon in degree // tang angle for position of observer on earth if (ang >= 2*Math.PI)ang -= 2*Math.PI;// clever way to reset the ang to zero if greater than 2pi if ( tang<0) tang= tang+2*pi; // special case 4thQ moon and 1stQ observer if (observable==true&&ang>1.5*pi&&tang<0.5*pi&&(ang-tang-2*pi)>=(-pi/2)&&(ang-tang-2*pi)<=(pi/2)) { special = true; // for debug inside = true; // for testing inside light cone colorobs = new Color(0,255,0,transp); } // special case 1stQ moon and 4thQ observer else if (observable==true&&ang<0.5*pi&&tang>1.5*pi&&(ang-tang+2*pi)>=(-pi/2)&&(ang-tang+2*pi)<=(pi/2)) { special = true; inside = true; colorobs = new Color(0,255,0,transp); } //if (ang+tang<ang+pi/2 && ang-tang>ang-pi/2 ) // work for 1st quardrant else if (observable==true&&(ang-tang)>=(-pi/2)&&(ang-tang)<=(pi/2)) { special = false; inside = true; colorobs = new Color(0,255,0,transp); // green } else if (observable==false) // to allow the colorobservable to stay the same after boolean unchecked { } else { special = false; inside = false; colorobs = new Color(255,0,0,transp); // red }
if (time>=0&&time<=5||time>18) { colorday = new Color(0,0,0,transp); } if (time>=6&&time<=18) { // a simple model for daylight by lookang blueness = (int) (255*Math.abs(Math.sin((time-6)*2*pi/24))); //blueness = 255; // colorday = new Color(62,106,blueness,100); colorday = new Color(62,106,195,blueness); }
//textstring by lookang if (ang>=-pi/18&&ang<=pi/18) { textstring = "New Moon"; } else if (ang>=pi/18&&ang<=pi/2-pi/18) { textstring = "Waxing Crescent Moon"; } else if (ang>=pi/2-pi/18&&ang<=pi/2+pi/18) { textstring = "Quarter Moon"; } else if (ang>=pi/2+pi/18&&ang<=pi-pi/18) { textstring = "Waxing Gibbous Moon"; } else if (ang>=pi/2-pi/18&&ang<=pi+pi/18) { textstring = "Full Moon"; } else if (ang>=pi+pi/18&&ang<=1.5*pi-pi/18) { textstring = "Waning Gibbous Moon"; } else if (ang>=1.5*pi-pi/18&&ang<=1.5*pi+pi/18) { textstring = "3rd Quarter Moon"; } else if (ang>=1.5*pi+pi/18&&ang<=2*pi-pi/18) { textstring = "Waning Crescent Moon"; }
EJSVIEW: Click link to view it's content
 Control variables:(testing)double,double
 title = "Moon Phases Model" layout = BORDER:0,0 visible = true location = "3,9" size = "700,500"
 position = center autoscaleX = false autoscaleY = false minimumX = -11 maximumX = 17.5 minimumY = -11 maximumY = 11 square = true TLmessage = "Orbital Top View of Moon " BLmessage = "Not to Scale" size = "600,600" background = black
 x = 0 y = 0 sizeX = 2*d sizeY = 2*d visible = ShowMO lineColor = white fillColor = none
 x = x y = y sizeX = rM*2 sizeY = rM*2 transformation = ang imageFile = "./MoonPhases/moontopviewgoogle.png"
 data = pl lineColor = 192,192,192,100 fillColor = 192,192,192,100
 data = pd lineColor = 64,64,64,100 fillColor = 64,64,64,100
 x = 0 y = 0 sizeX = x sizeY = y visible = overhead lineColor = MAGENTA
 x = 0 y = 0 sizeX = rE*2 sizeY = rE*2 transformation = tang imageFile = "./MoonPhases/earthtopview.png"
 data = el lineColor = 0,0,255,100 fillColor = 0,0,255,100
 data = ed lineColor = 0,0,0,100 fillColor = 0,0,0,200
 x = 17 y = 5 sizeX = -4 sizeY = 0 lineColor = orange fillColor = orange
 x = 17 y = 10 sizeX = -4 sizeY = 0 lineColor = orange fillColor = orange
 x = 17 y = 0 sizeX = -4 sizeY = 0 lineColor = orange fillColor = orange
 x = 17 y = -5 sizeX = -4 sizeY = 0 lineColor = orange fillColor = orange
 x = 17 y = -10 sizeX = -4 sizeY = 0 lineColor = orange fillColor = orange
 x = 15 y = 2.5 sizeX = 3 sizeY = 1.5 text = "Sunlight" lineColor = orange fillColor = orange
 x = xobs y = yobs sizeX = dspot sizeY = dspot transformation = tang visible = observer
 x = 1 y = 0 sizeX = 0.5 sizeY = 0.5 style = WHEEL lineColor = colorobs fillColor = colorobs
 x = 1 y = 0 sizeX = -0.5 sizeY = 0 lineColor = colorobs
 x = 0.5 y = 0 sizeX = 0 sizeY = 0.75 elementposition = CENTERED lineColor = colorobs
 x = 0.5 y = 0 sizeX = -0.5 sizeY = -0.3 lineColor = colorobs
 x = 0.5 y = 0 sizeX = -0.5 sizeY = 0.3 lineColor = colorobs
 data = cone visible = ShowLC lineColor = none fillColor = 255,255,255,50
 visible = timebolean
 numberOfElements = nm x = xmt y = ymt pixelSize = true text = %tmt% lineColor = CYAN fillColor = CYAN
 numberOfElements = nm x = xm y = ym sizeX = dxm sizeY = dym enabledPosition = false style = SEGMENT lineColor = CYAN fillColor = CYAN
 visible = false
 text = "Display Options"
 position = south layout = VBOX
 layout = HBOX
 variable = text text = "text" background = WHITE tooltip = "guiding text of the phases of moon"
 position = center variable = ShowMoon text = "Show Moon View" tooltip = "Show Moon View: select to show view of Moon as seen from Earth."
 variable = ShowMO text = "Show Moon's Orbit" background = WHITE tooltip = "Moon's orbit around Earth."
 variable = ShowLC text = "Show Light Cone" background = 255,255,255,50 tooltip = "shows the portion of Moon that is visible from Earth as well as the portion of Earth from which Moon is visible."
 variable = overhead text = "overhead" background = MAGENTA tooltip = "show the vertical line down from moon to earth where the moon is directly overhead"
 variable = observable selected = true text = "hint:observable?" background = colorobs tooltip = "shows location of observer on Earth. what does green and red mean?"
 layout = HBOX
 position = center layout = HBOX
 layout = VBOX tooltip = "observer"
 layout = HBOX
 position = center variable = observer text = "Show Observer on Earth" background = colorobs
 variable = time value = 0.0 minimum = 0.0 maximum = 24 background = colorobs tooltip = "Local Mean Solar Time for Observer (0-24 h)"
 layout = HBOX
 layout = HBOX
 position = west text = "Day" alignment = RIGHT background = colorobs tooltip = "Day"
 variable = day format = "00" tooltip = "number of days pass in simulation"
 layout = HBOX
 variable = timebolean background = CYAN
 position = west text = " Local Time: " alignment = RIGHT background = colorobs tooltip = "Local Mean Solar Time for Observer (0-24 h)"
 variable = time format = "0.0" tooltip = "Local Time: sets the local mean solar time for an observer (indicated by the green dot) on Earth. Time is in hours, with 0 corresponding to midnight."
 text = "hr" alignment = RIGHT background = colorobs tooltip = "hours"
 layout = VBOX
 position = center variable = ang value = 0 minimum = 0.0 maximum = 2*Math.PI dragaction = if (ang >= 2*Math.PI)ang -= 2*Math.PI;// clever way to reset the ang to zero if greater than 2pi tooltip = "Angle: slider controls the angle between Sun and Moon, as seen from Earth. This effectively moves Moon around in its orbit as seen in the Orbit Window."
 layout = HBOX
 position = center text = "Orbit Angle"
 variable = angle format = "0.0" tooltip = "Sun-Earth-Moon Angle (degrees) "
 text = "deg"
 position = west layout = HBOX
 position = west variable = _isPaused tooltip = "Play/Pause Button: play/pause Moon's motion along its orbit." imageOn = "/org/opensourcephysics/resources/controls/images/play.gif" actionOn = _play() imageOff = "/org/opensourcephysics/resources/controls/images/pause.gif" actionOff = _pause()
 image = "/org/opensourcephysics/resources/controls/images/stepforward.gif" action = _step(); tooltip = "Single steps the simulation."
 image = "/org/opensourcephysics/resources/controls/images/reset.gif" action = _reset() tooltip = "reset the simulation"
 position = west autoscaleX = false autoscaleY = false minimumX = -1.2 maximumX = 1.2 minimumY = -1.2 maximumY = 1.2 square = true TLmessage = "Earth View of the Moon" BLmessage = "Sky turn blue daytime, dark in nighttime" visible = ShowMoon background = BLACK tooltip = "Earth View of the Moon"
 x = 0 y = 0 sizeX = 2.4 sizeY = 10 style = RECTANGLE lineColor = colorday fillColor = colorday
 x = 0 y = 0 sizeX = 1.98 sizeY = 1.98 visible = inside imageFile = "./MoonPhases/moon.png" elementposition = CENTERED
 data = pv visible = inside lineColor = none fillColor = color
 x = 0 y = 0 pixelSize = true visible = text text = %textstring% font = Arial,BOLD,16 lineColor = WHITE fillColor = WHITE
 position = east layout = VBOX visible = false
 position = center variable = ang format = "ang=0.00"
 position = north variable = angle format = "angle=0.00"
 position = south variable = tang format = "tang=0.00"
 variable = theta format = "theta=0.00"
 variable = inside format = "inside=0"
 variable = special format = "special=0"
 variable = pi format = "pi=0.00"
 variable = ang2 format = "ang2=0.00"
 variable = (ang-tang)-pi/2 format = "ex1=0.00"
 variable = ang-tang+pi/2 format = "exp2=0.00"
 variable = dspot format = "dspot=0.00"
 variable = xm[0] format = "xmo=0.0"
 variable = xm[1] format = "xmi=0.00"
 variable = ym[0] format = "ymo=0.0"
 variable = ym[1] format = "ymi=0.0"
 variable = blueness format = "blueness=0" background = colorday