Last active
June 6, 2018 06:30
-
-
Save gabrielflorit/c092345895369a1214896dcfd7ac73c5 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-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