Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 112 characters in body
Source Link
Kjetil S
  • 6.2k
  • 11
  • 23

Perl 5, 11692 bytes

sub$r=$_;
$w=$r*2+11;
$_="P1 f{$r=pop;$w=$r*2+11;$s=0$w x$w**2;substr$s,sin$w @{[map{($x$_%$w-$r-5)*$r+$r+5+int(cos**2+($x)*$r+$r+5$_/$w-$r-5)*$w,**2<$r**2?1,1while++$x<1e5;"P1 $w $w $s":0}0..$w**2-1]}"

Try it online! Try it online!

Just a shorter translation of the C answer from @ErikFCircle with black filling. Except not caring about keeping x below Put the 92 bytes above into program.pl and run like this:

echo 50 | perl -p program.pl > circle.pbm # radius 50
feh circle.pbm # view with feh or other image viewer

Perl 5, 116 bytes

sub f{$r=pop;$w=$r*2+11;$s=0 x$w**2;substr$s,sin($x)*$r+$r+5+int(cos($x)*$r+$r+5)*$w,1,1while++$x<1e5;"P1 $w $w $s"}

Try it online!

Just a shorter translation of the C answer from @ErikF. Except not caring about keeping x below .

Perl 5, 92 bytes

$r=$_;
$w=$r*2+11;
$_="P1 $w $w @{[map{($_%$w-$r-5)**2+($_/$w-$r-5)**2<$r**2?1:0}0..$w**2-1]}"

Try it online!

Circle with black filling. Put the 92 bytes above into program.pl and run like this:

echo 50 | perl -p program.pl > circle.pbm # radius 50
feh circle.pbm # view with feh or other image viewer
Source Link
Kjetil S
  • 6.2k
  • 11
  • 23

Perl 5, 116 bytes

sub f{$r=pop;$w=$r*2+11;$s=0 x$w**2;substr$s,sin($x)*$r+$r+5+int(cos($x)*$r+$r+5)*$w,1,1while++$x<1e5;"P1 $w $w $s"}

Try it online!

Just a shorter translation of the C answer from @ErikF. Except not caring about keeping x below .

AltStyle によって変換されたページ (->オリジナル) /