Skip to content

Instantly share code, notes, and snippets.

@thykka
Created July 23, 2020 14:16
Show Gist options
  • Select an option

  • Save thykka/542dafb3abcfef3d718ca30c5fa9cee2 to your computer and use it in GitHub Desktop.

Select an option

Save thykka/542dafb3abcfef3d718ca30c5fa9cee2 to your computer and use it in GitHub Desktop.
SCRIPT-8
init = state => {
const rndCount = (Math.random() * 8 | 0) + 2
state.path1 = randomPath(rndCount)
state.path2 = randomPath(rndCount)
}
function randomPath(points) {
return range(0, points).map(_ => ([Math.random() * 128 | 0, Math.random() * 128 | 0]))
}
update = (state, input, elapsed) => {
state.path1.forEach((point, i) => {
point[0] += Math.random() - 0.5
point[1] += Math.random() - 0.5
state.path2[i][0] += Math.random() - 0.5
state.path2[i][1] += Math.random() - 0.5
})
if(input.startPressed) { init(state) }
}
draw = state => {
clear()
polyStroke(state.path1, 0)
const paths = 16
for(let pathIndex = 0; pathIndex < paths; pathIndex++) {
polyStroke(state.path1.map((point, pointIndex) => ([
lerp(point[0], state.path2[pointIndex][0], pathIndex / paths),
lerp(point[1], state.path2[pointIndex][1], pathIndex / paths)
])), pathIndex / paths * 7 | 0)
}
polyStroke(state.path2, 6)
}
function lerp(a, b, f) {
return (a * (1 - f)) + (b * f);
}
{
"iframeVersion": "0.1.280",
"lines": [
36,
0,
0,
0,
0,
0,
0,
0
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment