Topic: Mandelbrot tracer in 137 bytes Pages that link to <a href="https://ozoneasylum.com/backlink?for=30330" title="Pages that link to Topic: Mandelbrot tracer in 137 bytes" rel="nofollow" >Topic: Mandelbrot tracer in 137 bytes\

 
Author Thread
poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 06-15-2008 19:03 Edit Quote

In my never ending quest for size optimization in DHTML, I wanted to see how many bytes were needed to render the initial Mandelbrot set. A while ago I made one zooming and rotating in 256 bytes and hoped I could get close to or even reach 128 bytes but I failed "short" and got stuck at 137 bytes.

So here comes a Mandelbrot tracer in 137 bytes of DHTML. ( not IE friendly )

For the record IE chokes because it still does not support the String[ index ] syntax. Also I managed to go to 134 bytes in Opera thanks to its support for the DOM2 Text interface. But I wanted this to work in more browsers.


Hope you can appreciate the size optimization anyway. And please let me know if you manage to squeeze a few more bytes. Note that using a TT instead of a PRE, the text wraps every second line of the Mandelbrot set if the window is larger than 1000 pixels. So it's not really a solution.



(Edited by poi on 06-15-2008 19:29)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 06-15-2008 21:54 Edit Quote

Someone at Pouet.net suggested to remove the PRE altogether. It has the same effect as using a TT, but widening the set a bit so that it wraps nicely in windows < 1600px, brings the effect to 133 bytes. I'm not entirely sure if this is an OK limitation.

MaGnA
Nervous Wreck (II) Inmate

From: Toronto
Insane since: Jan 2008

IP logged posted posted 06-17-2008 06:43 Edit Quote

Awesome!

jseidelin
Nervous Wreck (II) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

IP logged posted posted 09-19-2008 18:54 Edit Quote

Oh so many dirty tricks.

122 bytes : http://www.nihilogic.dk/labs/mandelbrot/122b.htm


Doesn't work in Safari/Chrome.



Jacob Seidelin - http://blog.nihilogic.dk/

(Edited by jseidelin on 09-19-2008 18:55)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 09-21-2008 01:14 Edit Quote

Nice! Thanks for challenging me. I really need some kick.

I facepalm'ed myself when I saw the <body onload="..."> and the whitespace instead of \n. Don't know why I insisted in the PRE route. That was 2 bytes stupidly wasted.

Good job on the k-=1/32. Using of a power of 2 to be IEEE 754 friendly and have the k%3 behave nicely.

There's one thing I don't quite understand : the exit condition of the inner loop. I suppose i/y evaluates to false because of rounding errors, but I'm not entirely sure. I don't see how y could be Infinity thus making i/y equal 0 aka false.

Anyhow, very good job.


So with no further ado :

117 bytes : http://www.p01.org/releases/Demoscene/files/mandelbrot_117b.htm



(Edited by poi on 09-21-2008 01:39)

HZR
Paranoid (IV) Inmate

From: Cold Sweden
Insane since: Jul 2002

IP logged posted posted 09-21-2008 01:54 Edit Quote

Damn, you guys are insane.

Anyway, p01, you can save one whole byte by dropping quotes and replacing "' '" with "'\n'", i.e.

code:
<body onload=for(n=84;n-=1/32;document.write(n%3?6+!k:'\n'))for(r=i=0,k=99;--k/r;i=t)t=2*r*i+1-n/42,r=r*r-i*i+1-n%3>



Oh, and I know you guys are mainly concerned with optimizing the script itself, but that's way beyond me.

(Edited by HZR on 09-21-2008 02:18)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 09-21-2008 02:18 Edit Quote

*facepalm* I thought the HTML parser would end the attribute at the '. Well done.

Alright, so 115 bytes it is. I tried to force various encodings ( e.g. Thai, Korean, UTF-8 ) and it seems to work. At least in Opera and Firefox.



(Edited by poi on 09-21-2008 02:26)

HZR
Paranoid (IV) Inmate

From: Cold Sweden
Insane since: Jul 2002

IP logged posted posted 09-21-2008 02:28 Edit Quote

p01, I removed the sentence where I mentioned using some character that would break the word, and forcing an encoding, since actually it's 115 characters, but more bytes.

Edit: ah, I see what you used now I think. My version used more bytes though. Nice work.

(Edited by HZR on 09-21-2008 02:31)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 09-21-2008 02:33 Edit Quote

It isn't more bytes if you use a character whose "ASCII" code is below 128, e.g. a control character

jseidelin
Bipolar (III) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

IP logged posted posted 09-21-2008 11:35 Edit Quote

Nice job p01 and HZR, I like the special character to break the lines. I tried the onload without quotes as well, but I guess the parser tripped over the whitespace and not the quotes as I had assumed, so I just abandoned that idea. D'oh.

As I see it, most of the points diverge very quickly to huge numbers and once they pass the max_value for Number they become Infinity, making i/y == 0. JavaScript math limitations are great.

jseidelin
Bipolar (III) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

IP logged posted posted 09-21-2008 11:54 Edit Quote

It seems Firefox accepts the body tag without the ending ">", so that's 114 bytes

http://www.nihilogic.dk/labs/mandelbrot/114b.htm

Opera is not too happy about it, though.

Jacob Seidelin - http://blog.nihilogic.dk/

WebShaman
Lunatic (VI) Mad Scientist

From: The Happy Hunting Grounds...
Insane since: Mar 2001

IP logged posted posted 09-21-2008 12:02 Edit Quote

Holy crud!

Nice work!

WebShaman | The keenest sorrow (and greatest truth) is to recognize ourselves as the sole cause of all our adversities.
- Sophocles

jseidelin
Bipolar (III) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

IP logged posted posted 09-21-2008 12:45 Edit Quote

113 bytes with a slightly different look:

http://www.nihilogic.dk/labs/mandelbrot/113b.htm

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 09-21-2008 13:12 Edit Quote

I didn't change the look before as the characters 6,7 and 7,8 gave a much cleaner/sharper output.

Nice find with the > alas the cost is pretty high. Makes me wonder how such things are parsed in HTML5.

Anyhow, changing the look a bit, I got 112b version working in Firefox & Opera, and 111b for FireFox only when trimming the BODY tag.



(Edited by poi on 09-21-2008 13:24)

HZR
Paranoid (IV) Inmate

From: Cold Sweden
Insane since: Jul 2002

IP logged posted posted 09-21-2008 15:31 Edit Quote
quote:
Nice find with the > alas the cost is pretty high. Makes me wonder how such things are parsed in HTML5.


Just fine.

(Edited by HZR on 09-21-2008 15:32)



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu