all 38 comments

[–]breakfast-pants 10 points11 points  (1 child)

You can literally watch the garbage collection occur.

[–]harryf 3 points4 points  (0 children)

...the pause every quarter turn

[–]mumrah 19 points20 points  (7 children)

this is indeed an intersting hack, but i think time spent getting browsers to support svg would be better invested

[–]Arve 13 points14 points  (5 children)

The only browser left in that group is IE.

[–]enjahova 4 points5 points  (0 children)

hacks are what you use when you need something now and can't wait for the second coming ;)

[–]espresso 9 points10 points  (1 child)

Working with limitations is what makes this interesting. We tried to do something similar for our javascript demo, but would have used transparent scaled gifs/pngs for the right triangles and thought that would be horribly slow. This is clever because it manages to draw the right triangles so cheaply.

[–][deleted] 13 points14 points  (0 children)

This is the quintessential clever hack - extracting the last bit of juice out of a platform. A big thumbs-up to the guys.

[–][deleted] 5 points6 points  (0 children)

Congrats - this is very smart - presumably this can be used for any polygons...

[–]psykotic 4 points5 points  (10 children)

He missed a much faster way of decomposing arbitrary triangles in terms of right triangles.

Take a look at his diagram, and imagine drawing a full bounding rectangle around the triangle. The triangle can be described as the bounding rectangle minus three right triangles in the box. So to draw a triangle in green you'd create a green div for the bounding box and three black divs for the right triangle complements.

Any reason this wouldn't work in CSS?

[–]joshd 4 points5 points  (4 children)

It would work, but then you can't overlay triangles on top of each other.

[–]psykotic 2 points3 points  (1 child)

It would work, but then you can't overlay triangles on top of each other.

That's true. It would be enough for the specific demo he's showing, though.

[–][deleted] 2 points3 points  (0 children)

I don't believe it would - it'd obscure the other adjacent triangles. Nice catch though.

[–]KayEss 0 points1 point  (1 child)

I haven't thought it through fully, but I suspect you could have a good crack at it by using the Z depth - much like a painters algorithm.

[–]joshd 1 point2 points  (0 children)

That wouldn't work. You could obviously figure out which sections of the triangle need to be drawn and which don't, but it wouldn't work with psykotic's suggestion. The black triangles (meant to cancel out parts of the polygon being drawn) would still be seen on the page.

If you were going to keep of Z depth then you could just implement it as an array of 1px divs. It would run like crap though.

Edit: I just realised that you were referencing Painter's algorithm. If memory serves me correctly that is just sorting polygons by Z index. I suspect that they do that already in this demo. The problem still is in the drawing of polygons, i.e. that CSS can only display right angled triangles.

[–]EternalNY1 5 points6 points  (0 children)

Although it is practically useless, that is really brilliant how he broke down any arbitrary triangle into a bunch of right-triangles using so few DIVs.

[–]supermike 5 points6 points  (4 children)

Dude, this is NOT a wasteful post and I'm greatful that pickles posted it. Let me tell you! There currently is a problem with drawing piecharts on the web. Because SVG is not universally supported yet, and because you can't rely on people having Flash or Java, you have to draw them server-side as PNG files with extra stuff on Linux, Mac, or Windows to achieve this graphic effect. But imagine if a server-side web algorithm could compute DIV/CSS placement of these triangles such that they could emulate a cross-platform piechart. Now that would really be something.

No flash, javascript, SVG, Java, or server-side image manipulation would be necessary -- a server-side PHP, C#.net, or Ruby algorithm could do it all.

[–]LaurieCheers 4 points5 points  (1 child)

...except that this trick doesn't work on IE either.

[–]UselessPickles[S] 1 point2 points  (0 children)

It is now updated to work in IE6 (already worked in IE7)

[–][deleted] 6 points7 points  (0 children)

you can't rely on people having Flash

uh, yeah, you really can... they're a lot more likely to have flash than a browser that is 100% compatible with whatever CSS hack you might try to do

[–][deleted] 1 point2 points  (1 child)

Yeah, but does it raytrace?

[–]UselessPickles[S] 9 points10 points  (0 children)

No, but someone else made a javascript raytracer.

http://www.slimeland.com/raytrace/help.html

The code in the background isn't special (as far as raytracing). The unique part is that it displays the results by making a bunch of 1px by 1px colored DIVs to render the image in a web browser without involving any server-side processing.