Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about something like this?</p> <pre><code>public static void DrawMeACircle(int posX, int posY, int radius) { int thickness = 2; for (int j = 0; j&lt;posY+radius*2 + thickness;j++) { for (int i = 0; i&lt;posX+radius*2+thickness; i++) { if ( Math.abs(Math.pow(Math.pow(i-posX,2) + Math.pow(j-posY,2),.5) - radius*2) &lt; thickness) { System.out.print("#"); // or X ? } else { System.out.print(" "); } //System.out.print("\n"); } System.out.print("\n"); } } </code></pre> <p>The result with x = 16, y = 11, radius = 5 and thickness = 2 looks a bit like this</p> <pre><code> ######### ############# ############### ######## ######## ###### ###### ##### ##### #### #### ##### ##### #### #### #### #### #### #### ### ### #### #### #### #### #### #### ##### ##### #### #### ##### ##### ###### ###### ######## ######## ############### ############# ######### </code></pre> <p>The fact that it is elongated is probably a matter of the font...</p> <p>In order to provide a "single line" circle no matter the radius and position, i'd say the only way is to edit it afterwards like this:</p> <pre><code>public static void DrawMeACircle(int posX, int posY, int radius) { String [] result = new String [posY+radius*2+1]; for (int j = 0; j&lt;posY+radius*2+1;j++) { result[j] = ""; for (int i = 0; i&lt;posX+radius*2+1; i++) { float pointDistance = dist(i, j, posX, posY); if (pointDistance &lt; radius*2) result[j] +="#"; // or X ? else result[j]+=" "; } } boolean wholeLine = true; for (int j = 0; j &lt; result.length; j++) { boolean started = false; if (!wholeLine &amp;&amp; j &lt; result.length-1 &amp;&amp; !result[j+1].contains("#")) wholeLine = true; if (!wholeLine) for (int i = 0; i &lt; result[j].length()-1; i++) { if (result[j].charAt(i) != '#') continue; if (!started) started = true; else if (started &amp;&amp; result[j].charAt(i+1) != '#') { } else result[j] = result[j].substring(0, i) + " " + result[j].substring(i+1); } if(wholeLine &amp;&amp; result[j].contains("#")) wholeLine = false; System.out.println(result[j]); } } static float dist(int x1, int y1, int x2, int y2) { return (int)Math.abs(Math.pow(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2), .5)); } </code></pre> <p>which will (no matter what you throw at it) result in something like this:</p> <pre><code> ####### # # # # # # # # # # # # # # # # # # # # # # # # # # ####### </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload