5 ms·
Lorenz Attractor in 101 bytes of JS
- gbadman 14y agoLink to play with it: http://plnkr.co/edit/UFLKBx http://plnkr.co/edit/UFLKBx Hint: Hit the eye icon on the right for live preview.
- jashkenas 14y agoVery neat. Attractors + <canvas> are a lot of fun... My favorite is the Peter de Jong attractor, described here: http://paulbourke.net/fractals/peterdejong/ http://paulbourke.net/fractals/peterdejong/ Here's a <canvas> version. Click and drag and release to re-seed the starting coordinates: http://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html http://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html Here's the annotated source code: http://jashkenas.s3.amazonaws.com/misc/deJong/docs/deJong.html http://jashkenas.s3.amazonaws.com/misc/deJong/docs/deJong.ht... Edit: I've added a permalink button, so that you can link directly to interesting coordinates that you discover: http://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html#599,182 http://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html#59...
- dbaupp 14y agoIn the comments on the gist there is a canvas version too: http://fiddle.jshell.net/aemkei/d99PL/show/ http://fiddle.jshell.net/aemkei/d99PL/show/
- tholman 14y agohttp://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html#-283,666 http://jashkenas.s3.amazonaws.com/misc/deJong/deJong.html#-2...
- beneater 14y agoHere's a quick port to Khan Academy's new CS scratchpads: http://www.khanacademy.org/cs/lorenz-attractor/966238447 http://www.khanacademy.org/cs/lorenz-attractor/966238447
- ehosca 14y agoITT Schaub- ?
- jianshen 14y agoNostalgic! Fractals are what got me interested in programming when I was a student because I always wanted to know how to "draw infinitely".
- julian37 14y agoThis looks just like the C code on Paul Burke's page [1], except that the translation to JS isn't quite correct because x gets updated before yz are calculated (and y before z) due to sequential parameter evaluation. And the 101 bytes conveniently doesn't count any of the rendering and other code. The result is still pretty, but that's a bit too much handwaving for my taste. [1] http://paulbourke.net/fractals/lorenz/ http://paulbourke.net/fractals/lorenz/
- blorenz 14y agoGood use of 101 bytes! I'm attracted to it.
- jahewson 14y agoGreat. It's just a shame about the boneheaded "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE". It makes you look like a complete idiot.
- sp332 14y agoIt's really not worth licensing hassle for this amount of code.
- ctdonath 14y agoIt's really not worth dragging otherwise nifty code into the gutter with unnecessary obscenity. "Public domain" would suffice. Yes, a significant percentage of the population does have a problem with needless obscenity.
- EvanAnderson 14y agoIn some jurisdictions it isn't possible for creators to disclaim all their rights. In those cases something like WTFPL (or, in a more tasteful manner, CC0) is necessary.
- cshesse 14y agoWhich I suppose is why there's a 2:1 license-to-code ratio for this project.
- sp332 14y agoYes and even so it might not be legally valid. US copyright law is overly restrictive by default. It takes an effort to loosen it up a bit. c.f. Creative Commons project.
- wccrawford 14y agoWouldn't that be even more reason to just pick a license that doesn't ruffle feathers? BSD is nice. So is MIT. Says the same thing but doesn't get people to post "Why'd you pick that license?" posts.
- 0x0 14y agoClaiming 101 bytes feels a bit like cheating, since you need a bunch of setup and painting code to drive the algorithm, don't you think? :)
- karpathy 14y agoI ported this to the newly announced Khan Academy CS sandbox :) http://www.khanacademy.org/cs/lorenz-attractor/966338554 http://www.khanacademy.org/cs/lorenz-attractor/966338554
- bdon 14y agoNot quite 101 bytes, but here's an interactive version in WebGL: http://bdon.github.com/strange_attractor/ http://bdon.github.com/strange_attractor/ (Only works in Chrome)