Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Teapots!

 Teapots!

How to draw the Utah teapot in HTML using only right triangles.

Avatar for Georgios Gousios

Georgios Gousios

October 09, 2013
Tweet

More Decks by Georgios Gousios

Other Decks in Technology

Transcript

  1. <style>    div{  background:Black;            

       position:absolute;                width:9px;  } </style> <div  style="left:10px;  height:10px;"></div> <div  style="left:20px;  height:20px;"></div> <div  style="left:30px;  height:30px;"></div> ... <div  style="left:80px;  height:80px;"></div>
  2. <div  style="font-­‐family:'Comic  Sans  MS'; width:300; border-­‐left:  60  solid  green;  

    border-­‐right:  40  solid  yellow;   border-­‐top:  30  solid  red;   border-­‐bottom:  50  solid  blue;"> My  borders  are  bigger  than  yours </div>
  3. <div  style="width:0; border-­‐left:  60  solid  green;   border-­‐right:  40  solid

     yellow;   border-­‐top:  30  solid  red;   border-­‐bottom:  50  solid  blue;"> </div> Could  do  any  triangle  with   ver2cal  or  horizontal  leg
  4. <div   style="width:0; border-­‐left:  60   solid  green;   border-­‐right:

     0   solid  yellow;   border-­‐top:  30   solid  red;   border-­‐bottom:  0   solid  blue;  "></ div> <div   style="width:0; border-­‐left:  60   transparent;   border-­‐right:  0   solid  yellow;   border-­‐top:  30   solid  red;   border-­‐bottom:  0   solid  blue;  "></ div> <div   style="width:0; border-­‐left:  60   solid  green;   border-­‐right:  0   solid  yellow;   border-­‐top:  30   transparent;   border-­‐bottom:  0   solid  blue;  "></ div>
  5. 10 f(x)  =  αx  +  β analy2c  geometry  101 φ

    α  =  tan(φ) }β  μ(5,4)  v(4,3)
  6. 10 f(x)  =  αx  +  β analy2c  geometry  101 φ

    α  =  tan(φ) }β  μ(5,4)  v(4,3) α  =  (μ.y  -­‐  ν.y)  /  (μ.x  -­‐  ν.x) β  =  μ.y  -­‐  α  *  (μ.x)
  7. 11 f(x)  =  αx  +  β g(x)  =  γx  +

     δ analy2c  geometry  101
  8. 11 f(x)  =  αx  +  β g(x)  =  γx  +

     δ analy2c  geometry  101 (x,  (f(x)|g(x))
  9. 11 f(x)  =  αx  +  β g(x)  =  γx  +

     δ analy2c  geometry  101 (-Long.MaxValue to Long.MaxValue).find(x => f(x) == g(x)) (x,  (f(x)|g(x))
  10. 11 f(x)  =  αx  +  β g(x)  =  γx  +

     δ analy2c  geometry  101 (-Long.MaxValue to Long.MaxValue).find(x => f(x) == g(x)) (x,  (f(x)|g(x)) (min(β,δ) to max(β,δ)).find(x => f(x) == g(x))
  11. 11 f(x)  =  αx  +  β g(x)  =  γx  +

     δ analy2c  geometry  101 (-Long.MaxValue to Long.MaxValue).find(x => f(x) == g(x)) αx  +  β  =  γx  +  δ              <=> αx  -­‐  γx  =  δ  -­‐  β                  <=> x  =  (δ  -­‐  β)/(α  -­‐  γ) (x,  (f(x)|g(x)) (min(β,δ) to max(β,δ)).find(x => f(x) == g(x))
  12. α  (1,4) γ(6,  7) δ  (5,4) Stop when too small

    to see, e.g. when area is 1 or when line is 1 pixel
  13. 16

  14. 16

  15. 17

  16. The challenge • Teams of 2 • Convert code to

    Hack gist:gousiosg/6871500 • Speed it up • Add types • Use Hack containers • Optimize triangle generation • Fastest (relative) speed up wins t-shirt! • Extra hacker’s tie-dye t-shirt if output is HTML!
  17. Rules • The code must produce exactly the same number

    of triangles as base case • Results are reported as mean of 5 runs • Don’t remove assertions • Don’t change triangle generation cutoff • No busy loops in base case :-)