{"id":1129,"date":"2020-08-26T11:50:16","date_gmt":"2020-08-26T10:50:16","guid":{"rendered":"https:\/\/csee.bangor.ac.uk\/?p=1129"},"modified":"2020-08-26T11:50:16","modified_gmt":"2020-08-26T10:50:16","slug":"plot-40-rectangles-and-circles","status":"publish","type":"post","link":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/","title":{"rendered":"Plot 40 rectangles and circles"},"content":{"rendered":"\n<!-- Custom post code :: Pure CSS Rainbows -->\n<!-- Adds prettyprint for code snippets -->\n\n  code { background-color: rgba(0,0,0,.05); }\n  .linenums { color: #aaa; }\n  .linenums li {\n    list-style-type: decimal !important;\n    font-size: 12pt;\n    margin-top: 0px;\n  }\n  .linenums li:nth-child(even) { background: transparent !important; }\n  .wp-block-image { text-align: center !important; }\n  .wp-block-image img { display: inline; }\n\n\n\n\n\n<p>In this activity we will plot a known quantity of coloured rectangles and circles. For example, let&#8217;s choose 40 rectangles and 40 circles. The objects will fit inside the width of the window. While this exercise is quite simple, we will think through the for-loop steps, and do some code <strong>refactoring<\/strong> to improve the code.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"334\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles.png\" alt=\"Rainbow coloured rectangles with centred circles.\" class=\"wp-image-1163\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles-768x281.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><figcaption>Rainbow coloured rectangles with centred circles.<\/figcaption><\/figure><\/div>\n\n\n\n<p>The activity uses the Processing library, and the Hue Saturation Brightness (HSB) colour model that was covered in a previous activity. Take a look at some earlier activities, before tackling this activity, especially if you have not done any already:<\/p>\n\n\n\n<ol><li><a rel=\"noreferrer noopener\" href=\"https:\/\/csee.bangor.ac.uk\/project-rainbow\/introduction-to-processing\/\" target=\"_blank\">setting up the programming environment<\/a>,<\/li><li>the activity to&nbsp;<a href=\"https:\/\/csee.bangor.ac.uk\/project-rainbow\/using-the-critical-thinking-sheet\/\" target=\"_blank\" rel=\"noreferrer noopener\">make a quick sketch before you code<\/a>, and<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/csee.bangor.ac.uk\/project-rainbow\/learn-hue-saturation-and-brightness-hsb-colour-coding\/\" target=\"_blank\">Hue Saturation Brightness<\/a>&nbsp;activities first.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1. Make a quick sketch<\/h2>\n\n\n\n<p>Before you start this activity, print out&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/06\/CTS-Bangor-v1-2.pdf\" target=\"_blank\">the critical-thinking sheet<\/a>, and get a black pen and some coloured pens or pencils. <\/p>\n\n\n\n<p>We first need to make sure that we know the vision for the activity, so that know where we are heading! <\/p>\n\n\n\n<p><span class=\"has-inline-color has-accent-color\"><strong>The goal of this activity is to plot a known quantity of coloured rectangles, that get placed across the page.<\/strong><\/span><\/p>\n\n\n\n<p>Now we can complete the five panels of the critical-thinking sheet. Complete them in order, 1 to 5, as follows:<\/p>\n\n\n\n<ol><li><strong>Write the problem<\/strong>, name and add today&#8217;s date. Also explain the challenge in panel \u2460&nbsp;<\/li><li>In panel \u2461 <strong>make a sketch <\/strong>that explains the idea, and annotate to make the sketch clear. <\/li><li>Identify the <strong>main components <\/strong>of the problem in panel \u2462 . <\/li><li><strong>Explain the steps<\/strong> of the algorithm in panel \u2463. We can use a for-loop to plot 40 rectangles, and use multiplication to calculate the exact position. <\/li><li>In the final panel <strong>think what to do next<\/strong>. Maybe consider how the rectangles can be coloured, and perhaps consider placing white circles on top to add some extra interest.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"743\" height=\"1024\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml-743x1024.jpeg\" alt=\"Critical thinking sheet, for the 40 rectangles activity\" class=\"wp-image-1140\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml-743x1024.jpeg 743w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml-218x300.jpeg 218w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml-768x1058.jpeg 768w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml-1115x1536.jpeg 1115w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/critical-thinking-sheet-40rectangles-sml.jpeg 1255w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><figcaption>Completed Critical-Thinking sheet for the 40 coloured rectangle activity<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2. Set up the Processing environment<\/h2>\n\n\n\n<p>Setting up the Processing environment with a draft project should easy now. Create a grey rectangle on a white background in a thin window, as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40rects-testpict-grey.png\" alt=\"\" class=\"wp-image-1142\" width=\"391\" height=\"143\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40rects-testpict-grey.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40rects-testpict-grey-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40rects-testpict-grey-768x281.png 768w\" sizes=\"(max-width: 391px) 100vw, 391px\" \/><figcaption>Test picture, make sure that the Processing environment has been setup correctly. Showing one rectangle at 10,10, width and height being 100, and grey colour, with a white stroke,<\/figcaption><\/figure><\/div>\n\n\n\n<ul><li>Set the <code>size<\/code> of the window. Make long thin window 800 by 200.<\/li><li>Choose the correct <code>colorMode<\/code> (we said that we would use HSB). Let&#8217;s have these values range between 0 and 100.<\/li><li>Set the background to white. We need to use the correct values, as you have set by the <code>colorMode<\/code> function. <\/li><li>Place a test <code>rect<\/code> down to make sure things work. Make the rectangle grey, with a white stroke that is width 2.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>size(800,200);\ncolourMode(HSB, 100, 100, 100);\nbackground(100);\n\n\/\/ Do a test with one rectangle\n\/\/ just to make sure that everything is working fine\nfill(50);\nstroke(100);\nstrokeWeight(2);\nrect(10,10,100,100);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3. Make the <em>for<\/em> loop<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"269\" height=\"496\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/for-loop-expression.png\" alt=\"For loop flow diagram\" class=\"wp-image-1144\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/for-loop-expression.png 269w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/for-loop-expression-163x300.png 163w\" sizes=\"(max-width: 269px) 100vw, 269px\" \/><\/figure><\/div>\n\n\n\n<p>To create 40 rectangles we will use a <strong>for<\/strong> loop. For loops are useful to create known quantities of things, in our case we have 40 rectangles.<\/p>\n\n\n\n<p>The for loop has three main parts: <\/p>\n\n\n\n<ol><li>An&nbsp;<strong>initialisation expression<\/strong> that occurs at the start of the loop and only happens once.<\/li><li>The&nbsp;<strong>test expression<\/strong> happens at the beginning of every loop. If the expression is True then the loop continues. If it is False it Ends. <\/li><li>The&nbsp;<strong>update expression<\/strong> happens at the end of each loop, after the loop body, and just before the next test expression is called. Each of these parts are separated by semicolons.<\/li><\/ol>\n\n\n\n<p><code>for ( <strong>A<\/strong> ; <strong> B<\/strong> ; <strong>C <\/strong>) { ... loop body ... }<\/code><\/p>\n\n\n\n<figure class=\"wp-block-pullquote alignright has-background has-subtle-background-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-primary-color\"><p><span class=\"has-inline-color has-accent-color\">Top tip.<\/span><br>With zero-based indexing systems. The first one is at position 0, and the tenth element is at position 9. With <em>n <\/em>objects the last one sits at <em>n-1.<\/em><\/p><\/blockquote><\/figure>\n\n\n\n<p>We need a <strong>loop counter<\/strong>, as a way to keep a tally of how many times we go around the loop. The loop counter is also used to test to see if we need to loop again. For loops and loop counters are very powerful and can be defined many ways, but there are a few conventions that programmers use:<\/p>\n\n\n\n<ul><li>Typically loop counters are variables that <strong>have a short name<\/strong>. Programmers often use i, and j, k as needed. <\/li><li>Loop counters (typically) <strong>start from zero.<\/strong> While this may sound unusual, it fits in better with other programming concepts, such as <code>arrays<\/code> that also start from zero in many languages. <\/li><li><strong>Count in ones<\/strong> and use an <strong>integer<\/strong> loop counter. While, it is possible to have non-integer for-loop counters, try to avoid it. If you think you need floating point variables, don&#8217;t do it, there is a better way to do what you want to do!<\/li><li>Keep the <strong>loop expressions separate from loop body commands.<\/strong> Especially as a learner, this is a good principle to follow. If you want 40 things, control it in the loop expression. What you do with these 40 things should be defined in the loop body.<\/li><\/ul>\n\n\n\n<p><span class=\"has-inline-color has-accent-color\">We can now think through each of the parts of the <strong>for<\/strong> loop to create 40 things.<\/span> <\/p>\n\n\n\n<ul><li>The <em>initialisation expression<\/em> will be an integer, starting at 0. Let&#8217;s set it to be <code>int i=0;<\/code><\/li><li>The <em>test expression<\/em>, allows needs to check if the value <code>i<\/code> is less than 40. We say <code>i &lt; 40;<\/code><\/li><li>Finally, for the <em>update expression<\/em> we need to increment the loop counter by 1. We can say <code>i = i+1;<\/code> or as a shorthand <code>i++<\/code>.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code prettyprint listnums\"><code>for( int i=0; i&lt;40; i++){\n\/\/ the loop body goes here\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-pullquote has-background has-subtle-background-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-primary-color\"><p><span class=\"has-inline-color has-accent-color\">Top tip.<\/span><\/p><p>When creating a <span style=\"text-decoration: underline\">for<\/span> loop in the future, think about each expression in turn: <br><br><em>what to initialise, <\/em><br><em>what to test, <\/em><br><em>what to update.<\/em><\/p><\/blockquote><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4. Now define the body of the <span style=\"text-decoration: underline\">for<\/span> loop<\/h2>\n\n\n\n<p>Our current <strong>for<\/strong> loop makes 40 things. We now need to define the body statement. <\/p>\n\n\n\n<p>To create the code body, we can break down the problem into steps. This will help us work out what doesn&#8217;t change (the constants) and what needs to be adapted by the loop counter (the variables). <\/p>\n\n\n\n<p><strong>First let us define one rectangle;<\/strong> plotted at an unknown (x,y) position with a width 20 and <code>height<\/code> to equal the height of the window.  We can do this by writing:<\/p>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>rect( x, y, 20, height);<\/code><\/pre>\n\n\n\n<p><strong>We now need to define x<code>,<\/code> <code>y<\/code> and <code>height<\/code>.<\/strong> Well, in Processing, <code>height<\/code> is a pre-defined variable that holds the height of the window. So we now need to work out x and y.  Because we said that every rectangle sits along the top, we can fix <code>y <\/code>to <code>0<\/code>. Now we can simplify the line to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rect( x, 0, 20, height);<\/code><\/pre>\n\n\n\n<p><strong>Finally, we just need to work out the value for <code>x<\/code>.<\/strong> The <code>x<\/code> value changes every time, we can think through some steps::<\/p>\n\n\n\n<ul><li>On the first time round, the loop counter <code>i<\/code> is <code>0<\/code>, and we want to place the rectangle at (0,0). So <code>x<\/code> is <code>0<\/code>.<\/li><li>The second time round <code>i<\/code> is <code>1<\/code>, and we want to place the rectangle at (20,0), so x is 20.<\/li><li>The third time round, <code>i<\/code> is set to<code> 2<\/code>, and we want to place a rectangle at (40,0), and so x is 40, and so on for the other values.<\/li><\/ul>\n\n\n\n<p>It is clear to see that <code>x = i * 20<\/code>. Where every rectangle is placed 20 points to the right of the previous. Because the width of each rectangle is also 20, it means that one rectangle starts as the previous ends.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/rect-for-loop2-1024x355.png\" alt=\"Rect plotted on a for loop\" class=\"wp-image-1154\" width=\"690\" height=\"239\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/rect-for-loop2-1024x355.png 1024w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/rect-for-loop2-300x104.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/rect-for-loop2-768x266.png 768w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/rect-for-loop2.png 1416w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/figure>\n\n\n\n<p>The code so far is as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40grey-rects.png\" alt=\"40 grey rectangles across the window\" class=\"wp-image-1158\" width=\"336\" height=\"123\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40grey-rects.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40grey-rects-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40grey-rects-768x281.png 768w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><figcaption>40 grey rectangles across the window.<\/figcaption><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>size(800,200);\ncolorMode(HSB,100,100,100);\nbackground(100);\n\nfill(50); \/\/ set the colour to grey\nstroke(100);\nstrokeWeight(2);\n\nfor( int i=0; i&lt;40; i++){\n  rect(i*20,0,20,height);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5. Change the colour of each rectangle<\/h2>\n\n\n\n<p>It&#8217;s fun to try out different colour combinations. Let&#8217;s do a few:<\/p>\n\n\n\n<p><strong>Select random colours.<\/strong> To set each colour with a random value, we first choose a random value, and set the hue to this value. <\/p>\n\n\n\n<ul><li>We need to set the <code>fill<\/code> colour before creating a rectangle, so it will set the rectangle with the desired colour. <\/li><li>Because, with <code>colorMode<\/code> we set the range of hue to be 100, we need a random value between 0 and 100. <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>fill(random(100),100,100);\nrect(i*20,0,20,height);<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"334\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\" alt=\"40 randomly coloured rectangles.\" class=\"wp-image-1160\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects-768x281.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><figcaption>40 randomly coloured rectangles.<\/figcaption><\/figure>\n\n\n\n<p><strong>Spectrum coloured rectangles. <\/strong>To set each of the colours to a different hue, we need to map the loop counter value to the hue. The easiest way to do this is to set both ranges to the same values: the range of the colour hue, to the range of the rectangle quantity. <\/p>\n\n\n\n<p>To do this action, we could change the <strong><code>for<\/code><\/strong> loop value to fit in with the hue; or change the range of the <code><strong>colorMode<\/strong><\/code> to fit in with the quantity of rectangles. It is easier to adapt the <code>colorMode<\/code> to the rectangle quantity.<\/p>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>size(800,200);\ncolorMode(HSB,40,100,100);\nbackground(40);\n\nstroke(40);\nstrokeWeight(2);\n\nfor( int i=0; i&lt;40; i++){\n  fill(i,100,100);\n  rect(i*20,0,20,height);\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"334\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40spectrum-coloured-rects-.png\" alt=\"40 spectrum coloured rectangles\" class=\"wp-image-1162\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40spectrum-coloured-rects-.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40spectrum-coloured-rects--300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40spectrum-coloured-rects--768x281.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><figcaption>40 rectangles with white stroke, placed side-by-side and coloured by the rainbow spectrum.<\/figcaption><\/figure>\n\n\n\n<p><strong>Add 40 circles.<\/strong> Now we can add additional circles to the picture. Every rectangle gets a circle in the centre. One way to do this is to copy the whole of the <code>for<\/code> loop, and replace the <code>rect<\/code> command with an <code>ellipse<\/code> and change some of the values that define the right sized <code>ellipse<\/code>. <\/p>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>size(800,200);\ncolorMode(HSB,40,100,100);\nbackground(40);\n\nstroke(40);\nstrokeWeight(2);\n\nfor( int i=0; i&lt;40; i++){\n  fill(i,100,100);\n  rect(i*20, 0, 20, height);\n}\n\nfor( int i=0; i&lt;40; i++){\n  fill(i,100,100);\n  ellipse(i*20 + 10,100,20,20);\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"334\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles.png\" alt=\"40 coloured rects with circles\" class=\"wp-image-1163\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-col-rect-w-circles-768x281.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><figcaption>40 rectangles with white stroke, placed side-by-side and coloured by the rainbow spectrum, and with centred circles.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6. Refactor our code<\/h2>\n\n\n\n<figure class=\"wp-block-pullquote alignright has-background has-subtle-background-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-primary-color\"><p><span class=\"has-inline-color has-accent-color\">Top tip.<\/span><\/p><p>Every time you write code; think how it can be refactored. Edit the code to make it more efficient, clearer to read, general, etc.<\/p><\/blockquote><\/figure>\n\n\n\n<p>Now we have created the basic code &#8211; it is worth looking at the code &#8211; to see if we can improve it! This is the process of refactoring. Editing the code, and cleaning it up, without changing the functionality.<\/p>\n\n\n\n<p>The idea is to look through the code, and see if we can edit it to improve it. Look for repetitions, fixed numbers that can be exchanged to constants or variables, and tidy up its presentation. <\/p>\n\n\n\n<p><strong>In our code, the first thing to notice, is that there are lots of numbers in the code. <\/strong><\/p>\n\n\n\n<p>These are &#8220;<strong>magic numbers<\/strong>&#8220;. They are magic because they do powerful things, but when you look back at your code you won&#8217;t remember what they do, or why you chose them. <\/p>\n\n\n\n<p>In our code, we can notice a few of these &#8220;magic numbers&#8221;:<\/p>\n\n\n\n<ul><li>The value 20 is duplicated many times. This number means two things: it is the width of the rectangle, and also the position of each rectangle. We need to make it clear that these are different  things!<\/li><li>Furthermore the value of 20 for the width of each rectangle was deliberately chosen. But this choice is very subtle, and someone who is reading the code may not understand why it was chosen. In fact, the value of 20 was chosen to fit well with the width of the window, which is set to 800 (20 * 40 gives us the width of the window). This value is very specific, and a variable may help to make the code more general.<\/li><li>The number 40 is used both for the quantity of rectangles and the hue range. <\/li><\/ul>\n\n\n\n<p><strong>Second, we have duplicated code. <\/strong>We don&#8217;t need two for-loops, we can do it all in one loop. <\/p>\n\n\n\n<p>To improve the code, we can define a few variables. <\/p>\n\n\n\n<ul><li>We need something to hold the position of each rectangle. Let us define an integer called <code>pos<\/code>.<\/li><li>Let&#8217;s also define the width of each rectangle. Let&#8217;s have another integer, but call this one <code>wid<\/code>.<\/li><li>We should also work out how many rectangles will fit in the window. We can do this by dividing <code>wid<\/code> into the <code>width<\/code> of the window. But, this may not be an integer value, and we said that we&#8217;d want the <code>for<\/code> loops to only use integer loop counts. So, let&#8217;s take the lowest value of this division using the command <code><a rel=\"noreferrer noopener\" href=\"https:\/\/processing.org\/reference\/floor_.html\" target=\"_blank\">floor()<\/a><\/code>, which will round down the answer.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code prettyprint\"><code>int pos = 20;\nint wid = 20;\nint quant = floor( width \/ wid );<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"312\" height=\"334\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-coloured.png\" alt=\"Coloured rectangles, with changed screen size\" class=\"wp-image-1167\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-coloured.png 312w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-coloured-280x300.png 280w\" sizes=\"(max-width: 312px) 100vw, 312px\" \/><figcaption>Coloured rectangles, with changed screen size<\/figcaption><\/figure><\/div>\n\n\n\n<p>This gets us nearly there. But the colour definition is probably not what we want. Say if we want a smaller window, and set <code>size<\/code>(200,200). While the code works, and a small window is shown, the colour range is not quite what we wanted. We need to match the colour range to the quantity range. We can do this by adapting the <code>colorMode<\/code> line, and moving it lower. (Remembering also to change the <code>background() <\/code>and <code>stroke() <\/code>commands appropriately).<\/p>\n\n\n\n<p>We could improve some of the other values, but our refactored code is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code prettyprint linenums\"><code>size(200,200);\nbackground(255);\n\nfill(50);\nstroke(255);\nstrokeWeight(2);\n\nint pos = 20;\nint wid = 20;\nint quant = floor( width \/ wid );\ncolorMode(HSB,quant,100,100);\n\nfor( int i=0; i&lt;quant; i++){\n  fill(i,100,100);\n  rect(i*pos,0,wid,height);\n  ellipse(i*pos + wid\/2, 100, wid, wid);\n}<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-colored-rainbow.png\" alt=\"Rectangles filled within a smaller window\" class=\"wp-image-1169\" width=\"312\" height=\"334\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-colored-rainbow.png 312w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-rects-colored-rainbow-280x300.png 280w\" sizes=\"(max-width: 312px) 100vw, 312px\" \/><figcaption>Rainbow coloured rectangles in a smaller  window 200 by 200.<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7. Your turn<\/h2>\n\n\n\n<p>Now you can try out different values and different settings.<\/p>\n\n\n\n<ul><li><strong>Make a program with a fixed quantity of rectangles, and size the rectangle width appropriately. <\/strong>Adapt the code to make the width of each rectangle change, depending on how many rectangles you want to fit in the window. So, if you want 5 rectangles they are really wide. While 100 rectangles would be very thin.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects.png\" alt=\"100 coloured rectangles\" class=\"wp-image-1171\" width=\"263\" height=\"96\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-768x281.png 768w\" sizes=\"(max-width: 263px) 100vw, 263px\" \/><figcaption>100 coloured rectangles<\/figcaption><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-5rects.png\" alt=\"5 coloured rectangles\" class=\"wp-image-1170\" width=\"260\" height=\"94\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-5rects.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-5rects-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-5rects-768x281.png 768w\" sizes=\"(max-width: 260px) 100vw, 260px\" \/><figcaption>5 coloured rectangles<\/figcaption><\/figure>\n\n\n\n<ul><li><strong>Add many circles <\/strong>to each of the rectangles.<\/li><li><strong>Change the stroke colours to black.<\/strong><\/li><li><strong>Add twenty white circles<\/strong>, randomly placed on top of the design.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-w-whitecircles.png\" alt=\"100 rectangles that fit in the width of the window, with 20 white circles placed on top\" class=\"wp-image-1175\" width=\"610\" height=\"223\" srcset=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-w-whitecircles.png 912w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-w-whitecircles-300x110.png 300w, https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-100rects-w-whitecircles-768x281.png 768w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><figcaption>100 rectangles that fit in the width of the window, with 20 white circles placed on top<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create 40 coloured rectangles, use a for-loop, the critical thinking sheet, and do some code refactoring.<\/p>\n","protected":false},"author":2,"featured_media":1160,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7,16,17],"tags":[36,48,49,56,66,68,73,104,111,112,113,117,127],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Plot 40 rectangles and circles - Project Rainbow<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Plot 40 rectangles and circles - Project Rainbow\" \/>\n<meta property=\"og:description\" content=\"Create 40 coloured rectangles, use a for-loop, the critical thinking sheet, and do some code refactoring.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\" \/>\n<meta property=\"og:site_name\" content=\"Project Rainbow\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-26T10:50:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\" \/>\n\t<meta property=\"og:image:width\" content=\"912\" \/>\n\t<meta property=\"og:image:height\" content=\"334\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"projectrainbow\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"projectrainbow\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\"},\"author\":{\"name\":\"projectrainbow\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/fa50357aa55dc7c9e38a6114bf64f1f6\"},\"headline\":\"Plot 40 rectangles and circles\",\"datePublished\":\"2020-08-26T10:50:16+00:00\",\"dateModified\":\"2020-08-26T10:50:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\"},\"wordCount\":2061,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization\"},\"image\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\",\"keywords\":[\"colour\",\"critical thinking sheet\",\"critical-thinking-sheet\",\"ellipse\",\"hsb\",\"hue\",\"java\",\"projectrainbow\",\"rectangles\",\"refactor\",\"refactoring\",\"saturation\",\"value\"],\"articleSection\":[\"Beginner\",\"Colours\",\"Processing\",\"Project Rainbow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\",\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\",\"name\":\"Plot 40 rectangles and circles - Project Rainbow\",\"isPartOf\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\",\"datePublished\":\"2020-08-26T10:50:16+00:00\",\"dateModified\":\"2020-08-26T10:50:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage\",\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\",\"contentUrl\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png\",\"width\":912,\"height\":334,\"caption\":\"40 randomly coloured rectangles\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Plot 40 rectangles and circles\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#website\",\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/\",\"name\":\"Project Rainbow\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization\",\"name\":\"Project Rainbow\",\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/05\/bangor_logo_c1_flush.png\",\"contentUrl\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/05\/bangor_logo_c1_flush.png\",\"width\":3356,\"height\":958,\"caption\":\"Project Rainbow\"},\"image\":{\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/fa50357aa55dc7c9e38a6114bf64f1f6\",\"name\":\"projectrainbow\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/221f8a462bd270b3db788cf44a3c1757?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/221f8a462bd270b3db788cf44a3c1757?s=96&d=mm&r=g\",\"caption\":\"projectrainbow\"},\"url\":\"https:\/\/csee.bangor.ac.uk\/projectrainbow\/author\/projectrainbow\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Plot 40 rectangles and circles - Project Rainbow","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/","og_locale":"en_US","og_type":"article","og_title":"Plot 40 rectangles and circles - Project Rainbow","og_description":"Create 40 coloured rectangles, use a for-loop, the critical thinking sheet, and do some code refactoring.","og_url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/","og_site_name":"Project Rainbow","article_published_time":"2020-08-26T10:50:16+00:00","og_image":[{"width":912,"height":334,"url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png","type":"image\/png"}],"author":"projectrainbow","twitter_card":"summary_large_image","twitter_misc":{"Written by":"projectrainbow","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#article","isPartOf":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/"},"author":{"name":"projectrainbow","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/fa50357aa55dc7c9e38a6114bf64f1f6"},"headline":"Plot 40 rectangles and circles","datePublished":"2020-08-26T10:50:16+00:00","dateModified":"2020-08-26T10:50:16+00:00","mainEntityOfPage":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/"},"wordCount":2061,"commentCount":0,"publisher":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization"},"image":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage"},"thumbnailUrl":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png","keywords":["colour","critical thinking sheet","critical-thinking-sheet","ellipse","hsb","hue","java","projectrainbow","rectangles","refactor","refactoring","saturation","value"],"articleSection":["Beginner","Colours","Processing","Project Rainbow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/","url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/","name":"Plot 40 rectangles and circles - Project Rainbow","isPartOf":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#website"},"primaryImageOfPage":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage"},"image":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage"},"thumbnailUrl":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png","datePublished":"2020-08-26T10:50:16+00:00","dateModified":"2020-08-26T10:50:16+00:00","breadcrumb":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#primaryimage","url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png","contentUrl":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/08\/screenshot-40-randomly-coloured-rects.png","width":912,"height":334,"caption":"40 randomly coloured rectangles"},{"@type":"BreadcrumbList","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/2020\/08\/26\/plot-40-rectangles-and-circles\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/"},{"@type":"ListItem","position":2,"name":"Plot 40 rectangles and circles"}]},{"@type":"WebSite","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#website","url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/","name":"Project Rainbow","description":"","publisher":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#organization","name":"Project Rainbow","url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/logo\/image\/","url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/05\/bangor_logo_c1_flush.png","contentUrl":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-content\/uploads\/sites\/2\/2020\/05\/bangor_logo_c1_flush.png","width":3356,"height":958,"caption":"Project Rainbow"},"image":{"@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/fa50357aa55dc7c9e38a6114bf64f1f6","name":"projectrainbow","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/221f8a462bd270b3db788cf44a3c1757?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/221f8a462bd270b3db788cf44a3c1757?s=96&d=mm&r=g","caption":"projectrainbow"},"url":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/author\/projectrainbow\/"}]}},"_links":{"self":[{"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/posts\/1129"}],"collection":[{"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/comments?post=1129"}],"version-history":[{"count":0,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/posts\/1129\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/media\/1160"}],"wp:attachment":[{"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/media?parent=1129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/categories?post=1129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csee.bangor.ac.uk\/projectrainbow\/wp-json\/wp\/v2\/tags?post=1129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}