4 ms·
'Carmack Lines': Playing with Javascript
- mseepgood 13y agoTook me less than 5 minutes: http://play.golang.org/p/RnrpAs-iH5 http://play.golang.org/p/RnrpAs-iH5 I really like the outcome with multiplication: http://play.golang.org/p/vF9aq6xF10 http://play.golang.org/p/vF9aq6xF10
- zhemao 13y agoYou get some interesting box patterns if you use bitwise operators.
- wreegab 13y agoGo compiles so fast, would be nice to have it available as a scripting language in the browser. But that's me superficially thinking, there is probably a lot of various complications and security issues.
- RamiK 13y agoNot exactly what you want, but works to the same effect: https://docs.google.com/document/d/1oA4rs0pfk5NzUyA0YX6QsUEErNIMXawoscw9t0NHafo/pub https://docs.google.com/document/d/1oA4rs0pfk5NzUyA0YX6QsUEE...
- colmmacc 13y agoThat is nice! I couldn't resist the curiosity about the other operators, so I extended your code to include them all on one page for easy comparison; http://play.golang.org/p/O0F1FiAl6C http://play.golang.org/p/O0F1FiAl6C mod looks super interesting too.
- dwild 13y agotry y^2 + x^2 and y^2*x^2
- elwell 13y agoOh wow the multiplication one is cool
- kenrick95 13y agoAwww I see optical illusion!
- foobarian 13y agoWonder why this was hard to imagine. x+y is constant along diagonal lines, and any given bit flip will happen every 2^b pixels. Multiplication may be a little harder but still it's a quick way to paint contour lines.
- azakai 13y ago> I’m kind of amazed at how fast Javascript executes I'm a little surprised by the author's surprise. I am on an old 1GHz laptop right now, and on both firefox and chrome it runs so fast there is no noticeable delay between clicking and seeing a result. Which seems reasonable because it's doing a pretty small computational loop that browsers are quite good at optimizing these days. Browsers have been competing on exactly these things for years.
- krazydad 13y agoI've been making these for a long time. One of my favorites is (x XOR y) MOD 3 != 0 ((x ^ y) % 3) != 0 Other primes like 5 and 7 look interesting as well.
- GyrosOfWar 13y agoWith ((x | y) % 7) != 0), I get this result in Processing: http://i.imgur.com/K35xxI7.png http://i.imgur.com/K35xxI7.png I think I know what I'll do for the rest of the evening.
- rongenre 13y agoWow, very cool: http://play.golang.org/p/1X6UljMqpD http://play.golang.org/p/1X6UljMqpD
- coldsmoke 13y agoNice! There is a bug though that confused me a bit. The input has the value 1, but the hardcoded call of the draw function uses 7 on page load. I.e. line 66 draw(7);
- csbrooks 13y agoOops, sorry about that! Fixed now.
- gregschlom 13y agoThat's nothing. I was _blown away_, absolutely blown away, when I saw a Sierpinsky triangle emerge out of bitwise AND: http://play.golang.org/p/VQ-gEFB271 http://play.golang.org/p/VQ-gEFB271 (Sorry for the ugly code, I just copy/pasted and changed the example from mseepgood here, and I'm not a Go coder.)
- archgoon 13y ago> I’m kind of amazed at how fast Javascript executes, at least in Chrome. I’m iterating over 16,384 pixels every time you hit the button, and there’s no perceptable delay at all, at least on my Macbook. You have a computer that can execute 3 billion synchronous instructions per second* . Suppose that javascript was extremely inefficient (it's not), and required 10,000 machine instructions to iterate through the loop and set a pixel. The time to execute 10,000 machine instructions is about 50 milliseconds. I found that I didn't notice a delay until about 200 milliseconds (modifying the code with a setTimeout function). Such excessive waste would not be noticeable to a casual observer (you can run randomized A/B tests on yourself to investigate this :) ). The work that has gone into v8 is very impressive. Arguably, however, the sheer brute force power of modern CPU's is more so. Don't underestimate it. :) * Give or take. Setting pixels is an offscreen operation and should incur minimal I/O and scheduling overhead.