Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active June 6, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielflorit/c092345895369a1214896dcfd7ac73c5 to your computer and use it in GitHub Desktop.
Save gabrielflorit/c092345895369a1214896dcfd7ac73c5 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: Trigo-9
/* eslint-disable no-global-assign */
const min = -20
const max = 0
const delta = 0.075
initialState = {
rd: 0,
rdd: -delta
}
update = (state, input) => {
state.rd += state.rdd
if (state.rd < min || state.rd > max) {
state.rdd *= 0
}
if (input.up) {
state.rdd = delta
}
if (input.down) {
state.rdd = -delta
}
}
draw = state => {
clear()
// origin
const o = { x: 64, y: 64 }
// radius
const r = 60
// const rd = -20
// compute points
const points = range(0, 3, 0.05).map(i => {
const angle = i * 2 * Math.PI
const x = o.x + (r + state.rd * i) * Math.cos(angle)
const y = o.y + (r + state.rd * i) * Math.sin(angle)
return [x, y]
})
// draw points
points.forEach((p, i, a) => {
if (i < a.length - 1) {
line(...p, ...a[i + 1], 4)
}
circFill(...p, 2, 0)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment