Last active
April 11, 2024 22:21
-
-
Save jadeallencook/8c0a99cf11437db2bbca4dae66cb8833 to your computer and use it in GitHub Desktop.
This script automatically captures and logs the positional changes of Adobe's San Jose Semaphore discs in real-time, stops after reaching a predefined limit, and exports the logged data for further analysis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adobe Semaphore Data Capture | |
Author: @jadeallencook | |
Date: May 13, 2023 | |
This script captures the position sequences of the semaphore wheels from the Adobe Semaphore public art installation. | |
The script queries the semaphore's website, maps the transform styles of the wheel elements to their positions, | |
and stores the sequences of positions in an array. The script logs every captured sequence, and logs the progress | |
every 10 sequences. Once the script has captured a predetermined maximum number of sequences, it logs the entire | |
array of sequences and stops the capturing process. | |
|: 1 | |
/: 2 | |
-: 3 | |
\: 4 | |
https://www.adobe.com/about-adobe/visit-us/sj-semaphore.html | |
*/ | |
// Mapping of matrix transforms to wheel positions | |
const positions = { | |
'matrix(-1, 0, 0, -1, 0, 0)': 1, | |
'matrix(0.707107, 0.707107, -0.707107, 0.707107, 0, 0)': 2, | |
'matrix(0, -1, 1, 0, 0, 0)': 3, | |
'matrix(0.707107, -0.707107, 0.707107, 0.707107, 0, 0)': 4, | |
'matrix(1, 0, 0, 1, 0, 0)': 1, | |
'matrix(-0.707107, -0.707107, 0.707107, -0.707107, 0, 0)': 2, | |
'matrix(0, 1, -1, 0, 0, 0)': 3, | |
'matrix(-0.707107, 0.707107, -0.707107, -0.707107, 0, 0)': 4 | |
} | |
// Query the container of the semaphore wheels | |
const container = document.querySelector('.css-1q7ngnn'); | |
// Get all the wheel elements | |
const wheels = [...container.childNodes]; | |
// Array to store the sequences of wheel positions | |
const stream = []; | |
// Counter for the number of captured sequences | |
let numberOfSequences = 0; | |
// Maximum number of sequences to capture | |
let maxNumberOfSequences = 3000; | |
// Function to get the position of a wheel | |
const getWheelPosition = (wheel) => { | |
const string = window.getComputedStyle(wheel).transform; | |
return positions[string] || 0; | |
} | |
// Function to update the stream with a new sequence of wheel positions | |
const updateStream = (data) => { | |
// If the sequence is the same as the last sequence in the stream, do nothing | |
if (JSON.stringify(data) === JSON.stringify(stream.at(-1) || [])) { | |
return; | |
} | |
// Otherwise, push the sequence to the stream and increment the counter | |
stream.push(data); | |
numberOfSequences++; | |
console.log(`CAPTURED: [${data.join(', ')}]`); | |
// Every 10 sequences, log the progress | |
if (!(numberOfSequences % 10)) { | |
console.log(`PROGRESS: ${numberOfSequences}/${maxNumberOfSequences}`); | |
} | |
// If the counter reaches the maximum, log the entire stream and stop the process | |
if (numberOfSequences === maxNumberOfSequences) { | |
console.log(`EXPORT: ${JSON.stringify(stream)}`); | |
clearInterval(process); | |
} | |
} | |
// Start a process to capture wheel positions every 500 ms | |
const process = setInterval(() => { | |
// Map the wheels to their positions | |
const data = wheels.map(wheel => getWheelPosition(wheel)); | |
// If no wheel position is 0 (not recognized), update the stream with the new sequence | |
if (!data.includes(0)) { | |
updateStream(data); | |
} | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment