### Minuscule source code for Lyapunov images (ASCII style)

• 8 Replies
• 565 Views

0 Members and 1 Guest are viewing this topic.

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Minuscule source code for Lyapunov images (ASCII style)

« on: March 05, 2019, 12:54:20 PM »
galac posted a couple of days ago a small mandelbrot program for textual output https://fractalforums.org/programming/11/small-mandelbrot-set-in-c/2658/msg13288#new

I really liked the idea and thought I'd try it with my Lyapunov images. So I searched through them to find some that look recognizably enough in black and white and a very small resolution of 100x100 (ASCII output gets quite screen-big).

Here are some of the first examples I managed to find.

Has anyone else done this for other types of fractals?

Image: Trebuchet with 423 bytes of code
Code: [Select]
#include "stdio.h"#include "math.h"main(){int x,y,i,w=8,u[]={0,1,0,1,0,0,1,1},s;double z,l,r,h,k[2];for(y=99;y>=0;y--){for(x=0;x<100;x++){k[0]=3.64-x*0.0055-y*0.0105;k[1]=1.71-x*0.0105+y*0.0057;z=0.5;s=0;for(i=0;i<50;i++){h=sin(z+k[u[s++]]);z=3.55*h*h;s%=w;}l=0.0;s=0;for(i=0;i<100;i++){r=k[u[s++]];h=sin(z+r);l+=log(fabs(7.1*h*cos(z+r)));z=3.55*h*h;s%=w;}l/=100;if(l<0)printf("#");else printf(".");}printf("\n");}}
I wonder whether this size of about 3300 bits can be seen as the informational complexity (as in the Shannon theory). The image had 10000 bits, so in a sense, the program is a compression - however only if the size of the compiler is not considered.

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #1 on: March 06, 2019, 11:38:33 AM »
Yesterday I had a "crazy" thought: Trading speed for smallness. Usually I do the opposite, so it took me quite a while to get that thought. I use 2 separate loops in the small programs - one for the initial 50 iterations and one for the actual 100 computation. I could - and did yesterday - however merge those two into one loop, add an if-statement (if iterationcount>=50...) to only calculate the log-values for the last 100 iterations. I still don't like that, but it saved about 50 characters in the mandibula programm, now down to 371 bytes. Could it be even fewer? Any ideas?

Usually I use rotation in my images to somehow get the structure of interest to be aligned with the screen. So I have to use some sort of vector addition to get the plane coordinates to set the r value to. If, however the image has perpendicular axis and is aligned to the x and y-axis, I could use the loop-variables x and y directly, saving up some characters more (zirconcity from the last post, ldd22 in this). I could even de-rotate some of the pictures (mandibula would work), but then it wouldn't be the same picture - and the information "rotation necessary" will then be executed by the observer, so it feels a bit like "cheating" to reduce the number of characters in that outsourcing manner.

Here are some of the new examples, where I used these two ideas.

Image: Alice (396 bytes source code)
Code: [Select]
#include "stdio.h"#include "math.h"main(){int x,y,i,w=12,u[]={0,0,0,0,0,0,1,1,1,1,1,1},s;double z,l,r,h,k[2],j,c=0.00577778;for(y=99;y>=0;y--){for(x=0;x<100;x++){k[0]=-1.822222+y*c;k[1]=-0.3111111+x*c;z=0.5;l=0.0;s=0;for(i=0;i<150;i++){r=k[u[s++]];h=sin(z+r);j=cos(z+r);if(i>49)l+=log(fabs(2.5*(1-r*h)*cos(z+r*j)));z=5*h*j;s%=w;}l/=100;if(l<0)printf("#");else printf(".");}printf("\n");}}

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #2 on: March 07, 2019, 12:36:34 PM »
The sectionally defined functions were a bit tricky. I'm sure it can get smaller than here. Using the question mark statement in C++ instead of (some) if/then reduces the size of the "benchmark program" mandibula to now 349 bytes.

These small programs would have made a great task in middle school's computer science class - way more fascinating than entering a listing of a "hello world" program.

Again, I checked all C++ source code with an old gcc compiler from the early 2000s. So they should work on any computer.

Can these programs be expressed in other languages even smaller? I have no experience in e.g. Delphi or Java.

Image: Zorro, 507 bytes
Code: [Select]
#include"stdio.h"#include"math.h"main(){int i,w=6,u[]={0,0,0,0,0,1},s;double z,x,y,l,r,h,k[2];for(y=-1.1766;y<1.15;y+=0.0234){for(x=1.73;x>-1.43;x-=0.0319){k[0]=y;k[1]=x;z=0.5;s=0;for(i=50;i;i--){r=k[u[s++]];if((0>z)||(z>1))z=-5*sin(z+r*cos(z+r));else z=-5*sin(z+r)*sin(z+r);s%=w;}l=0.0;for(i=100;i;i--){r=k[u[s++]];if((0.6>z)||(z>1)){l+=log(fabs(5*(1-r*sin(z+r))*cos(h=z+r*cos(z+r))));z=-5*sin(h);}else{h=sin(z+r);l+=log(fabs(10*h*cos(z+r)));z=-5*h*h;}s%=w;}l/=100;printf((l<0)?"#":".");}puts(0);}}
"Benchmark" image: Mandibula, 349 bytes
Code: [Select]
#include"stdio.h"#include"math.h"main(){int x,y,i,w=12,u[]={0,0,0,0,0,0,1,1,1,1,1,1},s;double z,l,r,h,k[2];for(y=99;y>=0;y--){for(x=0;x<100;x++){k[0]=3.25-(x+y)*0.0076;k[1]=2.49+(x-y)*0.0076;z=0.5;s=0;l=0;for(i=150;i;i--){r=k[u[s++]];h=sin(z+r);if(i<101)l+=log(fabs(5.68*h*cos(z+r)));z=2.84*h*h;s%=w;}l/=100;printf((l<0)?"#":".");}puts(0);}}

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #3 on: March 09, 2019, 05:39:17 PM »
A new mini program for an image with which one can play a game called "Logicals" (next post).

