A close friend of the Vexbot, the Polybot API sends you nothing but polygons. With every request, our Polybot will send you up to 1,000 polygons from 3 sides (a triangle) to 72 sides (a heptacontakaidigon!). Create dazzling patterns or use the random shapes to create the terrain of your next game.
A polygon—as you'll recall from your ol' geometry textbook—is a connected plane of n line segments, so if you send a request to:
api.noopschallenge.com/polybot
We'll return a set of coordinates defining each vertex of the polygon:
{
"polygons": [
[
{"x":157,"y":998},
{"x":145,"y":1000},
{"x":122,"y":1000},
{"x":106,"y":989},
{"x":127,"y":969},
{"x":151,"y":972}
]
]
}
The API will return up to 1,000 polygons with a random number of sides between 3 to 72. You can specify the count
of polygons returns, minSides
and maxSides
, and the maximum size
you'd like your polygons to be. Or you can let the Polybot decide!
Here is a preview of the starter project.
When faced with an endless stream of polygons, what can you do?
First you could just draw one...
Nice! Then you could draw a whole bunch...
Neat. But what if you made them transparent, and overlapped them?
And what if we animated it?
What's next is up to you! Fork the challenge and share what you do on Twitter (#noopschallenge) or in the GitHub community.
There are millions of things you can do with the Polybot, but here are a few ideas to get you started:
- Name them: Did you know there's a formula to name polygons—all the way from henagon to bigon to tetracontadigon? Learn about it here and show us how yours works.
- Sort them: It's a simple matter of geometry to calculate the area of a polygon. Wouldn't they look nice sorted from largest to smallest? How fast could your algorithm do it?
- Make them obstacles in your game: The polygons would look mighty interesting as asteroids falling from the sky or as boulders your hero has to avoid.
- Add physics: Generate 100 polygons and let them fall from the top of the screen. Would they fit together? Would they squish other polygons? How much volume do they have, and how much mass?
- Make them touchable: Fill the screen with polygons, then make them slide across the screen when you swipe them.
Have an idea of your own? Create an issue and we'll add it to the list!
You can request up to 1,000 polygons, specify maxSides, minSides and size for your polygons, and set maximum x and y boundaries.
There's a single endpoint: api.noopschallenge.com/polybot
The endpoint accepts 6 parameters, all optional:
- count (optional, numeric): Between 1 and 1000. Number of polygons to return.
- size (optional, numeric): Between 10 and 100,000. Maximum size of polygons. Defaults to average of width + height.
- minSides (optional, numeric): Between 3 and 72. Minimum number of sides in the polygon.
- maxSides (optional, numeric): Between 3 and 72. Maximum number of sides in the polygon. To specify number of sides, set
minSides
andmaxSides
to the same number. - width (optional, numeric): Between 10 and 100,000. Maximum width of returned points.
- height (optional, numeric): Between 10 and 100,000. Maximum height of returned points.
The endpoint returns a JSON object with an array named polygons
of n length. Each item in the polygons
array is an object with two properties: x and y.
Example return for a five-sided polygon:
GET https://api.noopschallenge.com/polybot
{
"polygons": [
[
{"x":157,"y":998},
{"x":145,"y":1000},
{"x":122,"y":1000},
{"x":106,"y":989},
{"x":151,"y":972}
]
]
}
Request a six-sided polygon:
GET https://api.noopschallenge.com/polybot?minSides=6&maxSides=6
{
"polygons": [
[
{ "x": 854, "y": 61 },
{ "x": 845, "y": 76 },
{ "x": 823, "y": 69 },
{ "x": 822, "y": 45 },
{ "x": 843, "y": 36 },
{ "x": 856, "y": 56 }
]
]
}
Request a polygon within a bounding box:
GET https://api.noopschallenge.com/polybot?count=2&width=10&height=10
{
"polygons": [
[
{ "x": 10, "y": 8 },
{ "x": 10, "y": 9 },
{ "x": 9, "y": 9 },
{ "x": 8, "y": 9 },
{ "x": 8, "y": 9 },
{ "x": 7, "y": 8 },
{ "x": 7, "y": 7 },
{ "x": 8, "y": 7 },
{ "x": 8, "y": 6 },
{ "x": 9, "y": 6 },
{ "x": 9, "y": 7 },
{ "x": 10, "y": 7 }
],
[
{ "x": 4, "y": 8 },
{ "x": 3, "y": 8 },
{ "x": 3, "y": 7 },
{ "x": 3, "y": 7 },
{ "x": 4, "y": 7 }
]
]
}
Read the complete API documentation.
More about Polybot on the challenge page at noopschallenge.com.