Make SVG Flowers

This describes creating flowers with 5,6,8,10 or 12 petals of different colors. This is an example:

flower2Text

This is the code:

<!DOCTYPE html>
<html>
<style>
svg{position: absolute;width:100%;height:100%; top: 40px; left: 0; background:aqua}
</style>
<body>
<center><input type=”text” id=”t3″ value = “” placeholder = “# petals (5 6 8 10 12)” /> <input type=”text” id=”t1″ value = “” placeholder = “size” /> <input type=”color” id=”clr1″ value=”#ffffff” /> <input type=”color” id=”clr2″ value=”#ffffbb” /> /> <input type=”button” id= “b1” value = “Undo” onclick=’undo();’ /> <input type=”text” id=”t2″ style=”width: 500px” value=”” ondblclick=’getCode();’/></center>
<svg id=”svg1″></svg>
<script>
var posX; var posY; var l; var l2; var l3; var svgstr = “”; var back = “”; var rot = []; var no; var cnt = -1; var rot5 = [“0deg”,”72deg”,”144deg”,”216deg”,”288deg”]; var rot6 = [“0deg”,”60deg”,”120deg”,”180deg”,”240deg”,”300deg”]; var rot8 = [“0deg”,”45deg”,”90deg”,”135deg”,”180deg”,”225deg”,”270deg”,”315deg”]; var rot10 = [“36deg”,”72deg”,”108deg”,”144deg”,”180deg”,”216deg”,”242deg”,”288deg”,”324deg”]; var rot12 = [“0deg”,”30deg”,”60deg”,”90deg”,”120deg”,”150deg”,”180deg”,”210deg”,”240deg”,”270deg”,”300deg”,”330deg”]; var cnto = 1; var noini = 1;

document.getElementById(“svg1”).onclick = getMouse2;

function getMouse2(e) {
ret = [] ;
cnt = cnto – 2;
posX = e.pageX ;
posY = e.pageY – 25;
no = parseInt(document.getElementById(“t3”).value);
if (no == 5) rot = rot5;
if (no == 6) rot = rot6;
if (no == 8) rot = rot8;
if (no == 10) rot = rot10;
if (no == 12) rot = rot12;

back = document.getElementById(“svg1”).innerHTML;
l = parseInt(document.getElementById(“t1”).value) /2;n
l2 = parseInt(l) * 2.5/no ;
if (no == 5) l2 = parseInt(l) * 2/no ;
if (no == 6) l2 = parseInt(l) * 2.2/no ;
var l3 = l2 * 1.5;
l2 += “”;
l3 += “”;

var str = posX + “px ” + posY + “px”;
for (var i = noini; i <= no + noini – 1; i ++) {
cnt += 2;

document.getElementById(“svg1″).innerHTML += ‘<g id=”g’ + i + ‘”><ellipse id=”e’ + cnt + ‘” rx=”0″ ry=”80″ fill = “none” stroke=”black” stroke-width= “3” /><ellipse id=”e’ + (cnt + 1) + ‘” rx=”0″ ry=”80″ fill=”#ffff99″ /></g>’;
document.getElementById(“g” + i).style.transformOrigin = str;

document.getElementById(“g” + i).style.transform = “rotate(” + rot[i – noini] + “)”;
}
document.getElementById(“svg1″).innerHTML += ‘<ellipse id=”e’ + (cnt + 2) + ‘” rx=”0″ ry=”40″ fill=”brown” />’;
noini += no;

for (var i = cnto; i <= (cnt + 1); i ++) {
document.getElementById(“e” + i).setAttribute(“cx”, posX);
document.getElementById(“e” + i).setAttribute(“cy”, posY – parseInt(l));
document.getElementById(“e” + i).setAttribute(“rx”, l2);
document.getElementById(“e” + i).setAttribute(“ry”, l);
document.getElementById(“e” + i).setAttribute(“fill”, document.getElementById(“clr2”).value);
}

document.getElementById(“e” + (cnt + 2)).setAttribute(“rx”, l3);
document.getElementById(“e” + (cnt + 2)).setAttribute(“ry”, l3);
document.getElementById(“e” + (cnt + 2)).setAttribute(“cy”, posY + “px”);
document.getElementById(“e” + (cnt + 2)).setAttribute(“cx”, posX + “px”);

cnto = i + 1;
document.getElementById(“svg1”).style.backgroundColor = document.getElementById(“clr1”).value;
document.getElementById(“svg1”).innerHTML = svgstr + document.getElementById(“svg1”).innerHTML;
svgstr = document.getElementById(“svg1”).innerHTML;
document.getElementById(“t2”).value = document.getElementById(“svg1”).innerHTML;
document.getElementById(“t2”).focus();
document.getElementById(“t2”).select();
success = document.execCommand(“copy”);
}

function undo() {
svgstr = “”;
document.getElementById(“svg1”).innerHTML = back;
document.getElementById(“t2”).value = document.getElementById(“svg1”).innerHTML;
document.getElementById(“t2”).focus();
document.getElementById(“t2”).select();
success = document.execCommand(“copy”);
}

</script>
</body></html>

The flowers are created with a brown circle center and petals made of ellipses embedded in g elements:
cnt += 2;
for (var i = noini; i <= no + noini – 1; i ++) {
document.getElementById(“svg1″).innerHTML += ‘<g id=”g’ + i + ‘”><ellipse id=”e’ + cnt + ‘” rx=”0″ ry=”80″ fill = “none” stroke=”black” stroke-width= “3” /><ellipse id=”e’ + (cnt + 1) + ‘” rx=”0″ ry=”80″ fill=”#ffff99″ /></g>’;

The are placed by rotation according to the number of petals, this is for 8 petals:
var rot8 = [“0deg”,”45deg”,”90deg”,”135deg”,”180deg”,”225deg”,”270deg”,”315deg”];
document.getElementById(“g” + i).style.transformOrigin = str;

document.getElementById(“g” + i).style.transform = “rotate(” + rot[i – noini] + “)”;

The flowers are placed with an onclick listener:

document.getElementById(“svg1”).onclick = getMouse2;

function getMouse2(e) {
ret = [] ;
cnt = cnto – 2;
posX = e.pageX ;
posY = e.pageY – 25;
no = parseInt(document.getElementById(“t3”).value);
if (no == 5) rot = rot5;
if (no == 6) rot = rot6;
if (no == 8) rot = rot8;
if (no == 10) rot = rot10;
if (no == 12) rot = rot12;

Drop Shadows for SVG Elements

This app takes solid svg elements and adds a drop shadow.
Here are some examples:svgShadowTextsvgShadowText2svgShadowText3svgShadowText4

This is the code:

<!DOCTYPE HTML>
<html>
  <style>
body{background: black}
    
  </style>
<body>
<input type=”color” id=”clr1″/>  <select id=”s1″  onchange=’go();’><option>element</option><option>round rect</option><option>ellipse</option><option>polygon</option><option>path</option></select> <input type = “text” id=”t1″ style = “width: 400px” value=”” ondblclick=’makeShadow();’ />
<svg id=”svg1″ style = “position: absolute; left: 50%; margin-left: -300px; width: 600px; height: 600px; top: 50px; background:#eeffee”></svg>
<script>
var sel = document.getElementById(“s1”); var sg = document.getElementById(“svg1”); cl = document.getElementById(“clr1”); var ini = “”;

function go() {
if (sel.value == “round rect”) sg.innerHTML = ‘<rect id=”ell1″ x=”150″ y=”100″ rx=”10″ ry=”10″ width=”300″ height=”200″ style=”fill:’ + cl.value + ‘ ; stroke:none” />’;
if (sel.value == “ellipse”) sg.innerHTML = ‘<ellipse id=”ell1″ cx = “300” cy=”250″ rx=”150″ ry=”125″ style=”fill:’ + cl.value + ‘ ; stroke:none” />’;

if (sel.value == “polygon”) {
var ang = 0; var anginc = 2*Math.PI / 5; var rad = 150; var iniX = 300; var iniY = 300; var pent = “”; var px; var py;
ini  = ‘<polygon id=”ell1″ points=”‘;
for (var i = 0; i <= 4; i ++) {
ang += anginc;
px = iniX + parseInt(rad * Math.sin(ang));
py = iniY + parseInt(rad * Math.cos(ang));
ini += px + “,” + py + ” “;
}
ini += ‘” style=”fill:’ + cl.value + ‘;stroke:none” />’;
setTimeout(“disply(),1000”);
}

if (sel.value == “path”) sg.innerHTML = ‘<path id=”ell1″ fill=”‘ + cl.value + ‘” transform = “translate(100 20)” d=”M 214,115 C 214,115 241,137 268,165 287,190 289,222 289,256 283,292 274,322 249,351 228,370 201,383 170,375 145,353 122,328 107,297 97,259 89,229 99,187 111,154 127,131 154,123 184,116 184,116 184,116 184,116 214,115 214,115 Z”></path>’;
}

function disply() {
sg.innerHTML = ini;
}
 function makeShadow() {
 document.getElementById(“ell1”).style.filter = document.getElementById(“t1”).value;
 }
</script>
</body></html>

To add a drop filter it is necessary for the element to have a fill.

The function go() creates the elements and disply() shows them:
function go() {
if (sel.value == “round rect”) sg.innerHTML = ‘<rect id=”ell1″ x=”150″ y=”100″ rx=”10″ ry=”10″ width=”300″ height=”200″ style=”fill:’ + cl.value + ‘ ; stroke:none” />’;
if (sel.value == “ellipse”) sg.innerHTML = ‘<ellipse id=”ell1″ cx = “300” cy=”250″ rx=”150″ ry=”125″ style=”fill:’ + cl.value + ‘ ; stroke:none” />’;

if (sel.value == “polygon”) {
var ang = 0; var anginc = 2*Math.PI / 5; var rad = 150; var iniX = 300; var iniY = 300; var pent = “”; var px; var py;
ini  = ‘<polygon id=”ell1″ points=”‘;
for (var i = 0; i <= 4; i ++) {
ang += anginc;
px = iniX + parseInt(rad * Math.sin(ang));
py = iniY + parseInt(rad * Math.cos(ang));
ini += px + “,” + py + ” “;
}
ini += ‘” style=”fill:’ + cl.value + ‘;stroke:none” />’;
setTimeout(“disply(),1000”);
}

if (sel.value == “path”) sg.innerHTML = ‘<path id=”ell1″ fill=”‘ + cl.value + ‘” transform = “translate(100 20)” d=”M 214,115 C 214,115 241,137 268,165 287,190 289,222 289,256 283,292 274,322 249,351 228,370 201,383 170,375 145,353 122,328 107,297 97,259 89,229 99,187 111,154 127,131 154,123 184,116 184,116 184,116 184,116 214,115 214,115 Z”></path>’;
}
function disply() {
sg.innerHTML = ini;
}

Double clicking a text box with the shadow string adds ther shadow:
function makeShadow() {
 document.getElementById(“ell1”).style.filter = document.getElementById(“t1”).value;
 }

Colorize B&W Images with SVG

I had previosly posted an app to colorize b&w images using jsDraw2D. This does the same with plain svg. Here is an example:svgColorizeText

It does it by blending filled paths with the original b&w image for shading.

The fill color can be changed for any path by double clicking a color dialog.
The blending can be adjusted by altyering the brightness of the b&w image.

This is the code:

<!DOCTYPE HTML>
<html>
<style>
bo
#path0{}
</style>
<body>
  <center><select id=”s2″ ><option>Folder</option><option></option><option>A-E/</option><option>F-J/</option><option>K-O/</option><option>P-R/</option><option>S-T/</option></select> <input type=”file” id = “file1″ onchange=’ld();’/> <select id=”s1″><option>Action</option><option>Brightness</option><option>Contrast</option><option>Black BK</option><option>White BK</option><option>Size</option></select> <input type=”text” id=”t1″ style = “width: 400px” ondblclick=’sve();’/> <input type=”color” id=”clr1″ ondblclick=’colr();’ /></center>
<div id=”frame” style=”position: absolute;width:100%;height:1000px;left:0;top:40px; background:white”>
<svg id=”svg1″ style=”position: absolute; left: 10px; top: 0px; width: 100%; height:100%; filter: saturate(250%)”></svg>
<img id = “im1” src = “” style=”position: absolute; height: 680px; left: 10px; top: 0px; filter:grayscale(100%) brightness(100%) contrast(100%)” />
</div>
<script>
var posX; var posY; var cnt = -1; var px = []; var py = []; var str = “”; var cnt2 = -1; var bright = 100; var cont = 100; var sz; var fl; var oldURL = “svgColor.html”;

function ld() {
fl = document.getElementById(“file1”).value;
document.getElementById(“t1”).value = fl;
if (fl.indexOf(“fakepath”) != -1) fl = fl.substr(12);
document.getElementById(“t1″).value += ”  ” + fl;
fl = document.getElementById(“s2”).value + fl;
document.getElementById(“t1″).value += ”  ” + fl;
im1.src = fl;
setTimeout(‘sze()’,500);
}

function sze() {
  sz = im1.clientHeight;
document.getElementById(“svg1”).style.width = im1.clientWidth;
document.getElementById(“svg1”).style.height = im1.clientHeight;
}
document.getElementById(“im1”).onclick= setPoints;
document.onkeydown = fin;

function setPoints(e) {
posX = e.pageX – 10;
posY = e.pageY – 40;
cnt ++;
px[cnt] = posX;
py[cnt] = posY;
if (cnt == 0) {
  cnt2 ++;
  document.getElementById(“im1”).style.opacity = “.5”;
  str += ‘<path id = “path’ + cnt2 + ‘” fill=”‘ + document.getElementById(“clr1″).value + ‘” d = “M ‘ + px[0] + ‘,’ + py[0] + ‘ C ‘ + px[0] + ‘,’ + py[0] + ‘ ‘;
}
if (cnt > 0) str += px[cnt] + ‘,’ + py[cnt] + ‘ ‘;
document.getElementById(“svg1″).innerHTML += ‘<ellipse cx=”‘+ posX + ‘” cy =”‘ + posY + ‘” rx = “2” ry = “2” fill=”#000000″ /> ‘;
}

function fin(e) {
var sel = document.getElementById(“s1”).value;
if (e.keyCode == 17) {
if (sel == “Black BK”) document.getElementById(“frame”).style.backgroundColor = “black”;
if (sel == “White BK”) document.getElementById(“frame”).style.backgroundColor = “white”;
}

if (e.keyCode == 18) {
document.getElementById(“im1”).style.opacity = “.7”;
str += px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[0] + ‘,’ + py[0] + ‘ ‘  + px[0] + ‘,’ + py[0] + ‘ Z” />’;
document.getElementById(“svg1”).innerHTML = “”;
document.getElementById(“svg1”).innerHTML += str;
document.getElementById(“t1”).value = document.getElementById(“svg1”).innerHTML;
cnt = -1;
}

if (e.keyCode == 187) {
if (sel == “Brightness”) {
  bright += 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}
if (sel == “Contrast”) {
  cont += 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}

}

if (e.keyCode == 189) {
if (sel == “Brightness”) {
  bright -= 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}
if (sel == “Contrast”) {
  cont -= 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}

if (sel == “Size”) {
 sz -=2;
document.getElementById(“im1”).style.height = sz + “px”;
document.getElementById(“svg1”).style.height = document.getElementById(“im1”).style.height;
}
}
}

function colr() {
if (cnt2 > -1) document.getElementById(“path” + cnt2).setAttribute(“fill”, document.getElementById(“clr1”).value);
str = document.getElementById(“svg1”).innerHTML;
document.getElementById(“t1”).value = document.getElementById(“svg1”).innerHTML;
}

function sve() {
  var textToSave = ‘<!DOCTYPE HTML> <html> <body> ‘ + document.getElementById(“frame”).innerHTML + ‘ </body></html>’;
  document.getElementById(“t1”).value = textToSave;
  var textToSaveAsBlob = new Blob([textToSave], {type:”text/plain”});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
fileNameToSaveAs = prompt(“FileName to save as”,oldURL);
oldURL = fileNameToSaveAs;
var downloadLink = document.createElement(“a”);
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = “Download File”;
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = “none”;
document.body.appendChild(downloadLink);
downloadLink.click();
}

function destroyClickedElement(event) {
document.body.removeChild(event.target);
}

</script>
</body></html>

The function ld() loads the image chosen by a file input.
on loading a function called sze() is called which sets the svg element to the same size as the image:
setTimeout(‘sze()’,500);

function sze() {
  sz = im1.clientHeight;
document.getElementById(“svg1”).style.width = im1.clientWidth;
document.getElementById(“svg1”).style.height = im1.clientHeight;
}

onclick and keydown are checked:
document.getElementById(“im1”).onclick= setPoints;
document.onkeydown = fin;

Since tghe image sits on top of the svg, it is that which is checked, calling  setPoints(e):
function setPoints(e) {
posX = e.pageX – 10;
posY = e.pageY – 40;
cnt ++;
px[cnt] = posX;
py[cnt] = posY;
if (cnt == 0) {
  cnt2 ++;
  document.getElementById(“im1”).style.opacity = “.5”;
  str += ‘<path id = “path’ + cnt2 + ‘” fill=”‘ + document.getElementById(“clr1″).value + ‘” d = “M ‘ + px[0] + ‘,’ + py[0] + ‘ C ‘ + px[0] + ‘,’ + py[0] + ‘ ‘;
}
if (cnt > 0) str += px[cnt] + ‘,’ + py[cnt] + ‘ ‘;
document.getElementById(“svg1″).innerHTML += ‘<ellipse cx=”‘+ posX + ‘” cy =”‘ + posY + ‘” rx = “2” ry = “2” fill=”#000000″ /> ‘;
}
This creates small filled circles whereever the image is clicked.

keydown calls a function fin(e):

if the alt key is pressed, the path is completed:
if (e.keyCode == 18) {
document.getElementById(“im1”).style.opacity = “.7”;
str += px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[cnt] + ‘,’ + py[cnt] + ‘ ‘ + px[0] + ‘,’ + py[0] + ‘ ‘  + px[0] + ‘,’ + py[0] + ‘ Z” />’;
document.getElementById(“svg1”).innerHTML = “”;
document.getElementById(“svg1”).innerHTML += str;
document.getElementById(“t1”).value = document.getElementById(“svg1”).innerHTML;
cnt = -1;
}

The rest depend on the value of a select element:
if (e.keyCode == 17) {
if (sel == “Black BK”) document.getElementById(“frame”).style.backgroundColor = “black”;
if (sel == “White BK”) document.getElementById(“frame”).style.backgroundColor = “white”;
}
If ctrl is pressed the page background is made either black or white.

187 and 189 are the + and – keys.
They change either the size, brightness or contrast of the b&w image:
if (e.keyCode == 187) {
if (sel == “Brightness”) {
  bright += 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}
if (sel == “Contrast”) {
  cont += 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}

}

if (e.keyCode == 189) {
if (sel == “Brightness”) {
  bright -= 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}
if (sel == “Contrast”) {
  cont -= 2;
document.getElementById(“im1”).style.filter = “grayscale(100%) brightness(” + bright + “%) contrast(” + cont + “%) “;
}

if (sel == “Size”) {
 sz -=2;
document.getElementById(“im1”).style.height = sz + “px”;
document.getElementById(“svg1”).style.height = document.getElementById(“im1”).style.height;
}
}

The size can only be decreased interactively.
Double clicking the color input changes the fill of the current path:
function colr() {
if (cnt2 > -1) document.getElementById(“path” + cnt2).setAttribute(“fill”, document.getElementById(“clr1”).value);
str = document.getElementById(“svg1”).innerHTML;
document.getElementById(“t1”).value = document.getElementById(“svg1”).innerHTML;
}

There is also a text input which lists the innerHTML of the svg and which on double clicking saves to a file:
function sve() {
  var textToSave = ‘<!DOCTYPE HTML> <html> <body> ‘ + document.getElementById(“frame”).innerHTML + ‘ </body></html>’;
  document.getElementById(“t1”).value = textToSave;
The rest of sve() has been discussed before.

View Youtube Videos in 3d

This app allows the viewing of Youtube videos in 3d.
It involves getting the embed code of the video and using the url to view the video in an iframe.
A caveat: for most videos this file must be run from a server of simulated server, or a Video Unavailable message is obtained.

This is the code:

<html>
<body>
<div id=”frame” style = “position: absolute; width: 100%; height: 100%; top: 40px; background:black” ></div>
<select id= “s1″ onchange=’strt();’><option>Choose File</option><option>Roller Coaster</option><option>White Water</option><option>Toboggan</option><option>Scuba Diving</option><option>Honeymooners</option><option>Dick Van Dyke</option><option>Skiing</option></select> <input type=”text” id=”t1″ value = “” placeholder=”rotate (default: 22)” />
<script>
var param = ‘<iframe id=”if1″ frameborder=”0″ allow=”accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share”‘; var ht; var wd; var rotat; var cnt = 0; var si; var a; var b;
function strt() {
var choice = document.getElementById(“s1”).value;
if (choice == “Roller Coaster”) param += ‘src=”https://www.youtube.com/embed/oAJLKDMihnU&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “White Water”) param += ‘src=”https://www.youtube.com/embed/DXFehwLKO6I&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Toboggan”) param += ‘src=”https://www.youtube.com/embed/oRzs-HaRP_c&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Scuba Diving”) param += ‘src=”https://www.youtube.com/embed/bNucJgetMjE&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Honeymooners”) param += ‘src=”https://www.youtube.com/embed/em1DEwOtm3I&#8221; width = “665 “; height = “499 ” ></iframe>’;
if (choice == “Dick Van Dyke”) param += ‘src=”https://www.youtube.com/embed/jNXxWXBShFk&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Skiing”) param += ‘src=”https://www.youtube.com/embed/fbqHK8i-HdA&#8221; width = “887 “; height = “499 ” ></iframe>’;
a = param.indexOf(‘width = “‘);
wd = parseInt(param.substr(a + 9, 4));
a = param.indexOf(‘height = “‘);
ht = parseInt(param.substr(a + 9, 4));
document.getElementById(“frame”).innerHTML = param;
document.getElementById(“if1”).style.width = wd + “px”;
document.getElementById(“if1”).style.height = ht + “px”;
document.getElementById(“if1”).style.transform = “webkitRotateY(30deg)”;
document.getElementById(“if1”).style.transform = “rotateY(30deg)”;
rotat = (22 * (400 / wd)) + “deg”;
setTimeout(“go()”,10000);
}

function go(){
si = setInterval(“rot()”, 200);
}

function rot() {
if (document.getElementById(“t1”).value != “”) rotat = (parseInt(document.getElementById(“t1”).value) * (400 / wd)) + “deg”;
cnt ++;
if (cnt % 2 == 1) {
document.getElementById(“if1”).style.transform = “webkitRotateY(” + rotat + “)”;
document.getElementById(“if1”).style.transform = “rotateY(” + rotat + “)”;
} else {
document.getElementById(“if1”).style.transform = “webkitRotateY(0deg)”;
document.getElementById(“if1”).style.transform = “rotateY(0deg)”;
}
if (cnt == 10) cnt = 0;
}
</script>
</body></html>

A select element is set up:
<select id= “s1” onchange=’strt();’><option>Choose File</option><option>Roller Coaster</option><option>White Water</option><option>Toboggan</option><option>Scuba Diving</option><option>Honeymooners</option><option>Dick Van Dyke</option><option>Skiing</option></select>

var choice = document.getElementById(“s1”).value;
if (choice == “Roller Coaster”) param += ‘src=”https://www.youtube.com/embed/oAJLKDMihnU&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “White Water”) param += ‘src=”https://www.youtube.com/embed/DXFehwLKO6I&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Toboggan”) param += ‘src=”https://www.youtube.com/embed/oRzs-HaRP_c&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Scuba Diving”) param += ‘src=”https://www.youtube.com/embed/bNucJgetMjE&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Honeymooners”) param += ‘src=”https://www.youtube.com/embed/em1DEwOtm3I&#8221; width = “665 “; height = “499 ” ></iframe>’;
if (choice == “Dick Van Dyke”) param += ‘src=”https://www.youtube.com/embed/jNXxWXBShFk&#8221; width = “887 “; height = “499 ” ></iframe>’;
if (choice == “Skiing”) param += ‘src=”https://www.youtube.com/embed/fbqHK8i-HdA&#8221; width = “887 “; height = “499 ” ></iframe>’;

The URL is loaded and the iframe set to the video size:
a = param.indexOf(‘width = “‘);
wd = parseInt(param.substr(a + 9, 4));
a = param.indexOf(‘height = “‘);
ht = parseInt(param.substr(a + 9, 4));
document.getElementById(“frame”).innerHTML = param;
document.getElementById(“if1”).style.width = wd + “px”;
document.getElementById(“if1”).style.height = ht + “px”;

A time delay allows the clicking of the Youtube play:
setTimeout(“go()”,10000);

The amount of rotation is set:
rotat = (22 * (400 / wd)) + “deg”;

function go() sets up the Yrotation:
function go(){
si = setInterval(“rot()”, 200);
}

function rot() {
if (document.getElementById(“t1”).value != “”) rotat = (parseInt(document.getElementById(“t1”).value) * (400 / wd)) + “deg”;
cnt ++;
if (cnt % 2 == 1) {
document.getElementById(“if1”).style.transform = “webkitRotateY(” + rotat + “)”;
document.getElementById(“if1”).style.transform = “rotateY(” + rotat + “)”;
} else {
document.getElementById(“if1”).style.transform = “webkitRotateY(0deg)”;
document.getElementById(“if1”).style.transform = “rotateY(0deg)”;
}
if (cnt == 10) cnt = 0;
}

The rotation is adjustable; More rotation gives a greater effect but too much can be distracting.
Since the rotationm is interactively controlled, it can be customized for each video to give the best compromise.