Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active June 6, 2018 05:57
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/e27f1aa100ae32a3b06fbc6675f4e727 to your computer and use it in GitHub Desktop.
Save gabrielflorit/e27f1aa100ae32a3b06fbc6675f4e727 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: Trigo-4
/* eslint-disable no-global-assign */
initialState = {
x: 0
}
update = state => {
state.x += 0.01 * Math.PI
if (state.x > Math.PI) {
state.x = -Math.PI
}
}
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)
const r = 20
// draw sine
range(-0.5, 0.5, 0.01).forEach(i => {
const angle = i * 2 * Math.PI
const x = angle
const y = Math.sin(angle)
rectFill(o.x + r * x, o.y + r * y, 1, 1, 5)
})
// draw circle
range(-0.5, 0.5, 0.01).forEach(i => {
const angle = i * 2 * Math.PI
const x = Math.cos(angle)
const y = Math.sin(angle)
rectFill(o.x + r * x, o.y + r * y, 1, 1, 3)
})
// draw line
line(
o.x,
o.y + r * Math.sin(state.x),
o.x + r * Math.cos(state.x),
o.y + r * Math.sin(state.x),
2
)
// draw y marker
circFill(o.x, o.y + r * Math.sin(state.x), 2, 0)
// draw circle marker
circFill(o.x + r * Math.cos(state.x), o.y + r * Math.sin(state.x), 2, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment