{"id":26,"date":"2012-02-26T23:37:53","date_gmt":"2012-02-26T23:37:53","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2012\/02\/adding_colour_to_a_mandelbrot_set-shtml\/"},"modified":"2012-02-26T23:37:53","modified_gmt":"2012-02-26T23:37:53","slug":"adding_colour_to_a_mandelbrot_set-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/","title":{"rendered":"Adding Colour To A Mandelbrot Set"},"content":{"rendered":"<p>\nI was looking for a way to introduce some colour into my example <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/archive\/2012\/2\/Drawing_A_Mandelbrot_Set_With_Zend_PDF.shtml\">Drawing A Mandelbrot Set With Zend PDF<\/a>.\n<\/p>\n<p>\nThe method I settled upon was to use HSV &#8211; Hue, Saturation, Value.\n<\/p>\n<p>\nI&#8217;m not an expert on colour theory, so I may not be the best person to describe how it works. The best way I can though, is to describe it as a cylinder, round the circumference is the hue, the radius is the saturation, and the height is the value. For a detailed definition, read <a href=\"http:\/\/en.wikipedia.org\/wiki\/HSL_and_HSV#From_HSL\">the Wikipedia entry on HSL and HSV<\/a>.\n<\/p>\n<p>\nI can pick a hue and value, then just vary the saturation to give a nice graduated colour version of the earlier grayscale example.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/robblog\/images\/mandelbrot_pdf3.png\" width=\"494\" height=\"500\" alt=\"Blue Mandelbrot\" class=\"blogimage\" \/>\n<\/p>\n<p>\nAlternatively I can pick a value and saturation, and vary the hue to give a vivid rainbow style fractal.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/robblog\/images\/mandelbrot_pdf4.png\" width=\"494\" height=\"500\" alt=\"Vivid Mandelbrot\" class=\"blogimage\" \/>\n<\/p>\n<p>\nTo achieve the first, we replace the code in the loop that prepared the grayscale colours, and instead generate our <var>$colours<\/var> array with the following&#8230;\n<\/p>\n<pre class=\"lang:php decode:true \" >list($red, $green, $blue) = hsvToRgb(0.5, $grayLevel, 1);\n$colours[$i] = new Zend_Pdf_Color_Rgb($red, $green, $blue);\n<\/pre>\n<p>\nFirstly we get the values for <var>$red<\/var>, <var>$green<\/var> and <var>$blue<\/var> for a hue of 0.5 (blue), our varying $graylevel between 0 and 1, and a $value of 1 for the most vivid colours. After this we create a <var>Zend_Pdf_Color<\/var> and store it in the <var>$colours<\/var> array to use later.\n<\/p>\n<p>\nTo achieve the latter we just change how we call the <code>hsvToRgb<\/code> function.\n<\/p>\n<pre class=\"lang:php decode:true \" >list($red, $green, $blue) = hsvToRgb($grayLevel, 1, 1);\n$colours[$i] = new Zend_Pdf_Color_Rgb($red, $green, $blue);\n<\/pre>\n<p>\nNow, you may have noticed that there isn&#8217;t a function called <code>hsvToRgb<\/code> available to PHP. Just drop in the following code.\n<\/p>\n<pre class=\"lang:php decode:true \" >function hsvToRgb ($hue, $saturation, $value)\n{\n  $rgb = array($value, $value, $value);\n  if ($saturation != 0) {\n    $varH = $hue * 6;\n    $varI = floor($varH);\n    $var1 = $value * ( 1 - $saturation );\n    $var2 = $value * ( 1 - $saturation * ( $varH - $varI ) );\n    $var3 = $value * ( 1 - $saturation * (1 - ( $varH - $varI ) ) );\n    if ($varI == 0) {\n      $rgb = array($value, $var3, $var1);\n    } else if ($varI == 1) {\n      $rgb = array($var2, $value, $var1);\n    } else if ($varI == 2) {\n      $rgb = array($var1, $value, $var3);\n    } else if ($varI == 3) {\n      $rgb = array($var1, $var2, $value);\n    } else if ($varI == 4) {\n      $rgb = array($var3, $var1, $value);\n    } else {\n      $rgb = array($value, $var1, $var2);\n    }\n  }\n  return $rgb;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I was looking for a way to introduce some colour into my example Drawing A Mandelbrot Set With Zend PDF. The method I settled upon was to use HSV &#8211; Hue, Saturation, Value. I&#8217;m not an expert on colour theory, so I may not be the best person to describe how it works. The best &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding Colour To A Mandelbrot Set&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[50,81],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-dev","tag-php","tag-zend-framework"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Adding Colour To A Mandelbrot Set - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding Colour To A Mandelbrot Set - Robert Price\" \/>\n<meta property=\"og:description\" content=\"I was looking for a way to introduce some colour into my example Drawing A Mandelbrot Set With Zend PDF. The method I settled upon was to use HSV &#8211; Hue, Saturation, Value. I&#8217;m not an expert on colour theory, so I may not be the best person to describe how it works. The best &hellip; Continue reading &quot;Adding Colour To A Mandelbrot Set&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2012-02-26T23:37:53+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Adding Colour To A Mandelbrot Set\",\"datePublished\":\"2012-02-26T23:37:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/\"},\"wordCount\":250,\"keywords\":[\"PHP\",\"Zend Framework\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/\",\"name\":\"Adding Colour To A Mandelbrot Set - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2012-02-26T23:37:53+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/adding_colour_to_a_mandelbrot_set-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding Colour To A Mandelbrot Set\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding Colour To A Mandelbrot Set - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Adding Colour To A Mandelbrot Set - Robert Price","og_description":"I was looking for a way to introduce some colour into my example Drawing A Mandelbrot Set With Zend PDF. The method I settled upon was to use HSV &#8211; Hue, Saturation, Value. I&#8217;m not an expert on colour theory, so I may not be the best person to describe how it works. The best &hellip; Continue reading \"Adding Colour To A Mandelbrot Set\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/","og_site_name":"Robert Price","article_published_time":"2012-02-26T23:37:53+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Adding Colour To A Mandelbrot Set","datePublished":"2012-02-26T23:37:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/"},"wordCount":250,"keywords":["PHP","Zend Framework"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/","name":"Adding Colour To A Mandelbrot Set - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2012-02-26T23:37:53+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/adding_colour_to_a_mandelbrot_set-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Adding Colour To A Mandelbrot Set"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}