# Python: Use object-oriented programming and Numpy techniques to create simple graphics with bullseyes

**Need help with this question or any other academic project? Click on the button below to to hire an expert cheap.**

## Get Help With a similar task to - Python: Use object-oriented programming and Numpy techniques to create simple graphics with bullseyes

##### Additional Instructions:

6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 1/6 Homework, Problem 2 (45 points) Introduction In this problem, you'll use object-oriented programming and Numpy techniques to create simple graphics with bullseyes, like this one: Example output from this problem. A Note on Loops There is precisely one place in this entire problem in which a loop (such as a for -loop, a while - loop, or a list comprehension) is completely appropriate. This place is Part D. I'll tell you when we get there. With that one exception, you should avoid the use of loops whenever possible. Solutions that use loops elsewhere will receive partial credit. Concision and Style Remember, concision and style are two of the criteria on which we assess your solutions. You should aim to write code that is as short, simple, and readable as possible. My own solution for this problem requires 21 lines excluding comments. Longer solutions are ok, as long as they don't perform redundant computation and appropriately make use of Numpy operations. Comments and Docstrings Comments and docstrings are not required in any part of this problem. However, they may help us give you partial credit, so they are recommended unless you're feeling very confident. 6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 2/6 Input Checking It is not necessary to perform any input checking in this problem -- you can assume that the user will supply inputs with the correct data types, shapes, etc. Image Appearance It's ok for your images to look a little different from mine. For example, your image might appear slightly jagged or blocky, depending on the size of your background Canvas . That's ok! As long as your image clearly demonstrates correct code, you'll receive full credit. Part A You don't have to write any code here, just run the block below. You did it! Part B (10 points) Create a class Canvas , and implement two methods. The __init__() method should take two arguments other than self , background and n . The background is expected to be a 1d Numpy array of length 3, representing an RGB color. For example, black = np.array([0,0,0]) and purple = np.array([0.5, 0.5, 0]) . At this stage, the __init__ method should create an instance variable self.im , a Numpy array of shape (n, n, 3) . This array should be constructed so that self.im[i,j] == background for each value of i and j . The show() method should take no arguments (except for self ), and simply display self.im using the plt.imshow() function. For example, the code purple = np.array([0.5, 0.0, 0.5]) C = Canvas(purple, 2001) # 2001 x 2001 pixels C.show() should display a purple square, like this one: In [ ]: # run this to get started import numpy as np from matplotlib import pyplot as plt 6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 3/6 Example output. Make sure to run the test block after your class definition in order to demonstrate that your code works. Notes You can use ax.axis("off") to remove the axis ticks and borders, although that's not required for this problem. For me, the easiest way to create self.im was to create an array of appropriate dimensions using np.zeros() , and then populate it using array broadcasting. This problem can be solved using a loop for partial credit. Part C (15 points) Modifying your class above (that is, not copy/pasting code), implement a method called add_disk(centroid, radius, color) , which draws a colored disk with specified radius , centered at centroid , of the specified color. centroid may be assumed to be a tuple, list, or Numpy array of the form (x,y) , where x gives the horizontal coordinate of the disk's center and y gives the vertical coordinate. All points within distance radius of the centroid should be filled in with color . For example, the code In [ ]: # define your Canvas class here # solutions to Parts B, C, and D should all be in this cell In [ ]: # test code: run but do not modify purple = np.array([0.5, 0, 0.5]) C = Canvas(purple, 2001) # 2001 x 2001 pixels C.show() 6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 4/6 purple = np.array([.5, 0, .5]) white = np.array([1, 1, 1]) C = Canvas(background = purple, n = 2001) C.add_disk((1001, 1001), 500, white) C.show() should produce the following image: Example output. Run the test code supplied below to demonstrate that your code is working. Math Note Recall that the (open) disk of radius with centroid is the set of all points satisfying the formula Programming Notes The function np.meshgrid is a useful way to represent the horizontal and vertical coordinates. If you take this approach, you should ensure that this function is called only once even if your user calls self.add_disk() multiple times. This problem can be solved using a loop for partial credit. If you do take the loop-based approach for partial credit, you may need to reduce n , the size of the Canvas , in the examples below, as your code might be slower. r (x0, y0) (x, y) (x − x0) 2 + (y − y0) 2 < r2 . In [ ]: # test code: run but do not modify purple = np.array([.5, 0, .5]) white = np.array([1, 1, 1]) C = Canvas(background = purple, n = 2001) C.add_disk((1001, 1001), 500, white) C.show() 6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 5/6 Part D (15 points) Modify your code from Part B (still no copy/paste), write a method called add_bullseye(centroid, radius, color1, color2, bandwidth) . This method should create a bullseye pattern consisting of concentric circles with alternating colors. Each circle should have thickness equal to bandwidth , and the radius of the entire pattern should be equal to radius . For example: purple = np.array([0.5, 0.0, 0.5]) white = np.array([1.0, 1.0, 1.0]) grey = np.array([0.2, 0.2, 0.2]) C = Canvas(background = grey, n = 2001) C.add_bullseye((1001, 1001), 500, purple, white, bandwidth = 50) C.show() Example output. In this example, each of the bands is 50 pixels thick, and the entire pattern has radius 500. Loops In this part, it would be appropriate to write one for - or while -loop. Hint You might wish to create a new cell and run the following code -- it could help you catch on to the right idea. purple = np.array([0.5, 0.0, 0.5]) white = np.array([1.0, 1.0, 1.0]) grey = np.array([0.2, 0.2, 0.2]) C = Canvas(background = grey, n = 2001) C.add_disk((1001, 1001), 500, purple) 6/8/2021 Homework_P2 localhost:8889/nbconvert/html/Downloads/Homework_P2.ipynb?download=false 6/6 C.add_disk((1001, 1001), 450, white) C.show() Part E (5 points) Write a further demonstration of the correct functioning of your code by creating a new Canvas with at least three bullseyes drawn on it. You should demonstrate: At least three (3) different centroids. At least four (4) different colors. At least three (3) different values of the bandwidth parameter. You're also welcome to vary the radius parameter, but this isn't required. You're encouraged to be creative! Coordinate your colors, let your bullseyes partially intersect, etc. etc. But if you're not really feeling your artistic mojo today, it's ok to base your solution on the example shown at the very beginning of this problem, which satisfies all of the above criteria. I've predefined the colors I used for your convenience. Provided that you've solved up to Part D correctly, no further modifications to your Canvas class are required. In [ ]: # test code: run but do not modify purple = np.array([0.5, 0.0, 0.5]) white = np.array([1.0, 1.0, 1.0]) grey = np.array([0.2, 0.2, 0.2]) C = Canvas(background = grey, n = 2001) C.add_bullseye((1001, 1001), 500, purple, white, bandwidth = 50) C.show() In [ ]: # predefined colors -- feel free to add your faves! purple = np.array([.5, 0, .5]) white = np.array([1, 1, 1]) green = np.array([0, 1, 0]) blue = np.array([0, 0, 1]) orange = np.array([1, .4, 0]) yellow = np.array([1, 1, 0]) grey = np.array([.2,.2,.2]) # write your demonstration here # don't forget to show the image!

## Related Questions

Tutlance Experts offer help in a wide range of topics. Here are some of our top services:

- Do my math homework
- Do my nursing homework
- Do my statistics homework
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Do my programming homework
- Do my engineering homework
- Coursework writing help
- Term paper writing help
- Biology homework help
- Physics homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing help
- Chemistry homework help
- Math homework help
- Statistics homework help
- Programming homework help
- Online Assignment Help
- Essay Writing Help

Post your project now for free and watch professional experts outbid each other in just a few minutes.