Created
April 8, 2023 20:18
-
-
Save ihatecsv/7c27946994fefc18e922dd334fe2d241 to your computer and use it in GitHub Desktop.
drawASCIICircle by GPT4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written by GPT4 | |
// Prompt: Write a JS function that returns a string of an ASCII circle of a certain radius | |
function drawASCIICircle(radius) { | |
let output = ""; | |
for (let y = -radius; y <= radius; y++) { | |
for (let x = -radius; x <= radius; x++) { | |
// Using the equation of a circle (x^2 + y^2 = r^2) | |
// We add 0.5 to the threshold to make the circle look smoother | |
let distance = Math.sqrt(x * x + y * y); | |
let char = (distance <= radius + 0.5 && distance >= radius - 0.5) ? "*" : " "; | |
output += char; | |
} | |
output += "\n"; | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment