{"id":265,"date":"2012-11-05T15:05:20","date_gmt":"2012-11-05T15:05:20","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/?p=265"},"modified":"2012-11-05T15:05:20","modified_gmt":"2012-11-05T15:05:20","slug":"winters-outlook-version-2","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/05\/winters-outlook-version-2\/","title":{"rendered":"Winter&#8217;s Outlook Version 2"},"content":{"rendered":"<p>I changed my first creation that I had dubbed Winter&#8217;s Outlook.<br \/>\nWinter&#8217;s Outlook Version 2 has some improvements.<\/p>\n<p>   The improved code has:<br \/>\n1) Each color set as a variable<br \/>\n2) The main figures in the image produced through their own functions<\/p>\n<p>   It also<br \/>\n3) Responds in two ways to clicking<br \/>\n   a &#8211; Click and drag allows the snow to pile up<br \/>\n   b &#8211; Just clicking changes the snow as if its falling<\/p>\n<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\n\/\/ A Winter's Outlook : Version 2\r\n\/\/\tBy: Alex Clemens\r\n\/\/      Nov 5 2012\r\n\r\n\/\/ The grid will be set up so that each grid location is 6 across\r\n\/\/\tAnd each object in that location is 5 X 5\r\n\/\/\tLeaving a 1 space border\r\n\/\/\tThe edge of the picture will be removed so there is no outer border\r\n\r\n\/\/ PICTURE DRAWING STARTS ... ... ... ... NOW!!!\r\n\r\n\/\/ Color Variables\r\n\r\ncolor BG_Color_1 = color( 255, 215, 0 );\r\ncolor BG_Color_2 = color( 192, 192, 192 );\r\ncolor BG_Block_Color = color( 0 );\r\ncolor Sky_Color = color( 192, 192, 215 );\r\ncolor Snow_Color = color( 255 );\r\ncolor Horizon_Color = color( 0 );\r\ncolor Tree_Leave_Color = color( 34, 139, 34 );\r\ncolor Tree_Trunk_Color = color( 160, 82, 45 );\r\ncolor Edge_Black = color( 0 );\r\ncolor Edge_White = color( 255 );\r\n\r\n\/\/ Grid and image layout variable\r\n\r\nint GRIDSIZE = 600;\r\nint BLOCKSIZE = 6;\r\nint BLOCKS = GRIDSIZE \/ BLOCKSIZE;\r\nint PICSIZE = BLOCKSIZE - 1;\r\nint x, y; \r\nint picBreak;\r\n\r\n\r\nvoid setup()\r\n{\r\n\/\/Initial set up\r\n\r\nint GRIDSIZE = 600;\r\nint BLOCKSIZE = 6;\r\nint BLOCKS = GRIDSIZE \/ BLOCKSIZE;\r\nint PICSIZE = BLOCKSIZE - 1;\r\n\r\nsize( GRIDSIZE - 1, GRIDSIZE - 1 );\r\nbackground( BG_Color_1 ); \/\/ Gold backgound\r\nnoStroke();\r\n\r\n\r\n\/\/ Create a border\r\n\r\n\r\n\/\/ Place a winter scene\r\n\r\n  CreateBackground();\r\n\r\n\/\/ Add snow drops\r\n\r\n  LetItSnow();\r\n\r\n\/\/ Add a tree\r\n  \r\n  CreateTree();\r\n  \r\n  \r\n} \/\/ End Setup()\r\n\r\n\r\nvoid draw()\r\n{}\r\n\r\n\r\nvoid mousePressed()\r\n{\r\n  setup();\r\n}\r\n\r\nvoid mouseDragged()\r\n{\r\n  LetItSnow();\r\n}\r\n\r\n\r\nvoid CreateBackground()\r\n{\r\n  \r\n  \/\/ accessory variable\r\n\/\/ These should not need to be greater than BLOCKS\r\nint i, j;\r\n\/\/ Use background for gold inbetween black squares\r\n\r\nrectMode( CORNER );\r\n\r\nx = 0; \r\ny = 0;\r\n\r\nfill( BG_Block_Color );\r\n\r\nfor ( i = 0; i < BLOCKS; i++)\r\n\trect( i * BLOCKSIZE, y , PICSIZE, PICSIZE );\r\n\r\nfor ( j = 0; j < BLOCKS; j++)\r\n        rect( x, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\nfor ( i = 0; i < BLOCKS; i++)\r\n\trect( i * BLOCKSIZE,  GRIDSIZE - BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\nfor ( j = 0; j < BLOCKS; j++)\r\n\trect( GRIDSIZE - BLOCKSIZE, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\n\r\n\/\/ Then inside is gold squares on silver background\r\nx = x + 1; \/\/ move x to next inner square of grid\r\ny = y + 1; \/\/ move y to next inner square of grid\r\n\r\nfill( BG_Color_2 );\r\nrect( BLOCKSIZE, BLOCKSIZE, GRIDSIZE - ( 2 * x * BLOCKSIZE ) - 1 , GRIDSIZE - ( 2 * y * BLOCKSIZE ) - 1 );\r\n\r\n\r\nfill( BG_Color_1 );\r\nfor( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, y * BLOCKSIZE , PICSIZE, PICSIZE );\r\n\r\nfor( j = y; j < BLOCKS - y; j++ )\r\n\trect( x * BLOCKSIZE, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\nfor( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, GRIDSIZE - ( 2 * y * BLOCKSIZE ) , PICSIZE, PICSIZE );\r\n\r\nfor( j = y; j < BLOCKS - y; j++ )\r\n\trect( GRIDSIZE - ( 2 * x * BLOCKSIZE ), j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\n\r\n\r\nx += 1; \/\/ move x to next inner square of grid\r\ny += 1; \/\/ move y to next inner square of grid\r\n\r\n\/\/ Fill is still gold\r\n\r\nfor ( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, y * BLOCKSIZE , PICSIZE, PICSIZE );\r\n\r\nfor ( j = y; j < BLOCKS - y; j++ )\r\n\trect( x * BLOCKSIZE, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\nfor ( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, GRIDSIZE - ( ( 2 * y - 1 ) * BLOCKSIZE ) , PICSIZE, PICSIZE );\r\n\r\nfor ( j = y; j < BLOCKS - y; j++ )\r\n\trect( GRIDSIZE - ( ( 2 * x - 1 ) * BLOCKSIZE ), j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\n\r\n\/\/ Then switch back.\r\n\r\nx += 1; \/\/ move x to next inner square of grid\r\ny += 1; \/\/ move y to next inner square of grid\r\n\r\nrect( BLOCKSIZE * x, BLOCKSIZE * y, GRIDSIZE - ( 2 * x * BLOCKSIZE ) - 1, GRIDSIZE - ( 2 * y * BLOCKSIZE ) - 1 );\r\n\r\nfill( BG_Block_Color );\r\n\r\nfor ( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, y * BLOCKSIZE , PICSIZE, PICSIZE );\r\n\r\nfor ( j = y; j < BLOCKS - y; j++ )\r\n\trect( x * BLOCKSIZE, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\nfor ( i = x; i < BLOCKS - x; i++ )\r\n\trect( i * BLOCKSIZE, GRIDSIZE - ( ( 2 * ( y - 1 ) ) * BLOCKSIZE ) , PICSIZE, PICSIZE );\r\n\r\nfor ( j = y; j < BLOCKS - y; j++ )\r\n\trect( GRIDSIZE - ( ( 2 * ( x - 1 ) ) * BLOCKSIZE ), j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n\r\n\r\n\/\/ Border is finished, Now for the inner picture.\r\n\r\n\/\/ Inner background\r\n\r\nfill( BG_Color_2 ); \/\/ silver\r\n\r\nx += 1; \/\/ move x to next inner square of grid\r\ny += 1; \/\/ move y to next inner square of grid\r\n\r\nrect( BLOCKSIZE * x, BLOCKSIZE * y, GRIDSIZE - ( 2 * x * BLOCKSIZE ) - 1, GRIDSIZE - ( 2 * y * BLOCKSIZE ) - 1 );\r\n\r\n\/\/ Break in design 1\/3 of the way up the grid\r\n\r\npicBreak = int( 2 * ( GRIDSIZE - ( 2 * x * BLOCKSIZE ) ) \/ 3 );\r\npicBreak = ( picBreak \/ BLOCKSIZE ) - ( picBreak % BLOCKSIZE );\r\n\r\n\/\/ Make the sky blue-ish in the sky area\r\n\r\nfill( Sky_Color );\r\nrect( x * BLOCKSIZE + 1, y * BLOCKSIZE + 1, GRIDSIZE - ( 2 * x * BLOCKSIZE ) - 2, ( picBreak - x ) * BLOCKSIZE );\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\/\/ Add snow drops\r\n\r\nvoid LetItSnow()\r\n{\r\n  x = 4;\r\n  y = 4;\r\n  \r\n int i, j;\r\n  \r\n\/\/ more ints for random number generation\r\n\r\nint ran1, ran2;\r\n\r\npicBreak = int( 2 * ( GRIDSIZE - ( 2 * x * BLOCKSIZE ) ) \/ 3 );\r\npicBreak = ( picBreak \/ BLOCKSIZE ) - ( picBreak % BLOCKSIZE );\r\n\r\n\/\/ Set fill\r\n\r\nfill( Snow_Color ); \/\/ White\r\nstroke( Edge_Black );\r\n\r\nfor( j = y; j < BLOCKS - y; j++ )\r\n{\r\n\tif( j == picBreak )\r\n\t{\r\n\t\tfill( Horizon_Color );\r\n\t\tstroke( Edge_White );\r\n\t}\r\n\r\n\t\tfor( i = x; i < BLOCKS - x; i++ )\r\n\t\t{\r\n\t\t\tran1 = int( random( 2, PICSIZE + 1 ) );\r\n\t\t\tran2 = int( random( 2, PICSIZE + 1 ) );\r\n\t\t\tellipse( i * BLOCKSIZE + 1, j * BLOCKSIZE + 1, ran1, ran2 );\r\n\t\t}\r\n\r\n\tif( j == picBreak )\r\n\t{\r\n\t\tfill( Snow_Color );\r\n\t\tnoStroke();\r\n\t}\r\n}\r\n}\r\n\r\n\r\n\r\n\r\n\/\/ Create A tree in the picture\r\nvoid CreateTree()\r\n{\r\n\r\npicBreak = int( 2 * ( GRIDSIZE - ( 2 * x * BLOCKSIZE ) ) \/ 3 );\r\npicBreak = ( picBreak \/ BLOCKSIZE ) - ( picBreak % BLOCKSIZE );\r\n  \r\n  int i, j;\r\n  \r\nx += 1; \/\/ limit the tree from going all the way to the border\r\ny += 1;\r\n\r\nint TriTopX, TriBotLY, TriBotRX, TriBotRY;\r\n\r\nTriTopX = int( BLOCKSIZE \/ 2 );\r\nTriBotLY = PICSIZE;\r\nTriBotRX = PICSIZE;\r\nTriBotRY = PICSIZE;\r\nint treeWidth = 0;\r\n\r\n\/\/int treeTopx = int( 2 * ( GRIDSIZE - ( 2 * x * BLOCKSIZE ) ) \/ 3 );\r\nint treeTopx = picBreak + x;\r\n\r\n\/\/int treeTopy = int( ( GRIDSIZE - ( 2 * x * BLOCKSIZE ) ) \/ 3 );\r\nint treeTopy = ( picBreak + y ) \/ 2;\r\n\r\nint treeBottom = ( treeTopy * 2 );\r\n\r\n\/\/Add leaves\r\n\r\nfill( Tree_Leave_Color ); \/\/Forest Green\r\n\r\nint treeBreak1 = int( treeTopy + ( treeTopy \/ 3) );\r\nint treeBreak2 = int( treeTopy + ( ( 2 * treeTopy) \/ 3) );\r\n\r\nfor( j = treeTopy; j < treeBottom; j++, treeWidth++)\r\n{\r\n\tif( j == treeBreak1 || j == treeBreak2 )\r\n\t\ttreeWidth = treeWidth \/ 3;\r\n\r\n\tfor( i = treeTopx - treeWidth; i <= treeTopx + treeWidth; i++ )\r\n\t\ttriangle( i * BLOCKSIZE, j * BLOCKSIZE + TriBotLY, i * BLOCKSIZE + TriTopX, \r\n                          j * BLOCKSIZE, i * BLOCKSIZE + TriBotRX, j * BLOCKSIZE + TriBotRY );\r\n\t\r\n\tif( j > treeBreak1 )\r\n\t{\r\n\t\tif( j > treeBreak2 )\r\n\t\t\ttreeWidth++;\r\n\t\telse if( 0 == ( treeWidth % 3 ))\r\n\t\t\ttreeWidth++;\r\n\t}\r\n}\r\n\r\n\/\/ tree trunk\r\n\r\nint trunkWidthHalf = int( treeWidth \/ 6 );\r\nint trunkHeight = treeBottom + ( treeTopy \/ 4 );\r\n\r\nfill( Tree_Trunk_Color ); \/\/ Brown for the trunk, Sienna\r\n\r\nfor( i = treeTopx - trunkWidthHalf; i < treeTopx + trunkWidthHalf; i++ )\r\n{\r\n\tfor( j = treeBottom; j < trunkHeight; j++ )\r\n\t\trect( i * BLOCKSIZE, j * BLOCKSIZE, PICSIZE, PICSIZE );\r\n}\r\n}\r\n\r\n\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I changed my first creation that I had dubbed Winter&#8217;s Outlook. Winter&#8217;s Outlook Version 2 has some improvements. The improved code has: 1) Each color set as a variable 2) The main figures in the image produced through their own &hellip; <a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/2012\/11\/05\/winters-outlook-version-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/265"}],"collection":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/comments?post=265"}],"version-history":[{"count":8,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":286,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/posts\/265\/revisions\/286"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/IMGD3x00_B12\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}