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


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() {
  drawCircle(width/2, height/2, r, 60);

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;


This is a question. No ascii art.

This is . shortest answer in each language wins.

  • \$\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


Robocompass, 16 bytes


Where you have to define a before that as input.

  • \$\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

Desmos, 3 bytes


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.

  • 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

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.