{"id":516,"date":"2017-09-28T11:34:55","date_gmt":"2017-09-28T16:34:55","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=516"},"modified":"2017-10-08T14:33:21","modified_gmt":"2017-10-08T19:33:21","slug":"processing-py-how-to-create-grid-square-patterns-and-digital-camo","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-create-grid-square-patterns-and-digital-camo\/","title":{"rendered":"Processing.py: How to create grid square patterns and digital camo"},"content":{"rendered":"<p>Continuing the Processing.py series, this article demonstrates how to use a slight variant of the 10 PRINT example to build a grid pattern design made up of squares of differing sizes and colors. This technique can also produce digital camo (camouflage) patterns!<\/p>\n<p>For the previous entry in the Processing.py series, see this page:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"BPuwpJwmTc\"><p><a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-implement-10-print\/\">Processing.py: How to implement 10 PRINT<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-implement-10-print\/embed\/#?secret=BPuwpJwmTc\" data-secret=\"BPuwpJwmTc\" width=\"600\" height=\"338\" title=\"&#8220;Processing.py: How to implement 10 PRINT&#8221; &#8212; Chris Nielsen Code Walk\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>The variability of the patterns can be determined by using color, square size, backgrounds, square borders (using\u00a0 <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">stroke()<\/code>) , and using <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">random()<\/code> with if statements. In the code shown below, <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">random(1)<\/code> returns a floating point number between 0 and 1 and outputs are determined by where the random number falls between 0 and 100. More ranges can be added for more variability by filtering outputs into smaller and smaller buckets.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">x = 0\r\ny = 0\r\nspacing = 20\r\nrand_point1 = 0.25\r\nrand_point2 = 0.50\r\nrand_point3 = 0.75\r\n\r\ndef setup():\r\n    size(400, 400)\r\n    background(255)\r\n    #stroke(255)\r\n    #stroke(0)\r\n    #strokeWeight(3)\r\n\r\ndef draw():\r\n    global x, y, spacing, rand_point\r\n    noStroke()\r\n\r\n    # Between 0 and 25\r\n    if (random(1) &lt;= rand_point1):\r\n        #fill('#5D4C2E')\r\n        fill(0)\r\n        rect(x, y, spacing, spacing)\r\n    # Between 25 and 50\r\n    elif (random(1) &gt; rand_point1 and random(1) &lt;= rand_point2):\r\n        #fill('#A29980')\r\n        fill(64)\r\n        rect(x, y, spacing, spacing)\r\n    # Between 50 and 75\r\n    elif (random(1) &gt; rand_point2 and random(1) &lt;= rand_point3):\r\n        #fill('#C1B594')\r\n        fill(128)\r\n        rect(x, y, spacing, spacing)\r\n    else:\r\n        #fill('#CECECE')\r\n        fill(255)\r\n        rect(x, y, spacing, spacing)\r\n    x += spacing\r\n\r\n    if x &gt; width:\r\n        x = 0\r\n        y += spacing\r\n\r\n    saveFrame(\"print10_rect21.gif\")<\/pre>\n<p>Here are some of the patterns I was able to create by playing with these variables:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-517 size-full\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/squares.gif\" alt=\"\" width=\"400\" height=\"400\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuing the Processing.py series, this article demonstrates how to use a slight variant of the 10 PRINT example to build a grid pattern design made up of squares of differing sizes and colors. This technique can also produce digital camo (camouflage) patterns! For the previous entry in the Processing.py series, see this page: Processing.py: How &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-create-grid-square-patterns-and-digital-camo\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Processing.py: How to create grid square patterns and digital camo<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,46],"tags":[36,4],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-processing-language","category-processing-py","tag-processing-py","tag-python"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":3,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":520,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/516\/revisions\/520"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}