Skip to content
Advertisement

How to print a standard circle in the console window?

I am trying to print an arbitrary math function through a callback function, the execute() function will iterate over all integer coordinates (x,y), if the callback returns true then canvas[x][y] = ‘*’.

But my implementation only works when printing straight lines, always fails to print hollow circles

JavaScript

The following two pictures are the printed x shape and the wrong ring shape.

print x size 20

print circle size 13

Advertisement

Answer

You are also shifting the center here

JavaScript

Consider not changing the center as following

JavaScript

On a side note, now you know how to draw a crescent too.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement