Skip to content

Instantly share code, notes, and snippets.

@ihatecsv
Created April 8, 2023 20:18
Show Gist options
  • Save ihatecsv/7c27946994fefc18e922dd334fe2d241 to your computer and use it in GitHub Desktop.
Save ihatecsv/7c27946994fefc18e922dd334fe2d241 to your computer and use it in GitHub Desktop.
drawASCIICircle by GPT4
// 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