235 lines
7.9 KiB
HTML
235 lines
7.9 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 1-2
|
|
</title>
|
|
<style>
|
|
canvas {
|
|
position: absolute;
|
|
}
|
|
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0px;
|
|
border: 0;
|
|
overflow: hidden;
|
|
display: block;
|
|
}
|
|
|
|
.greenSlider {
|
|
-webkit-appearance: none;
|
|
border-radius: 5px;
|
|
height: 10px;
|
|
background: #d3d3d3;
|
|
outline: none;
|
|
opacity: 0.7;
|
|
-webkit-transition: .2s;
|
|
transition: opacity .2s;
|
|
|
|
}
|
|
|
|
.greenSlider::-webkit-slider-thumb {
|
|
-webkit-appearance: none;
|
|
appearance: none;
|
|
background: #00ff00;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.greenSlider::-moz-range-thumb {
|
|
background: #00ff00;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.redSlider {
|
|
-webkit-appearance: none;
|
|
border-radius: 5px;
|
|
height: 10px;
|
|
background: #d3d3d3;
|
|
outline: none;
|
|
opacity: 0.7;
|
|
-webkit-transition: .2s;
|
|
transition: opacity .2s;
|
|
|
|
}
|
|
|
|
.redSlider::-webkit-slider-thumb {
|
|
-webkit-appearance: none;
|
|
appearance: none;
|
|
background: #ff0000;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.redSlider::-moz-range-thumb {
|
|
background: #ff0000;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
</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>
|
|
<div class="slidecontainer">
|
|
<t>This program multiplies complex numbers.</t>
|
|
<t>Input the coordinates on w and z in the complex</t>
|
|
<t>plane.Then the blue vector is their product.</t>
|
|
<br>
|
|
<t>Real part of w</t>
|
|
<input type="range" min="-20" max="20" value="0" class="greenSlider" id="wRSlider">
|
|
<br>
|
|
<t>Imaginary part of w</t>
|
|
<input type="range" min="-20" max="20" value="0" class="greenSlider" id="wISlider">
|
|
<br>
|
|
<t>Real part of z</t>
|
|
<input type="range" min="-20" max="20" value="0" class="redSlider" id="zRSlider">
|
|
<br>
|
|
<t>Imaginary part of z</t>
|
|
<input type="range" min="-20" max="20" value="0" class="redSlider" id="zISlider">
|
|
</div>
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
var clx = "#ff0000";
|
|
var clw = "#00ff00";
|
|
var clz = "#0000ff";
|
|
var wR = 0;
|
|
var wRSlider = document.getElementById("wRSlider");
|
|
var wI = 0;
|
|
var wISlider = document.getElementById("wISlider");
|
|
var zR = 0;
|
|
var zRSlider = document.getElementById("zRSlider");
|
|
var zI = 0;
|
|
var zISlider = document.getElementById("zISlider");
|
|
var delta = 1;
|
|
var xPos = 0;
|
|
var yPos = 0;
|
|
var bottom = 0;
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(3, 3);
|
|
|
|
wRSlider.oninput = function()
|
|
{
|
|
wR = this.value * 5;
|
|
}
|
|
wISlider.oninput = function()
|
|
{
|
|
wI = -this.value * 5;
|
|
}
|
|
zRSlider.oninput = function()
|
|
{
|
|
zR = this.value * 5;
|
|
}
|
|
zISlider.oninput = function()
|
|
{
|
|
zI = -this.value * 5;
|
|
}
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
Clear(ctx);
|
|
var x2 = (zR * wR - zI * wI) / 50;
|
|
var y2 = (zR * wI + zI * wR) / 50;
|
|
ctx.strokeStyle = clx;
|
|
ctx.fillStyle = clx;
|
|
ctx.beginPath();
|
|
ctx.arc(zR, zI, 1, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.strokeStyle = clw;
|
|
ctx.fillStyle = clw;
|
|
ctx.beginPath();
|
|
ctx.arc(wR, wI, 1, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.strokeStyle = "#000000";
|
|
ctx.fillStyle = "#000000";
|
|
ctx.font = '5px serif';
|
|
ctx.fillText("Real axis", 65, -3);
|
|
ctx.rotate(Math.PI / 2);
|
|
ctx.fillText("Imaginary axis", 65, -3);
|
|
ctx.rotate(-Math.PI / 2);
|
|
ctx.beginPath();
|
|
ctx.moveTo(-3, 50);
|
|
ctx.lineTo(3, 50);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(-3, -50);
|
|
ctx.lineTo(3, -50);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(50, -3);
|
|
ctx.lineTo(50, 3);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(-50, -3);
|
|
ctx.lineTo(-50, 3);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(0, bottom - 100);
|
|
ctx.lineTo(0, 120);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(-150, 0);
|
|
ctx.lineTo(150, 0);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = clx;
|
|
ctx.beginPath();
|
|
ctx.moveTo(zR, zI);
|
|
ctx.lineTo(0, 0);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = clw;
|
|
ctx.beginPath();
|
|
ctx.moveTo(wR, wI);
|
|
ctx.lineTo(0, 0);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = clz;
|
|
ctx.beginPath();
|
|
ctx.moveTo(x2, y2);
|
|
ctx.lineTo(0, 0);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = clz;
|
|
ctx.fillStyle = clz;
|
|
ctx.beginPath();
|
|
ctx.arc(x2, y2, 1, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
setTimeout(Update, 1000/60)
|
|
}
|
|
|
|
window.addEventListener('resize', function(event) {
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
ctx.translate(c.width / 2, c.height / 2);
|
|
ctx.scale(3, 3);
|
|
}, true);
|
|
|
|
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> |