PHP, 186 184 196 bytes
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);for(;$a<$p=2*M_PI;)for($b=$a+=$p/=$argv[1];$b>0;)imageline($i,(1+cos($a))*$r=300,$r+$r*sin($a),$r+$r*cos($b-=$p),$r+$r*sin($b),1);imagepng($i);
writes the image to STDOUT
breakdown
// create image with white background
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);
// loop angle A from 0 to 2*PI
for(;$a<$p=2*M_PI;)
// loop angle B from A down to 0
for($b=$a+=$p/=$argv[1];$b;) // ($a pre-increment)
// draw black line from A to B
imageline($i, // draw line
(1+cos($a))*$r=300,$r+$r*sin($a), // from A
$r+$r*cos($b-=$p),$r+$r*sin($b), // to B ($b pre-decrement)
1 // undefined color=black
);
// output
imagepng($i);
-12 bytes for fixed n=20
Replace $p=2*M_PI
with 6
(-8), /=$argv[1]
with =M_PI/10
(-2), and $b>0
with $b
(-2)
Using exact PI/10 doesn´t hurt. With .3142
, the rounding errors from the parametrized version remained, but with M_PI/10
they vanished and I can check $b
(<>0) instead of $b>0
. I could have saved two bytes with .314
, but that would have off-set the points.
The limit $a<6
is sufficiently exact for 20 points.
174 bytes for fixed n=314
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);for(;$a<314;)for($b=$a++;$b--;)imageline($i,(1+cos($a))*$r=300,$r+$r*sin($a),$r+$r*cos($b),$r+$r*sin($b),1);imagepng($i);
Using 314 points results in a filled circle in that resolution (as do 136,140, every even number above that, and everything above 317).
7It'd be cool if you had to take in a number
n
and draw lines forn
points. – Yodle – 2016-12-01T17:45:30.3372I second this idea. Change it before someone gets the first answer. – shooqie – 2016-12-01T17:53:14.667
2@shooqie Then the title wouldn't make sense though, unless that can be edited by the mods? – Yodle – 2016-12-01T17:54:33.863
1Or you can make a new one – shooqie – 2016-12-01T17:55:05.670
Actually looks like anyone can edit the title, should I propose that as a change or leave it as is? – Yodle – 2016-12-01T17:56:49.747
I mean, it's up to the submitter what he will do. You should propose it as a change though. – shooqie – 2016-12-01T17:58:15.740
2I don't think changing 37 to an arbitrary
n
would add much to the challenge as I expect most solutions to work with any number anyway, especially because 37 is odd and hence there are no mirror symmetries. – Laikoni – 2016-12-01T18:01:00.773@Laikoni Well I figured it'd be interesting to see different patterns by changing the number, but I guess you could just use other people's solutions and change the 37 to whatever you want yourself. – Yodle – 2016-12-01T18:04:48.310
Your sample output is not a vector graphic; it's a JPEG raster graphic. – Glenn Randers-Pehrson – 2016-12-01T18:12:30.850
1@GlennRanders-Pehrson "or be an image at least 600 pixels by 600 pixels" – trichoplax – 2016-12-01T18:14:51.737
3Do we take
n
as input or just pick an arbitraryn
over 20? – Rɪᴋᴇʀ – 2016-12-01T18:16:03.223What is the minimum permitted radius of the circle, as a fraction of the image size? – trichoplax – 2016-12-01T18:17:19.687
Somewhat related. – Martin Ender – 2016-12-01T18:42:20.587
At least 80%? I mean... why is that concern? – J. Antonio Perez – 2016-12-01T18:44:36.773
What
n
did you use for your example? – Titus – 2016-12-01T22:35:38.823@Titus
37
, it was the initial challenge (check the question's revision history for more details) – Rod – 2016-12-02T10:52:29.780Do we have to parametrize? Please clarify with
for a given n
(and rephrase or remove the last sentence) or withfor n>=20 of your choice
or explicitly allow both. Thanks. – Titus – 2016-12-02T12:01:43.673For people interested in the mathematics behind this specific graph, check out this link on complete graphs.
– Jeel Shah – 2016-12-02T17:49:30.907