Added the rest of the files
This commit is contained in:
323
rainbow.html
Normal file
323
rainbow.html
Normal file
@@ -0,0 +1,323 @@
|
||||
<!--
|
||||
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: Rainbow
|
||||
</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>
|
||||
<label for="red">Red</label>
|
||||
<input type="checkbox" id="red" onclick="redClick()">
|
||||
<br>
|
||||
<label for="blue">Blue</label>
|
||||
<input type="checkbox" id="blue" onclick="blueClick()">
|
||||
<br>
|
||||
<label for="lines">Rainbow angle</label>
|
||||
<input type="checkbox" id="lines" onclick="linesClick()">
|
||||
</form>
|
||||
<div class="slidecontainer">
|
||||
<t>Ray density</t>
|
||||
<input type="range" min="0.25" max="2.5" value="0.5" step = "0.01" id="slider">
|
||||
<br>
|
||||
<t>X position</t>
|
||||
<input type="range" min="-120" max="120" value="0" step = "1" id="xSlider">
|
||||
<br>
|
||||
<t>Y position</t>
|
||||
<input type="range" min="-120" max="120" value="0" step = "1" id="ySlider">
|
||||
<br>
|
||||
<t>Zoom</t>
|
||||
<input type="range" min="-10" max="10" value="0" step = "1" id="zSlider">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var c = document.getElementById("myCanvas");
|
||||
var ctx = c.getContext("2d");
|
||||
ctx.canvas.width = window.innerWidth;
|
||||
ctx.canvas.height = window.innerHeight;
|
||||
|
||||
var nn = 1.35;
|
||||
var r = 75;
|
||||
var cl4 = "#ff0000";
|
||||
var cl17 = "#0000ff";
|
||||
var cl15 = "#000000";
|
||||
var red = false;
|
||||
var blue = false;
|
||||
var dtog = 0;
|
||||
var x0 = 0;
|
||||
var y0 = 0;
|
||||
var dy = 10;
|
||||
var nnn = 50;
|
||||
var xPos = 0;
|
||||
var yPos = 0;
|
||||
var slider = document.getElementById("slider");
|
||||
var xSlider = document.getElementById("xSlider");
|
||||
var ySlider = document.getElementById("ySlider");
|
||||
var density = 0.05;
|
||||
|
||||
slider.oninput = function()
|
||||
{
|
||||
density = this.value / 10;
|
||||
}
|
||||
|
||||
xSlider.oninput = function()
|
||||
{
|
||||
x0 = parseFloat(this.value);
|
||||
}
|
||||
|
||||
ySlider.oninput = function()
|
||||
{
|
||||
y0 = parseFloat(this.value);
|
||||
}
|
||||
|
||||
zSlider.oninput = function()
|
||||
{
|
||||
r = Math.pow(1.5, this.value) * 75;
|
||||
if (r < 50)
|
||||
{
|
||||
x0 = 2.5 * (50 - r);
|
||||
y0 = 1.8 * (50 - r);
|
||||
} else
|
||||
{
|
||||
x0 = 0;
|
||||
y0 = 0;
|
||||
}
|
||||
btog = 1;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
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);
|
||||
btog = 0;
|
||||
ctx.strokeStyle = "#000000";
|
||||
for (n = 0; n <= 101; n++)
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + x0 + r * Math.cos(Math.PI * n / nnn), yPos + y0 + r * Math.sin(Math.PI * n / nnn));
|
||||
ctx.lineTo(xPos + x0 + r * Math.cos(Math.PI * (n + 1) / nnn), yPos + y0 + r * Math.sin(Math.PI * (n + 1) / nnn));
|
||||
ctx.stroke();
|
||||
}
|
||||
for (h2 = 0; h2 <= 1; h2 += density)
|
||||
{
|
||||
if (red)
|
||||
{
|
||||
rline(r * h2, 1.332, cl4);
|
||||
}
|
||||
if (blue)
|
||||
{
|
||||
rline(r * h2, 1.35, cl17);
|
||||
}
|
||||
}
|
||||
if (btog == 1)
|
||||
{
|
||||
Clear(ctx);
|
||||
}
|
||||
if (dtog == 1)
|
||||
{
|
||||
//rline(r, 1.332, cl15);
|
||||
rrline(r, 1.332, cl15);
|
||||
//rline(r, 1.350, cl15);
|
||||
rrline(r, 1.350, cl15);
|
||||
}
|
||||
setTimeout(Update, 1000/60);
|
||||
}
|
||||
|
||||
function rline(h, nn, cl)
|
||||
{
|
||||
if (h < r)
|
||||
{
|
||||
th = Math.atan(h / Math.sqrt(Math.pow(r, 2) - Math.pow(h, 2)));
|
||||
} else
|
||||
{
|
||||
th = Math.PI / 2;
|
||||
}
|
||||
sth = h/r;
|
||||
thp = Math.atan(sth / nn / Math.sqrt(1 - sth * sth / nn / nn));
|
||||
console.log(thp);
|
||||
console.log(Math.asin(sth / nn));
|
||||
ctx.strokeStyle = cl;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-c.width, yPos + y0 + h);
|
||||
ctx.lineTo(xPos + x0 - Math.sqrt(r * r - h * h), yPos + y0 + h);
|
||||
ctx.stroke();
|
||||
xi1 = Math.PI + th - 2 * thp;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + x0 - r * Math.cos(xi1), yPos + y0 + r * Math.sin(xi1));
|
||||
ctx.lineTo(xPos + x0 - Math.sqrt(r * r - h * h), yPos + y0 + h);
|
||||
ctx.stroke();
|
||||
xi2 = th - 4 * thp;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + x0 - r * Math.cos(xi1), yPos + y0 + r * Math.sin(xi1));
|
||||
ctx.lineTo(xPos + x0 - r * Math.cos(xi2), yPos + y0 + r * Math.sin(xi2));
|
||||
ctx.stroke();
|
||||
xi3 = xi2 + th;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + x0 - r * Math.cos(xi2) - 350 * Math.cos(xi3), yPos + y0 + r * Math.sin(xi2) + 350 * Math.sin(xi3));
|
||||
ctx.lineTo(xPos + x0 - r * Math.cos(xi2), yPos + y0 + r * Math.sin(xi2));
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function rrline(h, nn, cl)
|
||||
{
|
||||
sthp = 1/3/nn*3 ** (1/2) * (4 - nn ** 2) ** (1/2);
|
||||
thp = Math.atan(sthp / Math.sqrt(1 - sthp ** 2));
|
||||
sth = nn * sthp;
|
||||
th = Math.atan(sth / Math.sqrt(1 - sth ** 2));
|
||||
xi3 = 2 * th - 4 * thp;
|
||||
sthp1 = 1/15/nn * 15 ** (1/2) * (16 - nn ** 2) ** (1/2);
|
||||
thp1 = Math.atan(sthp1 / Math.sqrt(1 - sthp1 ** 2));
|
||||
sth1 = nn * sthp1;
|
||||
th1 = Math.atan(sth1 / Math.sqrt(1 - sth1 ** 2));
|
||||
xi2 = th1 - 4 * thp1;
|
||||
ctx.strokeStyle = cl;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + x0 - r * Math.cos(xi2) - 30 * Math.cos(xi3), yPos + y0 + r * Math.sin(xi2) + 30 * Math.sin(xi3));
|
||||
ctx.lineTo(xPos + x0 - r * Math.cos(xi2) - 350 * Math.cos(xi3), yPos + y0 + r * Math.sin(xi2) + 350 * Math.sin(xi3));
|
||||
ctx.stroke();
|
||||
console.log(Math.cos(th), Math.cos(thp) * nn / 2)
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}, true);
|
||||
|
||||
document.onkeydown = checkKey;
|
||||
|
||||
function checkKey(e) {
|
||||
|
||||
e = e || window.event;
|
||||
|
||||
if (e.keyCode == '38') {
|
||||
yplus();
|
||||
}
|
||||
else if (e.keyCode == '40') {
|
||||
yminus();
|
||||
}
|
||||
else if (e.keyCode == '37') {
|
||||
xminus();
|
||||
}
|
||||
else if (e.keyCode == '39') {
|
||||
xplus();
|
||||
}
|
||||
else if (e.keyCode == '49') {
|
||||
//togglec();
|
||||
}
|
||||
else if (e.keyCode == '50') {
|
||||
toggled();
|
||||
}
|
||||
else if (e.keyCode == '51') {
|
||||
//togglee();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function redClick()
|
||||
{
|
||||
checkBox = document.getElementById("red");
|
||||
red = checkBox.checked;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
function blueClick()
|
||||
{
|
||||
checkBox = document.getElementById("blue");
|
||||
blue = checkBox.checked;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
function linesClick()
|
||||
{
|
||||
checkBox = document.getElementById("blue");
|
||||
dtog = 1 - dtog;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
function toggled()
|
||||
{
|
||||
console.log("toggled");
|
||||
dtog = 1 - dtog;
|
||||
btog = 1;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
function zoomPlus()
|
||||
{
|
||||
r *= 1.5;
|
||||
if (r < 50)
|
||||
{
|
||||
x0 = 2.5 * (50 - r);
|
||||
y0 = 1.8 * (50 - r);
|
||||
} else
|
||||
{
|
||||
x0 = 0;
|
||||
y0 = 0;
|
||||
}
|
||||
btog = 1;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
function zoomMinus()
|
||||
{
|
||||
r /= 1.5;
|
||||
if (r < 50)
|
||||
{
|
||||
x0 = 2.5 * (50 - r);
|
||||
y0 = 1.8 * (50 - r);
|
||||
} else
|
||||
{
|
||||
x0 = 0;
|
||||
y0 = 0;
|
||||
}
|
||||
btog = 1;
|
||||
Clear(ctx);
|
||||
}
|
||||
|
||||
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>
|
||||
Reference in New Issue
Block a user