# Help with lab "Changeable Chain"

**URL:** <https://discourse.processing.org/t/help-with-lab-changeable-chain/19966>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 20, 2020, 4:33pm UTC](https://discourse.processing.org/t/help-with-lab-changeable-chain/19966 "2020-04-20T16:33:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan25711](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Jonathan25711](https://discourse.processing.org/u/Jonathan25711)\
**Post date:** [April 20, 2020, 4:33pm UTC](https://discourse.processing.org/t/help-with-lab-changeable-chain/19966/1 "2020-04-20T16:33:18Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

The labs require this.

> Instructions for Lab 7.5 Changeable Chain
> 
> First Lab:
> 
> First declare two Integer arrays of size 5 to store the x location and y location of the ellipses.
> 
> Next declare three Integer or float arrays of size 5 to store the red, green and blue values of the ellipses
> 
> In the setup method
> 
> Set the size of the sketch window
> 
> Use a for loop to iterate through the size of the array and assign the values for x location and y
> 
> location using random method with width and height as range for the random methods
> 
> respectively.
> 
> Assign random value in the range of 1 to 256 using the random method to the corresponding
> 
> red, green and blue array elements.
> 
> In the draw method
> 
> Set the background to a shade of grey color.
> 
> Iterate through a for loop for the array length times, which will be 5 in this case and use the fill
> 
> command with the appropriate red, green and blue values to set the fill color of the ellipse.
> 
> Draw the ellipse at the given x and y location with the size and height values as 30.
> 
> Iterate through the for loop for the array length -1 times, as we will not be drawing the line from
> 
> the last x and y location.
> 
> Draw the lines connecting the x and y location to the [x+1] and [y+1] location
> 
> In the mouse Pressed method
> 
> Iterate through the loop for array length – 1 times which will be 4 in this case and shift the
> 
> values of the x and y location to the left by one spot by copying the value of the next element to
> 
> the element like x[i] = x[i+1] , y[i] = y[i+1].
> 
> Also shift the elements of the red , green and blue values like red[i]=red[i+1],
> 
> green[i]=green[i+1] and blue[i]=blue[i+1] to get the same fill colors of the ellipses.
> 
> Now assign the mouseX and mouseY values to the fifth element. X[4] = mouseX, y[4] = mouseY
> 
> Assign random value in the range of 1 to 256 using the random method to the corresponding
> 
> red, green and blue array elements. red[4] = (int) random(1,256),green[4] and blue[4]
> 
> * * *
> 
> Lab 2:  
> Declare 3 integer arrays to store the building heights, the x values of the stars and the y values
> 
> of the stars.
> 
> The size of the array int buildingHeights is 12.
> 
> The size of the array int starXValues is 200.
> 
> The size of the array int starYValues is 200.
> 
> In the setup() method
> 
> Sets the sketch window size to 600 pixels wide by 450 pixels height.
> 
> Set the rectmode and ellipsemode to be CORNER.
> 
> Call the drawAll and randomize method
> 
> In the draw() method we do not have any code, it is an empty method.
> 
> In the drawAll() method
> 
> Call the drawSky() & drawBuildings() method
> 
> In the randomize method
> 
> Use a for loop to iterate through the starXValues length which is 200 and assign the
> 
> random value of 0 to width to starxValues[i] and assign the random value of 0 to
> 
> height to staryValues[i] where i is the counter of the for loop.
> 
> Use another for loop to iterate through the buildingHeights length and assign
> 
> random value of 1 to 8 to the buildingHeights[i] where i is the counter of the for
> 
> loop.
> 
> In the drawSky() method
> 
> sets the background to black
> 
> set the stroke for the stars(point) to be white and strokeWeight to be 1
> 
> To draw the moon set the fill color of the ellipse to be white and set the x value to
> 
> be 500 and y value to a negative value to draw the moon at the right end of the
> 
> screen. Use appropriate width and height values.
> 
> To draw 200 stars use a for loop for starxValues length times and draw the point at
> 
> the (x,y) for each element in the array
> 
> In the drawBuildings() method
> 
> Use a for loop to iterate through the length of the buildingHeights which is 12 and call
> 
> the drawBuilding method with two parameters x and y.
> 
> The x value is assigned i\*50 and the y value is assigned the difference of the screen
> 
> height and the value of buildingHeights[i]\*50.
> 
> drawBuilding(i\*50, height-buildingHeights[i]\*50);
> 
> In the drawBuilding(int x, int y) method
> 
> Set the fill color of the rectangle[building] to 100 to get the grey shade.
> 
> Set the stroke to be black.
> 
> Draw the rectangle at the given x and y value with the width as 50 and height as the
> 
> difference between width and y.
> 
> Now to draw the windows within the building, we need to draw rows of rectangles
> 
> within the building size.
> 
> Use the outer loop with the initial column value as x+5 and increment it with 9 and
> 
> the condition as col\<x+45 as the building’s width is 50 in order to get 5 columns of
> 
> windows
> 
> In the inner loop set the row’s initial value to be y+10 and increment it with a 25 and
> 
> the condition as \< height.
> 
> To randomly color the windows to be black or yellow, use the random(2) method
> 
> and check if it is equal to 0 and if it is true set the fill color to yellow, else set the fill
> 
> color to black. Remember you need to cast random(2) like (int)random(2) to get the
> 
> int value.
> 
> Draw the rectangle at the given col and row value with width 5 and height 12.
> 
> In the mousePressed() method Call the randomize() & drawAll() methods.

* * *

You don’t have to just send me the labs, I just need some help. I don’t know how any of this works, and my comp sci teacher isn’t helping me. I would like to have some steps on how to do it. But if worst comes to worst, I just need them given to me. I hope this isn’t too much to ask for. **If it is important I use Proccessing 3.**

Thank you,

- Jonathan.

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [April 20, 2020, 5:03pm UTC](https://discourse.processing.org/t/help-with-lab-changeable-chain/19966/2 "2020-04-20T17:03:52Z")

</div>

Hello @Jonathan25711 and welcome to the forum,

At the top of your post there are 2 links which address your initial question of how the forum works. Please read the **homework policy** and **asking questions** guidelines.

> [@Jonathan25711](#):
>
> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

In order to receive the best help with your question, you would need to supply code of what you have attempted so far. That is how forum members can determine your coding knowledge level and answer your question based on your current level.

Since your question is about arrays, provide as much code (or pseudo code) as you are able.

Also available are some GREAT online tutorials about arrays, here:

https://www.youtube.com/embed/videoseries?list=PLRqwX-V7Uu6bO9RKxHObluh-aPgrrvb4a&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1

And here:

[![]( " - YouTube") ](https://www.youtube.com/watch?v=8OkdmaspI6s)

Also, look up arrays on Khan Academy in their programming courses.  
This should get you started!!  
🤓

---

<div class="post-metadata">

**Author:** ![Jonathan25711](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Jonathan25711](https://discourse.processing.org/u/Jonathan25711)\
**Post date:** [April 20, 2020, 5:04pm UTC](https://discourse.processing.org/t/help-with-lab-changeable-chain/19966/3 "2020-04-20T17:04:48Z")

</div>

Thank you! I really needed this!!

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 20, 2020, 5:16pm UTC](https://discourse.processing.org/t/help-with-lab-changeable-chain/19966/4 "2020-04-20T17:16:50Z")

</div>

Hello,

Here are some additional resources:

> **Resources \< Click here to expand !**
>
> I encourage you to review the resources available here:
> 
> - The Processing website has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - Those available with the Processing PDE (IDE).  
> An exploration of the tabs will reveal what is available; there are libraries and examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.

`:)`
