4
\$\begingroup\$

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.

Examples

//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.beginPath();ctx.moveTo(0,0);ctx.lineTo(0,300);ctx.lineTo(300,0);ctx.closePath();ctx.fill()
ctx.fillStyle = "lime"
ctx.beginPath();ctx.moveTo(200,0);ctx.lineTo(600,0);ctx.lineTo(300,300);ctx.closePath();ctx.fill()
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]]
]</pre>
<canvas id="two" width="600" height="300"></canvas>

Scoring is .

\$\endgroup\$
8
  • 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
    Commented 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
    Commented 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
    Commented Mar 24, 2019 at 3:00
  • \$\begingroup\$ @SHaggy I am assuming that this question is using a standard image I/O format \$\endgroup\$
    – MilkyWay90
    Commented 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
    Commented Mar 24, 2019 at 15:32

1 Answer 1

2
\$\begingroup\$

R, 122 71 bytes

function(w,h,p){plot.new();plot.window(c(0,w),c(0,h));polygon(p,c=1:8)}

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.

\$\endgroup\$

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.