xxxxxxxxxx
339
// Miscellaneous functions
const miscFontColour = color(127, 127, 127);
const posDataColour = color(088, 239, 224);
const negDataColour = color(107, 049, 048);
const miscFontSize = 14;
const panelWidth = 200;
// Lines and shapes
function mkVertLine(x) {
// make a vertical line
push();
stroke(miscFontColour);
line(x, 0, x, height);
pop();
}
function mkHorzLine(x1, x2, y) {
push();
stroke(miscFontColour);
line(x1, y, x2, y);
pop();
}
// // Arrows
// function mkArrow(x, y, l, w, angle, colour) {
// // x position, y position, length, width, angle, color
// translate(x, y);
// rotate(angle);
// fill(colour);
// stroke(colour);
// triangle(0, 0, -w, w / 2, -w, -w / 2);
// line(-w, 0, -l, 0);
// rotate(-angle);
// translate(-x, -y);
// }
// Instructions
function mkInstructHeader(x, y) {
fill(miscFontColour);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text("Controls", x, y + 13);
textStyle(BOLD);
textSize(miscFontSize - 1);
textAlign(LEFT, TOP);
// print("miscDraw Line 50");
// text("Click and drag the mouse on the image", x, y);
drawImage(IMGS[3][1], x + panelWidth - iconW - 30, y + 26, (9 / 8) * iconW, (9 / 8) * iconH, 255); // Click and drag
text("Change the lens \nposition on the \nright panel", x, y + 34)
// print("miscDraw line 53");
drawImage(IMGS[3][0], x + panelWidth - iconW - 10, y + 118, 2 * iconW / 3, 2 * iconH / 3, 255); // Click
// print("miscDraw Line 55");
drawImage(IMGS[3][2], x + panelWidth - iconW - 38, y + 98, 65, 20, 255); // Keys
text("Select thumbnail \nto change image", x, y + 110);
text("or", x + panelWidth - iconW - 30, y + 133);
drawImage(IMGS[3][3], x + panelWidth - iconW - 38, y + 178, (7 / 16) * iconW, (7 / 16) * iconH, 255); // S Key
drawImage(IMGS[3][4], x + panelWidth - iconW - 10, y + 178, 2 * iconW / 3, 8 * iconH / 9, 255); // Double Click
text("Switch between \nconvergent and \ndivergent lens", x, y + 178);
text("or", x + panelWidth - iconW - 30, y + 206);
}
function mkInstructBody(x, y, w) {
translate(x, y);
ax = 4 * (w / 2) / 5;
al = 4 * (w / 2) / 11;
aw = al / 5;
tx = 1.05 * ax;
textSize(miscFontSize);
textStyle(NORMAL);
textAlign(CENTER, CENTER);
text("Mouse\nMovement\nDirection", 0, 0);
textAlign(CENTER, BOTTOM);
text("Real\nData", 0, -tx);
textAlign(CENTER, TOP);
text("Imaginary\nData", 0, tx);
textAlign(LEFT, CENTER);
text("Advance\nTime", tx, 0);
textAlign(RIGHT, CENTER);
// text("Reverse\nTime", -tx, 0);
// mkArrow(ax, 0, al, aw, 0, miscFontColour); // right arrow
// mkArrow(0, -ax, al, aw, -HALF_PI, miscFontColour); // up arrow
// mkArrow(-ax, 0, al, aw, PI, miscFontColour); // left arrow
// mkArrow(0, ax, al, aw, HALF_PI, miscFontColour); // down arrow
noFill();
circle(0, 0, 2 * (ax - al));
translate(-x, -y);
}
function mkInstructFoot(x, y) {
translate(x, y);
textSize(miscFontSize);
textStyle(NORMAL);
text("Drag the mouse on the image for finer control. \nUse the sliders for a fast change.", 0, 0);
translate(-x, -y);
}
// Current Time
function mkTimeDisp(x, y) {
translate(x, y);
fill(color(0, 0, 0));
rect(0, 0, 200, 60);
fill(miscFontColour);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text("Interactive Time: ", 0, 0);
textSize(miscFontSize);
textStyle(NORMAL);
// text(timeString(), 0, 30);
translate(-x, -y);
}
function dispTime(x_off) {
translate(x_off, 0);
mkTimeDisp(20, height - 130);
translate(-x_off, 0);
}
// Project Time Stamp
function mkTimeStamp(x, y) {
authorId = "Kelvin Au";
// uTime = "4:00, April 20, 2021";
term = "Winter 2021";
projId = "PHYS 7440 Major Project";
fill(miscFontColour);
textStyle(NORMAL);
textSize(miscFontSize - 3);
textAlign(LEFT, CENTER);
// text(projId + "\n" + authorId + "\nLast Updated: " + uTime, x, y);
text(projId + "\n" + authorId + "\n" + term, x, y);
}
// Science Content
function mkScienceText(x, y) {
scititle = "Gravitational \nLensing";
scitext = "";
scitext += "\t\tIf you've ever looked at a \nstraw placed in a glass of \nwater you may have noticed \nthat the straw appears to \nbend. Water and air have \ndifferent indices of \nrefraction. A light ray \nencountering media of \ndifferent indices of refraction \nwill have its path bent. This \nis an example of Fermat's \nprinciple."
scitext += "\n\t\tGravitational lensing can \nbe similarly described by an \n'effective index of refraction.' \nA light ray will have its path \nbent by the deformation of \nspacetime caused by \nmassive objects such as \nstars, black holes, galaxies, \nor even clusters of galaxies.";
// scitext += "\n\t\tNote that the divergent lens \navailable here is purely \ntheoretical as it corresponds \nto lensing by a negative mass.";
// scitext += "\n\t\tThe function has been assumed to be symmetric in \u03D5.";
translate(x, y);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text(scititle, 0, 0);
textSize(miscFontSize);
textStyle(NORMAL);
text(scitext, 0, miscFontSize + 40);
translate(-x, -y);
}
// Colour Code
function mkColourCode(x, y) {
translate(x, y);
fill(miscFontColour);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text("Colour Codes:", 0, 0);
s = 20;
// Positive Data Colour
y1 = 30;
fill(posDataColour);
rect(0, y1, 50, s);
// Negative Data Colour
y2 = 60;
fill(negDataColour);
rect(0, y2, 50, s);
// Text Description
fill(miscFontColour);
textSize(miscFontSize);
textStyle(NORMAL);
text("F > 0", 55, y1);
text("F < 0", 55, y2);
translate(-x, -y);
}
// Schematic
function mkSchematicHeader(x, y) {
scititle = "Your View to the \nCosmos Through a";
translate(x, y);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text(scititle, 0, 0);
}
// Lenses
function mkLensHeader(x, y) {
fill(miscFontColour);
textSize(miscFontSize + 6);
textStyle(ITALIC);
// text("Convergent", x, y + 13);
textStyle(BOLD);
textSize(miscFontSize);
textAlign(LEFT, TOP);
// print("miscDraw Line 50");
// text("Click and drag the mouse on the image", x, y);
// drawImage(IMGS[3][1], x + panelWidth - iconW - 30, y + 25, (9 / 8) * iconW, (9 / 8) * iconH, 255); // Click and drag
// text("Change the lens \nposition on the \nright panel", x, y + 33)
}
// Lens Content
function mkConvergentText(x, y) {
scititle = "Convergent Lens";
scitext = "";
scitext += "A gravitational (convergent) \nlens will bend the path \nof a light ray eminating \nfrom a distant source \nTOWARD you."
// scitext += "\n\t\tGravitational lensing can be \nsimilarly described by an \n'effective index of refraction.' A \nlight ray will have its path bent by \nthe deformation of spacetime \ncaused by massive objects such \nas stars, black holes, galaxies, or \neven clusters of galaxies.";
// scitext += "\n\t\tNote that the divergent lens \navailable here is purely \ntheoretical as it corresponds \nto lensing by a negative mass.";
// scitext += "\n\t\tThe function has been assumed to be symmetric in \u03D5.";
// coverText(x, y);
translate(x, y);
fill(miscFontColour);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text(scititle, 0, -height / 2 - 42);
textSize(miscFontSize);
textStyle(NORMAL);
text(scitext, 0, miscFontSize + 10);
textSize(miscFontSize - 2);
translate(-x, -y);
}
// Lens Content
function mkDivergentText(x, y) {
scititle = "Divergent Lens";
scitext = "";
scitext += "A divergent lens will bend \nthe path of a light ray \neminating from a distant \nsource AWAY from you."
scitext2 = "";
scitext2 += "\n\*Note that gravitational divergent \nlens is purely theoretical as it \ncorresponds to a lens with \nnegative mass. However, plasma \nlenses are divergent."
// scitext += "\t\tA divergent lens will \nbend the path of a light ray \neminating from a distant \nsource AWAY you. \n\t\t*Note that a divergent \nlens is purely theoretical as \nit corresponds to a lens \nwith negative mass."
// scitext += "\n\t\tGravitational lensing can be \nsimilarly described by an \n'effective index of refraction.' A \nlight ray will have its path bent by \nthe deformation of spacetime \ncaused by massive objects such \nas stars, black holes, galaxies, or \neven clusters of galaxies.";
// scitext += "\n\t\tNote that the divergent lens \navailable here is purely \ntheoretical as it corresponds \nto lensing by a negative mass.";
// scitext += "\n\t\tThe function has been assumed to be symmetric in \u03D5.";
// coverText(x, y);
translate(x, y);
fill(miscFontColour);
textAlign(LEFT, TOP);
textSize(miscFontSize + 6);
textStyle(ITALIC);
text(scititle, 0, -height / 2 - 42);
textSize(miscFontSize);
textStyle(NORMAL);
text(scitext, 0, miscFontSize + 10);
textSize(miscFontSize - 2);
text(scitext2, 0, 90);
translate(-x, -y);
}
function coverText(x, y) {
// Creates a black rectange that covers elements in the right panel
fill(bcolour);
rect(x - 42, 60, 180, 575);
// rect(x, y + 20, 200, 160); // Covers lens text
// rect(x, 60, 200, miscFontSize + 13); // Covers Divergent/Convergent Lens
// rect(x, y + 20, 200, 160); // Covers schematic text
}
// Draw Schematics
function mkSchematics(x, y) {
// fill(miscFontColour);
// textSize(miscFontSize + 6);
// textStyle(ITALIC);
// text("Controls", x, y + 13);
textStyle(BOLD);
textSize(miscFontSize);
textAlign(LEFT, TOP);
text("Distant \nSource", x - 20, y - 20);
text("Lensing \nObject", x - 25, y + 138);
text("Observer", x - 20, y + 312);
}
function leftPanel(x_off) {
push();
fill(color(0, 0, 0));
rect(x_off, 0, panelWidth, height);
pop();
mkVertLine(panelWidth)
mkHorzLine(x_off, panelWidth - 1, height / 2 + 90);
// mkHorzLine(x_off, panelWidth - 1, height / 2 + 140);
// mkHorzLine(x_off, panelWidth - 1, height / 2 + 245);
// mkHorzLine(x_off, panelWidth - 1, height - 60);
x = (width - x_off) / 2;
y = 2 * height / 9;
w = 4.0 * (width - x_off) / 9.0;
h = w;
push();
translate(x_off, 0);
mkInstructHeader(20, height / 2 + 105); // Takes text position (x,y) as arguments
// mkInstructFoot(20, y + h / 2 + 30);
mkScienceText(20, 15);
// mkColourCode(20, height / 2 + 150);
// dispTime(0);
// mkTimeStamp(20, height - 30);
// mkInstructBody(x, y, w, h);
pop();
}
function rightPanel(x_off) {
push();
fill(color(0, 0, 0));
rect(x_off, 0, panelWidth, height);
pop();
mkVertLine(x_off)
// mkHorzLine(x_off + 1, width, height / 2 + 35);
// mkHorzLine(x_off, panelWidth - 1, height / 2 + 140);
// mkHorzLine(x_off, panelWidth - 1, height / 2 + 245);
mkHorzLine(x_off + 1, width, height - 60);
x = (width - x_off) / 2;
y = 2 * height / 9;
w = 4.0 * (width - x_off) / 9.0;
h = w;
push();
translate(x_off, 0);
mkLensHeader(20, height / 2 + 60); // Takes text position (x,y) as arguments
// mkInstructFoot(20, y + h / 2 + 30);
mkSchematicHeader(20, 15);
// mkSchematics(40, 120);
// mkColourCode(20, height / 2 + 150);
// dispTime(0);
mkTimeStamp(0, height - 45);
// mkInstructBody(x, y, w, h);
pop();
}
function dispMisc(x_off1, x_off2) {
// Draw left panel
leftPanel(x_off1);
// Draw right panel
rightPanel(x_off2);
}
// End of File