{"id":503,"date":"2017-09-26T13:24:31","date_gmt":"2017-09-26T18:24:31","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=503"},"modified":"2017-10-08T14:35:13","modified_gmt":"2017-10-08T19:35:13","slug":"processing-py-how-to-use-shapes-placements-and-colors","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/26\/processing-py-how-to-use-shapes-placements-and-colors\/","title":{"rendered":"Processing.py: How to use shapes, placements, and colors"},"content":{"rendered":"<p>To continue the series of how to use Processing.py, this article demonstrates how to use basic shapes, placements and colors.<\/p>\n<p>For the previous entry in the Processing.py series, see this page:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"FYWpE3Nwpd\"><p><a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/09\/25\/processing-py-how-to-draw-lines-and-use-mouse-events\/\">Processing.py: How to draw lines and use mouse events<\/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\/25\/processing-py-how-to-draw-lines-and-use-mouse-events\/embed\/#?secret=FYWpE3Nwpd\" data-secret=\"FYWpE3Nwpd\" width=\"600\" height=\"338\" title=\"&#8220;Processing.py: How to draw lines and use mouse events&#8221; &#8212; Chris Nielsen Code Walk\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>This code demonstrates the use of lines, rectangles, ellipses, colors and placements by sketching a simple scene programmatically.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def setup():\r\n    size(500, 500)\r\n    \r\ndef draw():\r\n    # Make all lines black\r\n    stroke(0)\r\n    \r\n    # draw a horizon line 70% of the way down from the top\r\n    # starting at the left side (0) and ending on the right (width)\r\n    line(0, .70*height, width, .70*height)\r\n    \r\n    # Create the foreground grass\r\n    fill('#99cc00')\r\n    rect(0, .70*height, width, .70*height)\r\n    \r\n    # Create the sky\r\n    fill('#ccfff5')\r\n    rect(0, 0, width, .70*height)\r\n    \r\n    # draw the stem so that it sits on the horizon\r\n    fill('#669900')\r\n    rect(width\/2-5, .70*height-100, 5, 100)\r\n     \r\n    # draw the petals\r\n    fill('#3399ff')\r\n    ellipseMode(CENTER)\r\n    \r\n    ellipse((width\/2)+10, .70*height-80, 30, 30)\r\n    ellipse((width\/2)+10, .70*height-120, 30, 30)\r\n    \r\n    ellipse((width\/2)-10, .70*height-80, 30, 30)\r\n    ellipse((width\/2)-10, .70*height-120, 30, 30)\r\n    \r\n    ellipse((width\/2)-20, .70*height-100, 30, 30)\r\n    ellipse((width\/2)+20, .70*height-100, 30, 30)\r\n    \r\n    # draw the center of the flower\r\n    fill('#ffdf80')\r\n    ellipseMode(CENTER)\r\n    ellipse((width\/2), .70*height-100, 25, 25)\r\n\r\n    # draw sun rays\r\n    line(0, 0, 120, 10)\r\n    line(0, 0, 120, 20)\r\n    line(0, 0, 120, 30)\r\n    line(0, 0, 120, 40)\r\n    line(0, 0, 110, 50)\r\n    line(0, 0, 100, 60)\r\n    line(0, 0, 90, 70)\r\n    line(0, 0, 80, 80)\r\n    line(0, 0, 70, 90)\r\n    line(0, 0, 60, 100)\r\n    line(0, 0, 50, 110)\r\n    line(0, 0, 40, 110)\r\n    line(0, 0, 30, 110)\r\n    line(0, 0, 20, 110)\r\n    line(0, 0, 10, 110)\r\n\r\n    # draw the sun\r\n    fill('#ffff00')\r\n    ellipseMode(CENTER)\r\n    ellipse(0, 0, 150, 150)\r\n    \r\n    saveFrame(\"sun_and_flower.jpg\")<\/pre>\n<p>Which produces:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-504\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/sun_and_flower-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/sun_and_flower-300x300.jpg 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/sun_and_flower-150x150.jpg 150w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/sun_and_flower.jpg 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>For more information, see these pages:<br \/>\n<a href=\"http:\/\/py.processing.org\/tutorials\/overview\/\">http:\/\/py.processing.org\/tutorials\/overview\/<\/a><br \/>\n<a href=\"http:\/\/py.processing.org\/tutorials\/drawing\/\">http:\/\/py.processing.org\/tutorials\/drawing\/<\/a><br \/>\n<a href=\"http:\/\/py.processing.org\/tutorials\/color\/\">http:\/\/py.processing.org\/tutorials\/color\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To continue the series of how to use Processing.py, this article demonstrates how to use basic shapes, placements and colors. For the previous entry in the Processing.py series, see this page: Processing.py: How to draw lines and use mouse events This code demonstrates the use of lines, rectangles, ellipses, colors and placements by sketching a &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/26\/processing-py-how-to-use-shapes-placements-and-colors\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Processing.py: How to use shapes, placements, and colors<\/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-503","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\/503","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=503"}],"version-history":[{"count":3,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/503\/revisions\/507"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}