''' **Exercise A:** In this exercise, you will build upon your code from Random particle diffusion, Exercise B. There, you were able to keep the particles inside the graphical window. In this exercise, you're asked to adjust the borders in such a way that 100 particles are now contained in a specified area. This container should be smaller than the screen. Make 3 versions with a square, a rectangular, and finally with a round container. Hint: testing whether a particle is inside a square or rectangular container is similar to testing if it stays within the screen, like you did before. However, testing whether a particle is inside a circle is a bit different. A circle is made up of a sine and a cosine function, centred on the middle and is as big as its radius. If the distance between a particle and the centre of a circle is larger than the radius of that circle, the particle is not inside the circle anymore. Use this information to think of a test to keep the particles within the round container. **Exercise B:** Extend your program from exercise A such that instead of a single round container you make three round containers and let there be 100 moving particles in each container. The particles should not escape the containers. Hint: the particles should get a location within one of the three containers before starting the simulation. All particles should be tested for all containers even if they are not inside that particular container. If a displacement leads to the future location of a particle outside of any container, this displacement should not be made. **Exercise C:** In exercise B we tested if particles were inside any of three containers. The code to check if particles are inside a container is very similar for each container, with just some changes in the location of the container and the size of the container. When there are many similar sections of code, you will recall from a previous book section that it's useful to define a Python function. In this exercise, you're asked to rewrite the code to check if a particle is in a container using a function. The inputs should be the `X` and `Y` location of the particle, and the `X` and `Y` location and radius of a container. The output should be a Boolean returning `True` if the particle is in the container and `False` if it is outside. For example, ''' def incircle(x, y, x_container, y_container, r_container): output = # code to test if x and y are inside container return output ''' Now you can check if a particle is inside the container using: ''' if incircle(x,y,x_c,y_c,r): # code to do if particle is in the container ''' **Exercise D:** Extend your program from exercise A, use the round container and the function from exercise C. When a particle tries to escape the container, introduce a chance of 25 % that it will succeed. See what happens when you vary the chance. Hint: Use the `random` function to create a probability. **Exercise E:** Extend your code from exercise D such that if a particle escapes the container, make it change colour and size. **Exercise F:** Extend your program from exercise E such that you keep track of the number of particles inside and outside of the container. Plot these numbers against time in a graph in a new graphical window positioned next to the graphical window with the moving particles. Therefore, another screen is required. Define this directly after the original screen: ''' chart = canvas("charttitle", xSize, ySize, xpos=50, ypos=50) ''' The last two arguments define the location of the chart, in this case at 50 pixels outside of the left upper corner of your screen. Hint: Think about how you would draw a dynamic graph using the NaNoPy package and what type of graph you want to plot. '''