Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Forked from nekonesse/README.md
Last active April 20, 2020 04:12
Show Gist options
  • Save gabrielflorit/5a081b9009dcca2ea47f93f0c7e05596 to your computer and use it in GitHub Desktop.
Save gabrielflorit/5a081b9009dcca2ea47f93f0c7e05596 to your computer and use it in GitHub Desktop.
SCRIPT-8
init = state => {}
update = (state, input, elapsed) => {}
// Circle parametric equation.
// Given an angle and radius, find xy.
const xy = ({ angle, radius, origin }) => {
const x = origin.x + radius * Math.cos(angle)
const y = origin.y + radius * Math.sin(angle)
return { x, y }
}
// Draw a polygon, given sides, radius, and origin.
const drawPolygon = ({ sides, radius, origin }) => {
const points = range(sides).map(i => {
const angle = i * ((2 * Math.PI) / sides)
const { x, y } = xy({ angle, radius, origin })
return [x, y]
})
polyStroke(points, 0)
}
draw = state => {
const radius = 28
const origin = { x: 64, y: 64 }
clear()
rectStroke(0, 0, 128, 128, 5)
drawPolygon({ sides: 3, radius, origin: { x: radius * 1.0, y: radius * 1.0 } })
drawPolygon({ sides: 4, radius, origin: { x: radius * 3.5, y: radius * 1.0} })
drawPolygon({ sides: 5, radius, origin: { x: radius * 1.0, y: radius * 3.5 } })
drawPolygon({ sides: 6, radius, origin: { x: radius * 3.5, y: radius * 3.5 } })
}
{
"iframeVersion": "0.1.280",
"lines": [
36,
0,
0,
0,
0,
0,
0,
0
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment