Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Circle of text characters [FINALIZED]

+0
−0

Now posted: Circle of text characters


Given a radius R, output a text representation of a circle.

Input

  • A positive integer R (strictly greater than zero)
  • You do not need to handle values of R greater than 32

Output

  • A square grid of characters of side length 2R + 1
  • You may choose any 2 distinct characters to represent the foreground (depicting the circle) and the background
  • The centre of the circle is the centre of the square. That is, the location (R, R) if using zero indexed coordinates
  • Each foreground character must have a distance from the centre that has either a floor or a ceiling of R. That is, R-1 < distance < R+1. Within a single output, some foreground characters may have a floor of R and some may have a ceiling of R - you do not need to choose one or other consistently
  • The circle must not have gaps. Specifically, there must be no connected path of horizontally or vertically adjacent background characters joining the centre to any edge of the square. Equivalently, a flood fill from the centre will not reach any of the edges

Examples

Here . represents the background and # represents the foreground.

Using these characters, the rules are equivalent to:

  • Every . must be included in the background
  • Any # may be included in the foreground, but not all of them need to be - some may be left as background provided there are no gaps between the foreground characters

This is intended to give the flexibility to allow various different circle drawing approaches to compete.

The potential character placements for radius 1 to 10:

R = 1

###
#.#
###


R = 2

#####
##.##
#...#
##.##
#####


R = 3

.#####.
###.###
##...##
#.....#
##...##
###.###
.#####.


R = 4

..#####..
.###.###.
##.....##
##.....##
#.......#
##.....##
##.....##
.###.###.
..#####..


R = 5

..#######..
.####.####.
###.....###
##.......##
##.......##
#.........#
##.......##
##.......##
###.....###
.####.####.
..#######..


R = 6

...#######...
..####.####..
.##.......##.
##.........##
##.........##
##.........##
#...........#
##.........##
##.........##
##.........##
.##.......##.
..####.####..
...#######...


R = 7

....#######....
..#####.#####..
.###.......###.
.##.........##.
##...........##
##...........##
##...........##
#.............#
##...........##
##...........##
##...........##
.##.........##.
.###.......###.
..#####.#####..
....#######....


R = 8

....#########....
...#####.#####...
..###.......###..
.###.........###.
###...........###
##.............##
##.............##
##.............##
#...............#
##.............##
##.............##
##.............##
###...........###
.###.........###.
..###.......###..
...#####.#####...
....#########....


R = 9

.....#########.....
....#####.#####....
..####.......####..
..##...........##..
.##.............##.
###.............###
##...............##
##...............##
##...............##
#.................#
##...............##
##...............##
##...............##
###.............###
.##.............##.
..##...........##..
..####.......####..
....#####.#####....
.....#########.....


R = 10

......#########......
....######.######....
...###.........###...
..###...........###..
.###.............###.
.##...............##.
##.................##
##.................##
##.................##
##.................##
#...................#
##.................##
##.................##
##.................##
##.................##
.##...............##.
.###.............###.
..###...........###..
...###.........###...
....######.######....
......#########......

Validator

You can validate specific outputs with this text circle validator, which will give an explanation for any failed validations.

Explanations are optional, but I'm more likely to upvote answers that have one.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads