[from archive] fractal.c

16 views
Skip to first unread message

Colin Randall

unread,
Sep 29, 2021, 9:49:11 AM9/29/21
to

I once found a little program in a .sig that creates a fractal in ascii when
you run it. Here we go:

/* by Carson Y H Cheung (che...@p4.cs.man.ac.uk) */
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}

...and this is what its output looks like:

WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! !dWW!ddddllllrrrrrrrooooooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
Worrrrrrrllllllddd!oooWWWoloWWWWoodr drrWdlllrrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wlddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
olddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Worrrrrrrllllllddd!oooWWWoloWWWWoodr droWdlllrrrrrrrr
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! WdWW!ddddllllrrrrrrrooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo


--
.
._!__ __ __
/ _\/_ |_ \!_
/ / 7 / /|
\ \_ _/ / \ .
\_//__/|_\_\!_.
|

Christian Garbs

unread,
Sep 30, 2021, 5:49:08 PM9/30/21
to
Colin Randall <colin.r...@gmail.com> wrote:

> I once found a little program in a .sig that creates a fractal in ascii when
> you run it. Here we go:

I also have one lying around, but don't know the source.
The output is not as pretty, but it is plain shell (no C, no floats).

- - - - - - - - - - - - - - - - 8< - - - - - - - - - - - - - - - -

sh -c 'set 2 1 0 / . - + ^ : , ! %;y=70;for a in $* $*;do x=54;while [ \
${#s} -lt 79 ];do r=0;i=0;for b in % $*;do [ $(((q=r*r)+(t=i*i))) -ge 9\
999 ]&&break;i=$((y+(r*i)/32));r=$((x+(q-t)/64));done;s=$b$s;x=$((x-2))\
;done;y=$((y-6));echo $s;s=;done;'

- - - - - - - - - - - - - - - - >8 - - - - - - - - - - - - - - - -


2222222222222222111111000000000000000000///.+,+..111111111111111111111111111111
2222222222222100000000000000000000///////...-^:%:%%%/////1111111111111111111111
222222222220000000000000000000/////////....+:%%%%%^+-..//////001111111111111111
222222222000000000000000000/////////...-+^:%%%%%%%%%%+.....////0001111111111111
222222200000000000000000////////-+---+++::,%%%%%%%%%,^^+-------//00000111111111
222222000000000000000/////...-+,%%%%%%%%%%%%%%%%%%%%%%%%%!,%%,!%:.0000001111111
222200000000000000........----^:!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-..000000011111
22220000000000.........---+^:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:++-./0000000111
22200000--,%!:++:%%::+++^^^,%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:.//000000011
22......-++:%%%%%%%%%%%%%!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!-///000000001
22.....^:,%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+..///00000001
22++::%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%^-...///00000000
22:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:+-..////00000000
22....%,:!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:-.////00000001
22......+++!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-.///00000001
222/....--^%%%%:!%%%%%:::::,%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%^+.//000000011
2220000000000---+.....--+++^,%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!:::./0000000111
22220000000000000.........---:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:-../00000011111
22222000000000000000////....--+:!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:./000000111111
22222220000000000000000///////-!,,%,^^!%!,%%%%%%%%%%%,:%,----+^:.00000111111111
22222222000000000000000000/////////.----+^^%%%%%%%%%,+-.....////000111111111111
22222222220000000000000000000/////////....,%%%%%%%,:%.../////000111111111111111
22222222222200000000000000000000////////....+^:%%,+--//////11111111111111111111
22222222222222211110000000000000000000////..-,,--../111111111111111111111111111


Best regards
Christian
--
....Christian.Garbs....................................https://www.cgarbs.de
"All true wisdom is found on T-shirts."
--Anonymous

Eli the Bearded

unread,
Sep 30, 2021, 8:04:22 PM9/30/21
to
In alt.ascii-art, Christian Garbs <mi...@cgarbs.de> wrote:
> Colin Randall <colin.r...@gmail.com> wrote:
>> I once found a little program in a .sig that creates a fractal in ascii when
>> you run it. Here we go:
> I also have one lying around, but don't know the source.
> The output is not as pretty, but it is plain shell (no C, no floats).
> - - - - - - - - - - - - - - - - 8< - - - - - - - - - - - - - - - -
>
> sh -c 'set 2 1 0 / . - + ^ : , ! %;y=70;for a in $* $*;do x=54;while [ \
> ${#s} -lt 79 ];do r=0;i=0;for b in % $*;do [ $(((q=r*r)+(t=i*i))) -ge 9\
> 999 ]&&break;i=$((y+(r*i)/32));r=$((x+(q-t)/64));done;s=$b$s;x=$((x-2))\
> ;done;y=$((y-6));echo $s;s=;done;'
>
> - - - - - - - - - - - - - - - - >8 - - - - - - - - - - - - - - - -

I'd suggest one change to help that be prettier: |tr % " "
Added right before $s is reset to empty:

sh -c 'set 2 1 0 / . - + ^ : , ! %;y=70;for a in $* $*;do x=54;while [ \
${#s} -lt 79 ];do r=0;i=0;for b in % $*;do [ $(((q=r*r)+(t=i*i))) -ge 9\
999 ]&&break;i=$((y+(r*i)/32));r=$((x+(q-t)/64));done;s=$b$s;x=$((x-2))\
;done;y=$((y-6));echo $s|tr % " ";s=;done;'

2222222222222222111111000000000000000000///.+,+..111111111111111111111111111111
2222222222222100000000000000000000///////...-^: : /////1111111111111111111111
222222222220000000000000000000/////////....+: ^+-..//////001111111111111111
222222222000000000000000000/////////...-+^: +.....////0001111111111111
222222200000000000000000////////-+---+++::, ,^^+-------//00000111111111
222222000000000000000/////...-+, !, ,! :.0000001111111
222200000000000000........----^:! -..000000011111
22220000000000.........---+^: :++-./0000000111
22200000--, !:++: ::+++^^^, :.//000000011
22......-++: !! !-///000000001
22.....^:, +..///00000001
22++:: ^-...///00000000
22: :+-..////00000000
22.... ,:! :-.////00000001
22......+++! -.///00000001
222/....--^ :! :::::, ^+.//000000011
2220000000000---+.....--+++^, !:::./0000000111
22220000000000000.........---: :-../00000011111
22222000000000000000////....--+:! :./000000111111
22222220000000000000000///////-!,, ,^^! !, ,: ,----+^:.00000111111111
22222222000000000000000000/////////.----+^^ ,+-.....////000111111111111
22222222220000000000000000000/////////...., ,: .../////000111111111111111
22222222222200000000000000000000////////....+^: ,+--//////11111111111111111111
22222222222222211110000000000000000000////..-,,--../111111111111111111111111111


And here it's reworked to be a nice bricktext:

sh -c 'c="2 1 0 / . - + ^ : , ! %";y=70;for a in $c $c; do x=54;
while [ ${#s} -lt 79 ];do r=0; i=0;for b in % $c;do [ $(((q=r*r)
+(t=i*i))) -ge 9999 ]&&break;i=$((y+(r*i)/32));r=$((x+(q-t)/64))
done;s=$b$s;x=$((x-2));done;y=$((y-6));echo $s|tr % " ";s=;done'

Elijah
------
probably not all /bin/sh will be happy with that
Reply all
Reply to author
Forward
0 new messages