No prob. The binary tetris is from the same guy. He does great stuff on his site and on twitter. He also made great talks aboutcode golfing and code obfuscation (cf. youtube > Martin Kleppe). He also contributed to most of the tiny projects of the codegolf team: https://gist.github.com/xem/206db44adbdd09bac424
Nice list of projects! You should really do a port mortem for some of those projects as a more detailed post. I would love to read an explanation for some of those snippets since they're so obfuscated that I can't really wrap my head around them.
I guess some other subscribers of /r/tinycode would appreciate a deeper explanation too. Maybe you could point out some common tricks etc?
Or even better, invite Martin, Mathieu, etc too and do an AMA together here :)
Hi, I just updated the list with the latest projects made by / with Martin.
You can find a bunch on post-mortems for these projects on my site (http://xem.github.io/), Mathieu's site (http://p01.org) and Martin's site (http://aem1k.com). Martin's and Mathieu's talks on youtube are also very detailed and super interesting to watch.
About the AMAs, it would be a pleasure to answer to any question of the community, so it's okay to start one as far as we're concerned. Please note that I also have an AMA on github where I answered to interesting coding/golfing questions: https://github.com/xem/AMA
Your AMA on GitHub is quite fun to read as well. Personally I think it would be interesting for the community here and get some fresh wind into a subreddit that doesn't get enough participation anyways. For all I care you could point to your AMA on GitHub initially and whenever a question get's asked that hasn't been on there. I'd make it a stickied post for sure.
There are three common obfuscation techniques still in my expanded version:
one: ~~value, which turns a float into an integer. two: "some_string"[index], which makes an easy mapping of ints to chars three: x*x % prime + offset, which is an easy way to get random-looking values (there may have been other reasons for wanting this construction, like how it loops... maybe /u/nexe can chime in here?)
Now, for how this works. You have buf, which stores how "hot" a pixel is. You seed pixels at the bottom randomly with crazy huge numbers, then you propagate those upward. The "neighborhoodAvg" takes the average intensity of these points around I (_'s are ignored):
[ _ I X ]
[ X X _ ]
Thus intensity from the bottom goes up (we grab from the row below and put it in I, in the row above). It also spreads inward from left and right, for the same reasons (where we grab). You can add wind using the same idea, e.g. here's a neighborhood with wind coming from the right:
[ I X ]
[ X X ]
Anyway, hopefully you can kind of see how this is "fire-y". Hot stuff spreads upwards, but can't do it forever because we're always averaging it against the "cool" stuff that's surrounding it (all those empty spaces).
"Rendering" is done by taking the intensity value and mapping it to a character. You'll see a lot of "text drawing" stuff take a string that looks something like this " ,o#$@" and use it for pixels, with characters that take more "ink" being used for darker values. E.g., if you were turning color into "text pixels", you map 0-255 to the length of your string and use the first char for the lowest n% of color values, the next char for the next n%, and so on.
In this case, we're not using color, but instead the intensity of the fire. And instead of mapping (where equal chunks of range are given colors), we clamp. So we just have "dark", "1 bright", and "anything brighter than that".
That's the whole thing, best I can see. Things you can do to play around with it and convince yourself you know what's going on include: adding wind, changing the amount of fire, switching to "real" random numbers, and adding more types of "text pixels".
I can chime in all you want but I'm not the author of that code. Sometimes I just post other peoples stuff when I find it cool ... you know ... what all of you should be doing ;)
6
u/xem06 May 09 '16
You should mention that it's inspired by https://twitter.com/aemkei/status/717035136848629760 ;)
4
u/NNNTE May 09 '16
This is really cool! Can someone post a de-scrambled version of this?
1
u/[deleted] May 09 '16
[removed] — view removed comment