{"id":1008,"date":"2013-04-12T13:41:48","date_gmt":"2013-04-12T13:41:48","guid":{"rendered":"http:\/\/www.geoplanit.co.uk\/?p=1008"},"modified":"2013-04-18T09:50:22","modified_gmt":"2013-04-18T09:50:22","slug":"quick-tip-using-cityengines-colorramp","status":"publish","type":"post","link":"https:\/\/www.geoplanit.co.uk\/?p=1008","title":{"rendered":"Quick Tip : Using CityEngine&#8217;s colorRamp Function"},"content":{"rendered":"<p><strong>UPDATE : <a href=\"http:\/\/www.arcgis.com\/apps\/CEWebViewer\/viewer.html?3dWebScene=aeebf6c1e166448cb91575fb92c8dc07\" target=\"_blank\">You can view a demo of this rule file in action here via CityEngine&#8217;s webscene web viewer<\/a><\/strong><\/p>\n<p>This is a fun quick tip, instead of assigning a specific colour to each floor and building when not use the built in colorRamp function. \u00a0Search for it in the help file for detailed usage here&#8217;s how I&#8217;ve used it:<\/p>\n<figure id=\"attachment_1009\" aria-describedby=\"caption-attachment-1009\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.geoplanit.co.uk\/?attachment_id=1009\" rel=\"attachment wp-att-1009\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1009\" alt=\"ce_colorramp\" src=\"https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2013\/04\/ce_colorramp.jpg?resize=300%2C194\" width=\"300\" height=\"194\" srcset=\"https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2013\/04\/ce_colorramp.jpg?resize=300%2C194&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2013\/04\/ce_colorramp.jpg?resize=1024%2C665&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2013\/04\/ce_colorramp.jpg?w=1131&amp;ssl=1 1131w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1009\" class=\"wp-caption-text\">Heat island?<\/figcaption><\/figure>\n<p>I&#8217;ve taken a centre point and coloured the rooftop of each building using the colorRamp function. \u00a0 Basically it checks to see how far it is from a chosen point (fixed in the rule file) and normalises it so the value is between 0 and 1 and then uses that value to pick a colour in the depending on your chosen colorRamp.<\/p>\n<p><!--more--><\/p>\n<p>The follow code is only extracts to get you going<\/p>\n<p>&nbsp;<\/p>\n<pre>attr CentreX = 0 \/\/select a node (road junction) and copy values from the attributes to put here\r\nattr CentreZ = 0 \/\/select a node (road junction) and copy values from the attributes to put here\r\n\r\ndistanceToCenter = sqrt((initialShape.origin.px - CentreX )*(initialShape.origin.px - CentreX ) + (initialShape.origin.pz - CentreZ) * (initialShape.origin.pz - CentreZ))\r\n\r\nattrColorValue(x) = 1\/ (radiusLimit-radiusCentre) * (distanceToCenter - radiusCentre) \/\/normalized between 0 and 1\r\n\r\ncolorBasedOnDistance--&gt;\r\n\tcolor (colorRamp(\"yellowToRed\",attrColorValue(distanceToCenter)))<\/pre>\n<p>You can also use the same principles for building heights, for example giving each floor level an individual colour based on its elevation (scope.elevation instead of distanceToCenter).<\/p>\n<p>Let me know if this needs more work, it seems good to me &#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UPDATE : You can view a demo of this rule file in action here via CityEngine&#8217;s webscene web viewer This is a fun quick tip, instead of assigning a specific colour to each floor and building when not use the built in colorRamp function. \u00a0Search for it in the help file for detailed usage here&#8217;s [&hellip;]<\/p>\n","protected":false},"author":161,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"tdm_status":"","tdm_grid_status":"","footnotes":""},"categories":[116,145,231,156,7,54],"tags":[],"class_list":["post-1008","post","type-post","status-publish","format-standard","category-city-creation","category-cityengine","category-code","category-geodesign","category-gis","category-tips"],"_links":{"self":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/users\/161"}],"replies":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1008"}],"version-history":[{"count":6,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1008\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1008\/revisions\/1013"}],"wp:attachment":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}