Last active
August 20, 2024 22:47
-
-
Save wolfgangmeyers/904e78d4a96052232012f0d982bef259 to your computer and use it in GitHub Desktop.
Use with https://www.calligrapher.ai/ to automate handwriting of larger texts (paste into javascript console). Use text of any length. You will need to approve multiple downloads when running, but then it will download SVG handwriting of roughly evenly-sized chunks of text.
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
let text = `paste text of any size here`; | |
function splitIntoSegments(inputString) { | |
inputString = inputString.replace(/\n/g, " ") | |
const words = inputString.split(' '); | |
const segments = []; | |
let currentSegment = ''; | |
for (let word of words) { | |
// strip each word of whitespace | |
word = word.trim(); | |
if (word == '') { | |
continue; | |
} | |
if ((currentSegment + ' ' + word).length <= 50) { | |
currentSegment += (currentSegment ? ' ' : '') + word; | |
} else { | |
segments.push(currentSegment); | |
currentSegment = word; | |
} | |
} | |
if (currentSegment) { | |
segments.push(currentSegment); | |
} | |
return segments; | |
} | |
// sleep function that returns a promise based on setTimeout | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function config() { | |
// set speed-slider to 9.5 | |
const speedSlider = document.getElementById("speed-slider"); | |
speedSlider.value = 9.5; | |
// bias slider to 2.5 | |
const biasSlider = document.getElementById("bias-slider"); | |
biasSlider.value = 2.5; | |
// width slider to 1 | |
const widthSlider = document.getElementById("width-slider"); | |
widthSlider.value = 1; | |
// select-style (select dropdown) value to "5" | |
const selectStyle = document.getElementById("select-style"); | |
selectStyle.value = "19"; | |
} | |
async function dump(text) { | |
let segments = splitIntoSegments(text) | |
const textInput = document.getElementById("text-input") | |
config(); | |
for (let segment of segments) { | |
textInput.value = segment; | |
await sleep(100); | |
const writeButton = document.getElementById("draw-button"); | |
// writeButton.click(); | |
// trigger event instead: "mousedown" | |
writeButton.dispatchEvent(new Event('mousedown')); | |
await sleep(2000); | |
const downloadButton = document.getElementById("save-button"); | |
downloadButton.click(); | |
} | |
} | |
dump(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment