From 13b3d3514a7c11102e401ecb1ef8f7873088b42a Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Fri, 28 Jul 2023 17:39:57 +1000 Subject: [PATCH] broken --- main.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 31171d5..4f437b6 100644 --- a/main.js +++ b/main.js @@ -83,6 +83,43 @@ function rotXY(theta) { +function fallbackCopyTextToClipboard(text) { + var textArea = document.createElement("textarea"); + textArea.value = text; + + // Avoid scrolling to bottom + textArea.style.top = "0"; + textArea.style.left = "0"; + textArea.style.position = "fixed"; + + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + try { + var successful = document.execCommand('copy'); + var msg = successful ? 'successful' : 'unsuccessful'; + console.log('Fallback: Copying text command was ' + msg); + } catch (err) { + console.error('Fallback: Oops, unable to copy', err); + } + + document.body.removeChild(textArea); +} + + +function copyTextToClipboard(text) { + if (!navigator.clipboard) { + fallbackCopyTextToClipboard(text); + return; + } + navigator.clipboard.writeText(text).then(function() { + console.log('Async: Copying to clipboard was successful!'); + }, function(err) { + console.error('Async: Could not copy text: ', err); + }); +} + @@ -162,9 +199,16 @@ function createShape(name) { } - - -createShape(DEFAULT_SHAPE); +function floatParam(linkUrl, param) { + const value = linkUrl.searchParams(param); + if( value ) { + const fl = parseFloat(value); + if( fl !== NaN ) { + return fl; + } + } + return 0; +} camera.position.z = 4; @@ -213,14 +257,32 @@ renderer.domElement.addEventListener("pointerup", (event) => { const gui = new GUI(); +const linkUrl = new URL(window.location.toLocaleString()); + +const linkparams = {}; + const gui_params = { shape: DEFAULT_SHAPE, hyperplane: 2, xRotate: 'YW', yRotate: 'XZ', - damping: false + damping: false, + copylink: function () { + const url = + } }; +for( const param in [ "shape", "hyperplane", "xRotate", "yRotate", "damping" ]) { + const value = linkUrl.searchParams(param); + if( value ) { + gui_params[param] = value; + } +} + +dpsi = floatParam(linkUrl, 'dpsi'); +dtheta = floatParam(linkUrl, 'dtheta'); + + gui.add(gui_params, 'shape', [ '5-cell', '16-cell', 'tesseract', '24-cell', '120-cell', '600-cell' ] ).onChange(createShape) @@ -229,6 +291,7 @@ gui.add(gui_params, 'hyperplane', 1.5, 4); gui.add(gui_params, 'xRotate', [ 'YW', 'YZ', 'ZW' ]); gui.add(gui_params, 'yRotate', [ 'XZ', 'XY', 'XW' ]); gui.add(gui_params, 'damping'); +gui.add() const ROTFN = { XY: rotXY, @@ -241,6 +304,9 @@ const ROTFN = { +createShape(gui_params["shape"]); + + const rotation = new THREE.Matrix4(); function animate() {