Advertisement
Guest User

Mandelbrot fractal renderer in a single MySQL query

a guest
Sep 20th, 2012
4,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.86 KB | None | 0 0
  1. /*     A Mandelbrot renderer in a single MySQL-query.    */
  2. /* Use a monospace-font to correctly display the output! */
  3. /*                by niktator<at>live.com                */
  4. SELECT if(ASCII(concat(
  5. @w:=180,    /* width */
  6. @h:=72,     /* height. max. resolution: w*h=78125 */
  7. @max_iter:=20,  /* max. iterations - max.: 64 */
  8. @xmin:=-2.025,  /* left */
  9. @xmax:=0.625,   /* right */
  10. @ymin:=-1.25,   /* top */
  11. @ymax:=1.25     /* bottom */
  12. ))+(@cm:=(4/@max_iter))+(@xs:=(@xmax-@xmin)/@w)+(@ys:=(@ymax-@ymin)/@h)+(@cnt:=0)+(@y0:=@ymin)+(@run:=1)+ASCII(@r:=SPACE(0))+(SELECT count(if(@run,if(mod(@cnt,@w),0,(@y0:=@y0+@ys)+if(@cnt,ASCII(@r:=concat(@r,0x0d0a)),0))+(@x0:=@xmin+mod(@cnt,@w)*@xs)+(@i:=@x:=@y:=0)+(@runi:=1)+(SELECT count(if(@runi,+(@xt:=@x*@x-@y*@y+@x0)+(@y:=2*@x*@y+@y0)+(@x:=@xt)+(@i:=@i+1)+if(@i=@max_iter or (@x*@x+@y*@y)>4,@runi:=0,0),0)) from (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) a CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) b CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) c)+(@c:=ceil(@i*@cm))+(@v:=(CASE when @c=4 then char(0xE29688 using utf8) when @c=3 then char(0xE29693 using utf8) when @c=2 then char(0xE29692 using utf8) else char(0xE29691 using utf8) END))+ASCII(@r:=concat(@r,@v))+(@cnt:=@cnt+1)+if(@cnt=@w*@h,(@run:=0),0),0)) FROM (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 ) a CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) b CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) c CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) d CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) e CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) f CROSS JOIN (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) g),@r,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement