16
\$\begingroup\$

Intro

Given radius \$r\$, draw a circle in the center of the screen.

Sandbox.

The Challenge

Here is a simple challenge.

Plot a circle using the formula \$x^2+y^2=r^2\$, or any other formula that will plot a circle according to the given parameters.

You may use any units that your language provides, so long as they are well defined and give consistent output.

The circle must have it's center at the center of the canvas, and must have a padding of 5 units or more on all sides.

The circle can have any fill that does not match the outline.

You may have axes in the background of your plot.

The outline of the circle must be solid (no gaps), and it must be visible. Here is an example:

enter image description here

Input can be taken in any acceptable form. (function params, variables, stdin...)

Output can be in the form of a separate window, or an image format.

Standard loopholes and rules apply.

Example Code (Java + Processing)

// Modified from the C language example from
// https:// en.wikipedia.org/wiki/Midpoint_circle_algorithm
int r = 70; //radius
void settings() {
  size(2*r+10, 2*r+10);
}
 
void draw() {
  background(255);
  drawCircle(width/2, height/2, r, 60);
  save("Circle.png");
}

 
void drawCircle(int x0, int y0, int radius, int angle) {
  int circCol = color(0, 0, 0);
  float limit = radians(angle);
  int x = radius;
  int y = 0;
  int err = 0;
 
  while (x >= y && atan2(y, x) < limit) {
    set(x0 + x, y0 + y, circCol);
    set(x0 + y, y0 + x, circCol);
    set(x0 - y, y0 + x, circCol);
    set(x0 - x, y0 + y, circCol);
    set(x0 - x, y0 - y, circCol);
    set(x0 - y, y0 - x, circCol);
    set(x0 + y, y0 - x, circCol);
    set(x0 + x, y0 - y, circCol);
 
    y += 1;
    if (err <= 0) {
      err += 2*y + 1;
    }
    if (err > 0) {
      x -= 1;
      err -= 2*x + 1;
    }
  }
}

Scoring

This is a question. No ascii art.

This is . shortest answer in each language wins.

\$\endgroup\$
14
  • \$\begingroup\$ What do you mean by 'the thickness of the outline must be 1 unit'? Are the units of outline thickness the same as those of the radius? \$\endgroup\$
    – Dingus
    Commented Sep 22, 2020 at 6:49
  • \$\begingroup\$ yes, it doesn't make sense. I changed it. \$\endgroup\$
    – Razetime
    Commented Sep 22, 2020 at 6:53
  • 1
    \$\begingroup\$ Related (Draw a Polygon) \$\endgroup\$
    – Jo King
    Commented Sep 22, 2020 at 8:04
  • 1
    \$\begingroup\$ You say there should be a padding of 5 units, what should happen if radius is bigger than window size? \$\endgroup\$
    – LiefdeWen
    Commented Sep 22, 2020 at 8:36
  • 1
    \$\begingroup\$ If we can zoom, wouldn't the same constant-sized circle, not showing axes, work for any input? \$\endgroup\$
    – att
    Commented Sep 23, 2020 at 6:58

32 Answers 32

1
2
0
\$\begingroup\$

Robocompass, 16 bytes

arc(0,0,a,0,360)

Where you have to define a before that as input.

\$\endgroup\$
2
  • \$\begingroup\$ I don't think this is a permitted input method. \$\endgroup\$
    – Wheat Wizard
    Commented May 9, 2022 at 8:56
  • \$\begingroup\$ @WheatWizard but as far as I am concerned it is the only way in robocompass. :-( \$\endgroup\$ Commented May 10, 2022 at 4:45
0
\$\begingroup\$

Desmos, 3 bytes

r=1

Simply entering r, in my concern, doesn't work, but entering r=0 automatically makes it a slider.

r=0 doesn't create a circle. Sorry about that.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Pasting this into desmos doesn't seem to produce a circle. \$\endgroup\$
    – Wheat Wizard
    Commented May 9, 2022 at 8:58
  • \$\begingroup\$ @WheatWizard fixed \$\endgroup\$ Commented May 10, 2022 at 4:45
1
2

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.