Image: Borders (similar to the ldd22 from the previous post, that one did not directly work with the game), 372 bytes source code

Code: [Select]
#include"stdio.h"#include"math.h"main(){int i,w=12,u[]={0,0,0,0,0,1,1,0,1,1,1,1},s;double z,l,r,h,k[2],x,y,t,v;for(y=3.2;y>-3.2;y-=0.064){for(x=-3.2;x<3.2;x+=0.064){k[0]=x;k[1]=y;z=0.5;s=0;l=0;for(i=150;i;i--){r=k[u[s++]];h=sin(r*z-2.8);t=sin(z+2*r);v=sin(z-r);if(i<101)l+=log(fabs(r*z-2.8*h*h*h*h));z=r*v*v+2.8*t*t*t;s%=w;}l/=100;printf((l<0)?"#":".");}puts(0);}}

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #4 on: March 09, 2019, 05:46:54 PM »
PM (a German popular science magazine) publishes for years a game called "Logicals". Basically it's a modified version of the old kid's game "Battleships". You are given an empty grid and are supposed to fill out some of the fields while leaving others empty. In the end you will get an image like a bicycle, a flower or something like that. Each row and column have a number of ships (or consecutive blocks of coloured fields), separated by at least one empty field. And just by logical reasoning, one should be able to identify the exact location of every block.

When I showed the textual output of the mini programs to my girlfriend, she immediately said, that this looked like the result of such a game. So I checked (well a script did) all my Lyapunov images in very tiny resolution (32x32) and black and white, whether this image could be the output for such a game (I had written a solver for that riddle many years ago - so basically I took the output of one program (the minuscule one), put it into a converter, and that result into the solver and checked, whether it came to the initial result - just like AlphaZero for chess did, playing against itself).

Here's the first example that did work automatically. Something for cold winter nights (well, a bit late for that...) Have fun!

#### Sabine62

• Fractal Freak
• Posts: 663

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #5 on: March 09, 2019, 09:41:57 PM »

Glorious!
To thine own self be true

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #6 on: March 10, 2019, 03:28:07 PM »
Thanks! Since you liked it, here's one more, this time the Mandelbrot set in 59x59, automatically found and solved.

#### Sabine62

• Fractal Freak
• Posts: 663

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #7 on: March 10, 2019, 05:14:08 PM »
Super!
I so love it when fractal-related stuff throws up 'real' applications, applications in the sense that they can be used to do more practival things than make interesting pictures

#### marcm200

• Fractal Frankfurter
• Posts: 563

#### Re: Minuscule source code for Lyapunov images (ASCII style)

« Reply #8 on: March 20, 2019, 07:37:58 PM »
The first mini program for my current project at hand: Julia sets using Lyapunov sequences.
I used galac's ideas to shorten my code further: 279 bytes to generate the Julia/Lyapunov set for c1=-0.4+0.1i, c2=0.3+0.6i, sequence AB.

Code: [Select]
#include"stdio.h"main(){float r,i,x,y=1.4,t,c[]={-.4,.3},d[]={.1,.6};int n,w,s,l=2,u[]={0,1};for(;y>-1.4;y-=.07){for(x=-1.6;x<1.6;x+=.07){i=y;r=x;n=99;s=w=0;while(n--){t=i*i;i=2*r*i+d[u[s]];r=r*r-t+c[u[s++]];s%=l;if((r*r+i*i)>4){w=1;break;}}putchar(w?46:88);}puts(0);}}
And here's the corresponding Logicals quiz (automatically found and checked, unfortunately currently the only one working.)

### Similar Topics

###### True shape/IA 2D/3D Julia set source code

Started by marcm200 on Programming

12 Replies
533 Views
January 21, 2020, 01:35:39 PM
by marcm200
###### Minuscule Aquatica

Started by Ray on Fractal movie gallery

0 Replies
120 Views
June 25, 2018, 11:57:43 PM
by Ray
###### Birdie Style

Started by gannjondal on Fractal Image Gallery

1 Replies
461 Views
May 08, 2018, 02:39:37 PM
by who8mypnuts
###### Precision in Lyapunov images?

Started by marcm200 on Programming

1 Replies
243 Views
January 30, 2019, 04:31:30 PM
by claude
###### Neural Style Transfer with Fractal Art

Started by reallybigname on Other Artforms

1 Replies
257 Views
July 20, 2019, 04:25:41 PM
by reallybigname