Files
WavesPrograms/xray1.html
2021-08-18 19:24:55 -07:00

260 lines
8.6 KiB
HTML

<!--
This work is licensed under CC BY-NC-ND 4.0
Link to license: http://creativecommons.org/licenses/by-nc-nd/4.0/
Attribute to Russell Georgi
-->
<html>
<head>
<title>
Waves: X-ray 1
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
form {
position: relative;
}
.slideContainer {
position: relative;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;">
Your browser does not support the HTML5 canvas tag.</canvas>
<form id = "form">
<label for="t1">Incoming planes of constant phase</label>
<input type="checkbox" id="t1" onclick="t1Click()">
<br>
<label for="t2">Outgoing planes of constant phase</label>
<input type="checkbox" id="t2" onclick="t2Click()">
<br>
<label for="t3">Atoms in the crystal</label>
<input type="checkbox" id="t3" onclick="t3Click()">
<br>
<label for="t4">Incoming k-vector</label>
<input type="checkbox" id="t4" onclick="t4Click()">
<br>
<label for="t5">Outgoing k-vector</label>
<input type="checkbox" id="t5" onclick="t5Click()">
<br>
<label for="t6">Change in k-vector</label>
<input type="checkbox" id="t6" onclick="t6Click()">
</form>
<div class="slidecontainer" id = "div">
<t>Direction of incoming x-rays</t>
<input type="range" min="-12" max="12" value="0" step = "0.1" id="xSlider">
</div>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
var scrwidth = c.width / 3;
var lclr = ["#aa00aa", "#aa0000", "#ff5555", "#ffff55", "#55ff55","#00aa00", "#5555ff", "#0000aa"];
var t1 = false;
var t2 = false;
var t3 = false;
var t4 = false;
var t5 = false;
var t6 = false;
var dth = .05;
var th = .525;
var xPos = 0;
var yPos = 0;
var xSlider = document.getElementById("xSlider");
var m = 1;
xSlider.oninput = function()
{
th = parseFloat(this.value);
}
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
ctx.scale(1.5, -1.5);
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Clear(ctx);
Draw();
setTimeout(Update, 1000/60);
}
function Draw()
{
cth = Math.cos(th);
sth = Math.sin(th);
ke = 300 * sth / cth * 25 / scrwidth;
if (t3)
{
for (j = 0; j <= 50; j++)
{
for (k = -20; k <= 70; k++)
{
ctx.fillStyle = lclr[(j - k + 200) % 8];
console.log(ctx.fillStyle);
ctx.beginPath();
ctx.arc(scrwidth * (j - 25) / 25, scrwidth / 25 / sth * (k - 25 - (j - 25) * cth), 2, 0, Math.PI * 2);
ctx.fill();
}
}
}
if (t1)
{
for (j = 0; j <= 50; j++)
{
ctx.strokeStyle = lclr[j % 8];
ctx.beginPath();
ctx.moveTo(scrwidth * (j - 25) / 25, c.height / 3);
ctx.lineTo(scrwidth * (j - 25) / 25, -c.height / 3);
ctx.stroke();
}
}
if (t2)
{
for (j = -20; j <= 70; j++)
{
ctx.strokeStyle = lclr[(j + 200) % 8];
ctx.beginPath();
ctx.moveTo(scrwidth * (j - 25) / 25 / cth + 150 * sth / cth, c.height / 3);
ctx.lineTo(scrwidth * (j - 25) / 25 / cth - 150 * sth / cth, -c.height / 3);
ctx.stroke();
}
}
if (t4)
{
vector(0, 0, 100, 0, 8, "#000000");
}
if (t5)
{
vector(0, 0, 100 * Math.cos(th), 100 * Math.sin(th), 8, "#000000");
}
if (t6)
{
vector(0, 0, 100 * (1 - Math.cos(th)), -100 * Math.sin(th), 8, "#000000");
}
}
window.addEventListener('resize', function(event) {
c.width = window.innerWidth;
c.height = window.innerHeight;
ctx.translate(c.width / 2, c.height / 2);
ctx.scale(1.5, -1.5);
scrwidth = c.width / 3;
}, true);
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
htmlHide();
}
}
function htmlHide()
{
var x = document.getElementById("form");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
x = document.getElementById("div");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function t1Click()
{
checkBox = document.getElementById("t1");
t1 = checkBox.checked;
Clear(ctx);
}
function t2Click()
{
checkBox = document.getElementById("t2");
t2 = checkBox.checked;
Clear(ctx);
}
function t3Click()
{
checkBox = document.getElementById("t3");
t3 = checkBox.checked;
Clear(ctx);
}
function t4Click()
{
checkBox = document.getElementById("t4");
t4 = checkBox.checked;
Clear(ctx);
}
function t5Click()
{
checkBox = document.getElementById("t5");
t5 = checkBox.checked;
Clear(ctx);
}
function t6Click()
{
checkBox = document.getElementById("t6");
t6 = checkBox.checked;
Clear(ctx);
}
function vector(xv, yv, xvv, yvv, va, cl)
{
vl = ((xvv - xv) ** 2 + Math.pow(yvv - yv, 2)) ** (1/2);
ctx.strokeStyle = cl;
ctx.beginPath();
ctx.moveTo(xPos + xv, yPos + yv);
ctx.lineTo(xPos + xvv, yPos + yvv);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + xvv, yPos + yvv);
ctx.lineTo(xPos + xvv - va / vl * (xvv - xv) + va / vl / 2 * (yvv - yv), yPos + yvv - va / vl * (yvv - yv) - va / vl / 2 * (xvv - xv));
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + xvv, yPos + yvv);
ctx.lineTo(xPos + xvv - va / vl * (xvv - xv) - va / vl / 2 * (yvv - yv), yPos + yvv - va / vl * (yvv - yv) + va / vl / 2 * (xvv - xv));
ctx.stroke();
}
Update();
</script>
</body>
<p xmlns:cc="http://creativecommons.org/ns#" style="font-size: 1vw; bottom: 0px; position: absolute;">
This work is licensed under
<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1"></a></p>
</html>