Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active June 6, 2018 05:59
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/3054e952b5a3c1efdc3e9fecff78c0e9 to your computer and use it in GitHub Desktop.
Save gabrielflorit/3054e952b5a3c1efdc3e9fecff78c0e9 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: Trigo-7
/* eslint-disable no-global-assign */
const min = 0.05
const max = 0.25
initialState = {
d: min,
dd: 0.001
}
update = state => {
state.d += state.dd
if (state.d > max || state.d < min) {
state.dd *= -1
}
}
draw = state => {
clear()
// origin
const o = { x: 64, y: 64 }
// axes
line(o.x, 0, o.x, 128, 6)
line(0, o.y, 128, o.y, 6)
// radius
const r = 60
// compute points
const points = range(-0.5, 0.5, state.d).map(i => {
const angle = i * 2 * Math.PI
const x = o.x + r * Math.cos(angle)
const y = o.y + r * Math.sin(angle)
return [x, y]
})
// draw line
polyStroke(points, 3)
// draw points
points.forEach(p => {
circFill(...p, 2, 0)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment