Rendering Mandelbrot and Julia Fractal

Warning! Some information on this page is older than 3 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

21:01
Thu
10
Dec 2009

Rendering Mandelbrot and Julia Fractal

I've been playing recently with Mandelbrot and Julia sets. These are fractals rendered in the completely different way that my last experiments with IFS (Iterated Function Systems). In IFS I had a set of points with given (x,y) positions and I've been transforming their positions iteratively by some functions before I rendered them. I'll blog more about IFS another time. Rendering Mandelbrot and Julia fractals is more like writing a pixel shader - for every pixel on the screen with its (x,y) coordinates we do some computations to calculate final color. I didn't extend my framework to render such things yet, but instead I've been doing my experiments in EvalDraw (where I can freely pan and zoom the view) and AMD RenderMonkey (where I can write pixel shaders executed on GPU).

Complex Numbers for Game Developers :) Fractal is a mathematical concept and so there is lots of hardcore math involved in the foundation of these beautiful objects. But fortunately we don't have to understand all that stuff to be able to render them. Mandelbrot and Julia fractals are created using complex numbers, but for us they can be thought of just as float2/D3DXVECTOR2 2-component (x,y) vectors with some operations defined:

That's actually all we need to render Mandelbrot and Julia fractals. The general formula for both of them is: z = z^2 + c where z and c are complex numbers, c is a constant and z is recalculated many times through this function. It was a mystery for me for a long time how to apply this formula. Now it turned out that when we calculate it many times for each pixel with staring z_start = (0, 0) and c dependant on pixel position in range (-2..2, -2..2) and draw all the pixels for which z is bounded and do not go to infinity, we get the shape of the Mandelbrot fractal. Of course we are not going to iterate this function inifinite times in our computers like mathematicians do in their heads, so instead we do it several times and treat all pixels for which length(z_final) < 2 as being "inside" the shape. Here is a draft made in EvalDraw. Unfortunately we meet some limitations of floating point numbers here, like limited precision and infinites and that's why the space outside is white.

To render Julia set we do something similar, but this time we use pixel position as starting z and set c to some constant, like (-0.1, 0.7). Different constants make different images.

A question arises about how to render a fractal - how to map a complex number to pixel color? The algorithm I like the most is called Escape Time Algorith and it goes like this: recalculate z for several iterations, but only while the length of z=(x,y) vector is less than 2 (that is zx*zx + zy*zy < 2*2). If the loop reached the iteration count limit, this pixel is inside the fractal - draw in in black. If not, then color of this pixel depends on number of iterations done.

Here are my implementations of these fractals in EvalDraw and RenderMonkey. They are very simple so the whole source code is visible on the screenshots. You can also download the code here: Fractals_for_RenderMonkey.rfx, Mandelbrot_for_EvalDraw_1.kc, Julia_for_EvalDraw_1.kc, Multibrot_for_EvalDraw_1.kc. You can find more screenshots in my fractals gallery.

Some variations of these fractals have also been discovered. For example when we do absolute value of z components before every iteration in Mandelbrot fractal, we get an interesting shape called Burning Ship.

Alternatively, if we raise z to any real power instead of 2, we make Mandelbrot fractal "unfolding", having more and more "bulbs" as the exponent grows. It is called Multibrot set. Raising a complex number to power with any real exponent is a little bit more complicated, as it has to use polar form (HLSL-like pseudocode here):

float2 ComplexPow(float2 v, float n)
{
  float len = sqrt(x*x + y*y); // Standard 2D vector length
  float n_fi = n * atan2(y, x);
  return pow(len, n) * float2( cos(n_fi), sin(n_fi) ); // scalar * vector
}

Comments (1) | Tags: rendering math fractals | Author: Adam Sawicki | Share

Comments

wxm
2016-03-29 09:45:07
beautiful things www.rayban.org.es to www.ray-ban-outlet.us.com read more, www.michael-kors.net.co look www.tnf-jackets.us.com for www.nike-schuhe.com.de a long www.nike-roshe-run.com.es time, www.toms--outlet.com.co I www.abercrombieand-fitch.ca felt www.basketballshoes.com.co closer www.ugg-boots.ca to www.uggboots.com.de reality www.oakleyoutlet-online.us.com very www.hogan.com.de far away, www.airmax-2015.org life www.uggsoutlet.com.co is short, www.michaelkorsoutletonline-sale.us.com if www.beats-headphone.com.co put www.cheap-jordans.net too www.swarovskicanada.ca much www.cheapoakley-sunglasses.in.net time www.louis-vuitton-australia.com.au is www.tiffany-und-co.de spent on www.mcm-bags.in.net practical www.tocoachoutlet.com things, really www.ugg-boots-australia.com.au is www.ugg-australia.com.de a www.ralph-lauren.com.au waste www.pandorajewelry.top of www.nike.org.es life, www.thenorthface.com.de but some www.eyeglassesonline.us.com things, www.nike--freerun.co.uk but www.canadagooses-2016.com if www.longchamp.com.co the www.gucci-taschen-outlet.de raw flavor, www.outlet-burberry.net.co leisure www.nike-shoes-canada.ca goods airmax.shoesoutlet.us.com for www.oakleys-sunglasses.us.com gossip, www.marcjacobs.us.com so www.hermes-outlet.com.co I www.asicsgels.de love www.chanel-bags.com.co romantic www.christianlouboutinshoesoutlet.org dreamer, www.rolexwatches-canada.ca but www.timberlandbootsoutlet.us.com I www.ray-bansunglasses.net love www.wedding--dresses.ca real www.katespadeoutlet.gb.net life.Day www.tomsoutletonline.net in www.nikefactory.org a hurry, took www.iphone-cases.net.co all www.bottega-veneta.us.com the www.p90xworkout.us.com joy www.rolex-watches.us.com and www.truereligion-outlet.com.co sadness, www.hollisteronlineshop.com.de a www.replica-watches.com.co lot www.nikeshoesoutlet.org.uk of www.michael-kors-taschen.com.de things, not www.soccer-shoes.us.com enough www.giuseppe-zanotti.net time www.louisvuitton-outlet.com.co to www.nike-tnrequinpascher.fr recall, www.michaelkorsoutlet.ar.com Chaoyang www.polo-ralph-lauren.de July, www.coach-outletonline.net.co early www.ralphs-lauren.co.uk June already www.juicycoutureoutlet.net.co covered www.longchamp.com.de confused. www.jimmy-choos.com Season www.toryburchsale.com.co removed, www.nike-skor.com.se landscape www.prada-handbags.com.co transformation, www.christian--louboutin.in.net the so-called forever www.cheapoakley-sunglasses.com always www.designer-handbagsoutlet.us.com far-fetched, www.ralphlaurenoutlet-online.us.com time, www.mizuno-running.net not www.thomas-sabos.org.uk to www.nikerosherun.us be www.burberry2016.co.uk squandered, www.nfl-jersey.us.com the www.omegarelojes.es true meaning of life www.truereligion-outlet.us.org is www.michael-kors.com.co to www.cheaprayban.com.co enjoy the good www.michaelkors.so in www.tommyhilfiger.net.co the www.rosheruns.us flat, www.christianlouboutin.org.uk I www.mcmbags.net Dimei airhuarache.shoesoutlet.us.com fireworks, www.tiffanyandco-canada.ca also airmax.misblackfriday.com read www.rayban-sunglassesoutlet.co.uk the www.louisvuittons.com.co leisure, www.moncler-outlet.us.org with www.raybans-sunglassesoutlet.in.net a www.lauren-ralph.co.uk touch www.ralph-laurenoutlet.ca of www.converse-shoes.net ink, www.louis-vuittonoutletcanada.ca painting www.nike-rosherun.nl a www.nike-air-max.com.de thin www.ugg-bootsclearance.com clear www.coach-factoryyoutletonline.net Huan, www.toms-shoes.net.co look www.coachoutlet-online.com.co lush www.michaelkors-uk.org.uk green, www.burberryoutlet2016.us.com covered www.chi-flatiron.us.com with www.nikemercurial.in.net mottled www.michaelkors-outlet-online.com.co wall. www.oakley.org.es This www.toms-shoes.com.co July, I www.michaeljordan.com.de kept www.woolrich-clearance.com the www.mcmsworldwide.com book's www.burberry-handbagsoutlet.com.co swoosh; www.beats-by-dre.com.co this www.oakleys-glasses.us.com July, www.hollister-abercrombie.com.se I www.jordan-shoes.com.co dream www.montblanc--pens.in.net in www.tommyhilfigeroutlet.in.net Lijiang; www.nike-air-max.ca this www.burberrybags-outlet.com July, and has www.burberryoutlet-sale.in.net been well, not www.supra-shoes.org made www.new-balance.ca sad.If www.oakley-sunglasses.mex.com you www.coach-factory.in.net can www.levisjeans.com.co do www.lululemon-australia.com.au if www.christian-louboutin-shoes.ca a www.tory-burchshoesoutlet.net light www.celine-bags.org breeze www.tiffany-andco.us.com right www.louboutin.jp.net woman, www.hollister.us.org placed www.oakley.com.de in the www.designerhandbagsoutlet.net.co text www.beatsbydrdre.co.com soul, www.valentino-shoesoutlet.us.com written www.coco-chanels.us.com imprint of www.ghd-hairstraightener.net life, write www.longchamp-handbagsoutlet.us.com thin www.nike-air-max.com.se cool www.adidas.com.se and www.cheap-oakleyglasses.us.com clear www.thomas-sabo.com.de Huan, www.new-balance-schuhe.de occasionally www.ferragamoshoes.in.net write www.soccer-shoesoutlet.com love, www.nike-shoesoutlet.us.com but www.babyliss-pro.us.com never uggaustralia.misblackfriday.com give www.louis-vuittonblackfriday.com love, www.michael--kors.us.com keep www.tomsshoes-outlet.us.com a www.swarovski--uk.me.uk clear www.replicarolex-watches.us.com gel www.calvin-kleins.us.com Bay, www.retro-jordans.com look www.fashionclothes.us.com for www.omega-watches.us.com a www.reebok.com.de parts www.pulseras-pandora.com.es of www.burberrys-outlet.co.uk the www.timberlandshoes.net.co peace, www.hollisterclothingstore.org the www.rosherun.org.uk joy www.the-northface.net.co and www.bottegaveneta-bagsoutlet.com sorrow www.jordanretro.org of www.pandorajewellery.com.au all www.michael-korshandbags.org.uk his www.harrods-london.co.uk writings, www.longchamp-bags.us.com and www.longchampoutlet.com.co text www.montres-pascher.fr only www.vans-shoes.net affair has www.tiffanyand-co.net.co nothing www.uggboots.net.co to do www.toms-outlets.us.com with www.rayban.co.nl the www.chanelhandbags.net.in other.Morning www.ralphlauren-polos.com.co time, www.michael-kors-outlet.us.org with www.tiffany-jewelry.net a www.polo-outlets.com.co tranquil www.uggs-onsale.net and www.the-northface.com.co contented www.converse.net.co Zen cloud www.newbalance-outlet.org water, www.christianlouboutinoutlet.net.co eyes www.guccioutlet-sale.in.net closed, www.nikefree-run.org.uk the www.newbalance.com.es heart www.kate-spade.in.net distant www.truereligionjeans.net.co exile, www.michael-kors-handbags.us.com Wind www.nike-maxfr.com and www.chiflatiron.net.co Smoke www.instylers.us.com curl www.louis--vuitton.org.uk in www.nike-airmaxinc.co.uk the www.raybans.us.org mountains, www.the-north-face.ca such www.adidas--canada.ca as Dai, www.nikefree5.net ups www.true-religion.com.co and www.toms-shoesoutlet.net downs, www.giuseppezanotti.com.co indeed, www.juicycouture.com.co like a www.abercrombie-hollister.nl thread, www.airhuarache.co.uk the www.nikeair--max.fr ups www.soft-ballbats.com and downs www.coco-chanel.com.de of www.ray--ban.ca life, www.christian-louboutinshoes.com.co with www.swarovskijewelry.com.co long www.oakleysunglasses-cheap.in.net Qingyuan www.nikeskos.dk . Flowers www.air-huarache.co.uk followed www.newoutletonlinemall.com the www.marc-jacobs.us.com road, www.rayban.com.de facing www.vans-schuhe.com.de the www.yoga-pants.ca sun www.coach-factoryoutlet.net.co slowly www.cheapuggboots.us.com forward, www.longchamps.us.com then the www.beatsbydre.com.co mind www.weddingdressesuk.org.uk is www.louisvuitton.so calm, www.adidas.org.es quiet www.uhren-shop.com.de as www.airmax-90.org the www.poloralphlaurenoutlet.net.co lake, www.uggs.in.net the www.toryburchoutlet-sale.us.com water www.tommy-hilfigeroutlet.com peach, flower www.abercrombie-and-fitch.us.com with www.nike-air-max.com.au water, just www.hollister-clothing.in.net like www.cheap-raybans.com the www.adidas-schuhe-online.de fate www.oakley--sunglasses.com.au of www.thenorthfacejackets.net.co this www.adidas-superstar.de world, www.burberry-outletonlinesale.in.net do not www.oakleysunglass-outlet.net ask why, www.converse.com.de regardless www.bcbg-max-azria.ca of www.louisvuitton.jp.net come www.guccishoes-uk.co.uk and www.cheap-nike-shoes.net go, www.ralphlaurenpolos.in.net only flowers www.oakley-sunglasses-canada.ca need www.toryburch-sandals.in.net to www.tommy-hilfiger.co.nl remember www.michaelkorsoutlet-online.ar.com Lu www.polooutlets-store.com Qing, Yue www.edhardy.us.org possessor www.nike-schoenen.co.nl of www.vans-shoes.co.uk the www.mk-outlet.us.com green www.tomsoutlet-online.com heart, www.maccosmetics.net.co cool count. www.ralph-laurens.org.uk Sunlight www.ugg-uggboots.net penetration mist, www.pumaonline-shop.de alluding www.abercrombie-fitchs.us.com on www.hermesbirkin-bag.net the www.ralphslauren-outlet.co.uk lake, www.nikestore.com.de the www.louis-vuitton-taschen.com.de water green, www.replica-handbags.net.co clear, www.pumashoes.in.net sparkling, on www.swarovski-online-shop.de the www.burberry-handbags2016.in.net beach, www.michaelkorsbags.us.org there www.thenorth-faces.co.uk are birds www.coachblackfriday.com flying www.pradaoutlet.com.co over www.canada-goosesjackets.us.com from www.hermesbags.jp.net time www.tommy-hilfiger.com.de to time, www.eyeglassframes.in.net the sky www.barbour-factory.com blue and www.air-max.com.de empty, www.burberryonlineshop.de with nike.shoesoutlet.us.com a www.pandora-charms-canada.ca quiet www.maccosmetics.gr.com life www.converse-shoesoutlet.com after www.ralphlaurenonlineshop.de ups www.cheapjerseys.com.co and www.cheapjerseys.us.org downs, www.coachoutletstore.net.co this www.uggs.co.nl time www.ray-banocchiali.it the www.handbagsoutlet.net.co heart supra.shoesoutlet.us.com is close www.mkoutletonline.us.com to www.ralphlaurenoutletonline.us.org nature, www.burberryoutlet-canada.ca without www.newbalance-shoes.org the www.adidas-superstar.nl slightest ripples, www.mcmhandbags.com.co content www.michaelkors.co.nl with www.hollisters-canada.ca this www.mmoncler-outlet.com quiet www.michaelkors.com.se and www.horloges-rolex.nl peaceful. www.tommy-hilfiger-online-shop.de An www.nike-air-max.us end, www.michael-kors-outlet-online.us.org wins the www.nike-roshe-run.de snow www.mcm-handbags.org lotus, www.michael-kors-canada-outlet.ca world www.ferragamo.com.co clarity, www.barbour-jacketsoutlet.com years www.rayban-wayfarer.in.net of www.rayban-sunglasses.us.org silence, www.thejoreseproject.com the heart www.guccishoes.com.co is www.nike-air-force.de also www.cheap-baseballbats.net safe.Time, very www.burberry-outletstore.net long. www.adidasshoes.top I www.nike-huarache.nl know, www.jimmy-chooshoes.com I www.michael-kors-australia.com.au can www.ralphlaurenoutlet.us.com stay www.tiffany-andco.com.au in my www.nikefree-run.net mind www.gucci-outletstore.com there www.nikestore.us are www.timberlands-paschere.fr limitations, www.jordanrelease-dates.us.com not www.oakley-outletstore.in.net the www.ghdhair-straighteners.co.uk majority, can www.ralphlauren-polos.co.uk only www.nike-free-run.de rely www.bcbg-dresses.com on www.salomon-schuhe.com.de these www.airjordans.us words www.swarovski-australia.com.au to www.pandora.com.de memory.Time, www.asics-outlet.us.com is very www.kate-spade.gb.net short. www.zxcoachoutlet.com I www.prada-shoes.com.co understand, www.ralphlaurenepolo.com you www.oakleyoutlet.ar.com can www.prada.com.de never www.burberrys-outlet2016.com forget www.yoga-pants.net.co so www.ugg-boots.us.org little, www.cheapshoes.com.co so www.christianlouboutinshoes.jp.net I www.rolexwatchesforsale.us.com was www.northfaceoutlet.com.co in www.coachoutletstore-online.com.co such a www.polos-ralphlauren.us.com manner www.gucci-shoes.net so www.pandora-charms.org.uk as www.uggsaustralia.com.co to www.guccihandbags.net.co leave some www.tommy-hilfiger-canada.ca more.Youth, is www.guccishoes.in.net very long. www.cheapmichaelkors.us.org In www.salvatoreferragamo.in.net life, shiny www.swarovski-crystal.us.com people, www.scarpe-hoganoutlets.it in www.nikeair-max.es fact, www.insanity-workout.us.com that www.bebeclothing.in.net a www.coachhandbags2016.us.com figure, www.louisvuitton-outlets.us how www.cheap-michaelkors.com the www.abercrombie-kids.us.com passage of www.coach-purseoutlet.net time, www.pradahandbags.net.co or the www.rolex-watch.me.uk whole www.the-northfacejackets.us.com dazzling Love.Youth, www.michael-kors.com.es is www.burberry-outlet.net.co very www.lululemoncanada.ca short. www.ralphlaurenoutletonline.in.net In www.longchamphandbagsoutlet.net life, flickering days www.abercrombie-fitchsale.com

www.lululemonoutlet.gb.net

Post comment

Nick *
Your name or nickname
E-mail
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2016 Adam Sawicki
Copyright © 2004-2016 Adam Sawicki