Skip to content

Commit

Permalink
screenshot button
Browse files Browse the repository at this point in the history
  • Loading branch information
parameterized committed Aug 30, 2024
1 parent b128415 commit 8438cb4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
state.pause = !state.pause
},
step,
save: () => {
"save as html": () => {
const sauceWithState = sauce.replace(
/(?<=const state = ).*/,
`JSON.parse('${JSON.stringify(state)}')`
Expand All @@ -84,6 +84,16 @@
a.setAttribute("download", `${state.guiParams.filename}.html`)
a.click()
},
"save as png": () => {
const screenshotData = canvas.elt.toDataURL("image/png").replace(
"image/png",
"image/octet-stream"
)
const a = document.createElement("a")
a.setAttribute("href", screenshotData)
a.setAttribute("download", `${state.guiParams.filename}.png`)
a.click()
}
}

const gui = new lil.GUI()
Expand Down

0 comments on commit 8438cb4

Please sign in to comment.