Skip to content

Instantly share code, notes, and snippets.

@sylvinus
Forked from 140bytes/LICENSE.txt
Created October 2, 2011 10:24
Show Gist options
  • Save sylvinus/1257323 to your computer and use it in GitHub Desktop.
Save sylvinus/1257323 to your computer and use it in GitHub Desktop.
Mandelbrot in less than 140 bytes of Javasacript

140byt.es

A tweet-sized, fork-to-play, community-curated collection of JavaScript.

How to play

  1. Click the Fork button above to fork this gist.
  2. Modify all the files to according to the rules below.
  3. Save your entry and tweet it up!

Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

Rules

All entries must exist in an index.js file, whose contents are

  1. an assignable, valid Javascript expression that
  2. contains no more than 140 bytes, and
  3. does not leak to the global scope.

All entries must also be licensed under the WTFPL or equally permissive license.

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function(){
var myFunction = function(z,s,r,i,k,n,w){
//because we have a break-word div, we can just output the lines without caring about the \n
for(w=z*z,n=w;n--;s[w-n]='█'.fontcolor('#'+k*9)) //use the little-known String.fontcolor function!
for(r=i=k=0;r*r+i*i+k++<z;i=t) //run the suite to see if it crosses the threshold (=is it in the mandelbrot set or not)
t=2*r*i+1-2*n/w,
r=r*r-i*i+1-3*n/z%3
}
function(z,s,r,i,k,n,w){for(w=z*z,n=w;n--;s[w-n]='█'.fontcolor('#'+k*9))for(r=i=k=0;r*r+i*i+k++<z;i=t)t=2*r*i+1-2*n/w,r=r*r-i*i+1-3*n/z%3}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "mandelbrot",
"description": "Mandelbrot fractal set (@sylvinus + @fgnass)",
"keywords": [
"fractal",
"mandelbrot",
"fontcolor"
]
}
<!DOCTYPE html>
<title>Mandelbrot set</title>
<div id="out" style="font-size:1px;width:200px;word-wrap:break-word"></div>
<script>
// This is a 140byt.es entry, hosted at https://gist.github.com/1257323
// initiated by @sylvinus, golfed down to death by @fgnass !
// demo at http://jsfiddle.net/jP9Sa/9/
var myFunction =
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function(z,s,r,i,k,n,w){for(w=z*z,n=w;n--;s[w-n]='█'.fontcolor('#'+k*9))for(r=i=k=0;r*r+i*i+k++<z;i=t)t=2*r*i+1-2*n/w,r=r*r-i*i+1-3*n/z%3}
var html = [];
myFunction(200, html);
out.innerHTML = html.join('');
</script>
@jed
Copy link

jed commented Oct 3, 2011

wow, this is amazing! i wish it had come out before my presentation, though! @sylvinus, would love to see you pull @fgnass's changes.

@sylvinus
Copy link
Author

sylvinus commented Oct 3, 2011

Thanks jed! I wish too but before your presentation I had never heard of 140byt.es ;-)

I've merged a few changes from felix, restored variable width, and fixed the colors+orientation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment