Last active
June 6, 2018 05:55
-
-
Save gabrielflorit/369104b7b4bec92463cb8f8ac92dab66 to your computer and use it in GitHub Desktop.
SCRIPT-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// title: Trigo-3 | |
/* 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, 4) | |
}) | |
// draw axes marker lines | |
line( | |
o.x + r * state.x, | |
o.y + r * Math.sin(state.x), | |
o.x, | |
o.y + r * Math.sin(state.x), | |
1 | |
) | |
line( | |
o.x + r * state.x, | |
o.y + r * Math.sin(state.x), | |
o.x + r * state.x, | |
o.y, | |
1 | |
) | |
// draw axes markers | |
circFill(o.x + r * state.x, o.y, 2, 0) | |
circFill(o.x, o.y + r * Math.sin(state.x), 2, 0) | |
// draw marker | |
circFill(o.x + r * state.x, o.y + r * Math.sin(state.x), 1, 7) | |
circStroke(o.x + r * state.x, o.y + r * Math.sin(state.x), 2, 0) | |
print(0, 0, 'sine', 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment