Given: a width, a height, and a set of sets of points. Output: An image where each set of points is connected and colored in (like a shape). Each shape must be a different color from all of the other shapes, but the actual color doesn't matter as long as each color is distinct. The shapes must be in order; whether you start at the end or the beginning of the set doesn't matter, though. The dots must be connected in the order they're given in the set.

Output formats are in accordance with standard image rules.


//the code here has nothing to do with the actual challenge and just shows examples

document.getElementById("one").getContext("2d").fillRect(0, 0, 300, 300)
const ctx = document.getElementById("two").getContext("2d")
ctx.fillStyle = "black"
ctx.fillStyle = "lime"
canvas {border: 1px dotted black}
<pre>Width: 500, Height: 500, Set: [[[0, 0], [0, 300], [300, 300], [300, 0]]]</pre>
<canvas id="one" width="500" height="500"></canvas>

<pre>Width: 600, Height: 300, Set:
  [[0,0], [0,300], [300,0]],
  [[200,0], [600,0], [300,300]]
<canvas id="two" width="600" height="300"></canvas>

Scoring is .

  • 1
    \$\begingroup\$ I meant to ask this question in the Sandbox but what qualities as a "different" colour? Is #000000 different to #000001? \$\endgroup\$
    – Shaggy
    Mar 24, 2019 at 0:11
  • \$\begingroup\$ Also, what output formats are allowed? Is a base-64 encoded PNG outputted as s string OK? Or the XML markup of an SVG? \$\endgroup\$
    – Shaggy
    Mar 24, 2019 at 0:26
  • 1
    \$\begingroup\$ How are we supposed to connect the shapes? Suppose it's a pentagon. Which points go with which points? \$\endgroup\$
    – Gymhgy
    Mar 24, 2019 at 3:00
  • \$\begingroup\$ @SHaggy I am assuming that this question is using a standard image I/O format \$\endgroup\$
    – MilkyWay90
    Mar 24, 2019 at 15:32
  • \$\begingroup\$ I am voting to close because it doesn't say how we should connect the dots. \$\endgroup\$
    – MilkyWay90
    Mar 24, 2019 at 15:32

1 Answer 1


R, 122 71 bytes


Try it online!

RDRR - actually shows graphics

A function that takes arguments width, height and a matrix of points detailing the shapes. Each shape is separated by a row of NAs. Output is a plot to the screen of the shapes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.