{"id":3416,"date":"2014-11-12T02:10:30","date_gmt":"2014-11-11T23:10:30","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=3416"},"modified":"2014-11-12T02:11:10","modified_gmt":"2014-11-11T23:11:10","slug":"draw-munching-squares","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2014\/11\/12\/draw-munching-squares\/","title":{"rendered":"Draw Munching Squares"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3417\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/11\/12\/draw-munching-squares\/munching_squares_unity_csharp\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?fit=412%2C412&amp;ssl=1\" data-orig-size=\"412,412\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"munching_squares_unity_csharp\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?fit=412%2C412&amp;ssl=1\" class=\"alignnone size-full wp-image-3417\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?resize=412%2C412\" alt=\"munching_squares_unity_csharp\" width=\"412\" height=\"412\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?w=412&amp;ssl=1 412w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?resize=300%2C300&amp;ssl=1 300w\" sizes=\"auto, (max-width: 412px) 100vw, 412px\" \/><\/p>\n<p>Converted this php script into unity, while trying to keep it similar to original code..<br \/>\nagain some difference in the output but close enough..<br \/>\n<a title=\"http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP\" href=\"http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP\" target=\"_blank\">http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Source c#<\/strong> (MunchingSquares.cs)<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ Original source: http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\n\r\npublic class MunchingSquares : MonoBehaviour\r\n{\r\nvoid Start ()\r\n{\r\nMakeMunch();\r\n}\r\n\r\nvoid MakeMunch()\r\n{\r\nint w = 256;\r\nint h = 256;\r\nTexture2D im = new Texture2D(w, h);\r\nif (im==null) Debug.LogError(&quot;Cannot Initialize new texture&quot;);\r\n\r\nList&lt;Color&gt; color = new List&lt;Color&gt;();\r\n\r\nfor(int i=0;i&lt;256;i++)\r\n{\r\ncolor.Add(new Color( (Mathf.Sin((i)*(2*3.14f\/256))*128+128)\/255 , (i\/2)\/255 , i\/255 , 1));\r\n}\r\n\r\nfor(int i=0;i&lt;w;i++)\r\n{\r\nfor(int j=0;j&lt;h;j++)\r\n{\r\nim.SetPixel(i,j,color&#x5B;i^j]);\r\n}\r\n}\r\n\r\nim.Apply(false);\r\nrenderer.material.mainTexture = im;\r\n}\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converted this php script into unity, while trying to keep it similar to original code.. again some difference in the output but close enough.. http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP &nbsp; Source c# (MunchingSquares.cs) \/\/ Original source: http:\/\/rosettacode.org\/wiki\/Munching_squares#PHP using UnityEngine; using System.Collections; using System.Collections.Generic; public class MunchingSquares : MonoBehaviour { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3417,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[23,3],"tags":[676,189],"class_list":["post-3416","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-functions-unity3d","category-unity3d","tag-munching-squares","tag-script"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/11\/munching_squares_unity_csharp.jpg?fit=412%2C412&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-T6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=3416"}],"version-history":[{"count":2,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3416\/revisions"}],"predecessor-version":[{"id":3419,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3416\/revisions\/3419"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/3417"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=3416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=3416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=3416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}