Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write this in Python language! 5. Modern Art Monte Carlo Simulation You've decided to visit the Metropolitan Museum of Art with some friends and

Please write this in Python language!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

5. Modern Art Monte Carlo Simulation You've decided to visit the Metropolitan Museum of Art with some friends and notice an interesting painting on the wall: One of your friends wonders out loud how probable it would to hit a colored section of the painting if they were to close their eyes and throw a dart at random at the canvas. You tell your friend that this is a very bad idea, but because you are in an programming class you know that you can use your newly acquired Python skills to solve this problem! For this program you will be writing some code that will simulate the throwing of a random dart at this modern art painting. To do this you can repeatedly generate a random coordinate within the painting area and test to see which shape (if any) the dart falls into. Note that the playing field is 800 units wide and 500 units high, so you will be generating random coordinates within this range as part of your simulation. When you are finished you should calculate the % chance of a dart hitting a particular shape. Refer to the schematic below for the exact measurements of the painting. Hint: Start off by simulating just one dart toss and use the coordinate plane to determine if the dart has fallen into one of the colored regions. Start off with the red rectangle since it will be the simplest shape to work with how can you write a statement to determine if a point falls within a rectangle? From there, expand this logic and apply it to the other shapes. Hint: you may need the distance formula again to determine if a point falls within a circular region! Once you are confident that you have designed an effective algorithm you can scale up and place your code inside a loop. 0,0 800,0 0,500 800,500 Canvas is 800 units by 500 units Origin point (0,0) is at the top left edge of the diagram Here's a a few sample runnings of the program: 1 Number of throws: 10000 2 5 3 Total time elapsed: 1.19 seconds Red: 357 (3.57%) Blue: 791 (7.91%) Green: 1,643 (16.43%) Dark Grey: 810 (8.10%) Light Grey: 91 (0.91%) Misses: 6,308 (63.08%) 7 9 1 Number of throws: -50 2 Invalid, try again! 3 Number of throws: 50000 4 5 6 7 Total time elapsed: 4.61 seconds Red: 1,932 (3.86%) Blue: 3,952 (7.90%) Green: 8,153 (16.31%) 9 Dark Grey: 3,956 (7.91%) 10 Light Grey: 414 (0.83%) 11 Misses: 31,593 (63.19%) Additional Hints: You can ask Python to generate the current time by calling the time.time() func- tion. You will need to import the time module in order to call this function. A Monte Carlo simulation approximates a solution to a problem. Because of this you will see different numbers when you run your program. The percentages that get generates should roughly match the percentages shown here. The more "throws you compute the closer you will get to the actual solution. You can generate a random floating point number within a given range by using the random.uniform() function. This function takes two arguments - a low boundary and a high boundary - and generates a floating point number within this range (edges inclusive) The coordinate system shown here is one that is standard in the world of computer graphics - notice that the origin point is at the top left side of the screen, and that the y axis only contains positive values. You will need to format your output to match the sample output above (i.e. all of your values should line up) Your "execution time" value will likely be different than the ones given here in the sample output. This is due to the fact that every computer will run at a slightly different rate based on processor speed, available memory, etc. 5. Modern Art Monte Carlo Simulation You've decided to visit the Metropolitan Museum of Art with some friends and notice an interesting painting on the wall: One of your friends wonders out loud how probable it would to hit a colored section of the painting if they were to close their eyes and throw a dart at random at the canvas. You tell your friend that this is a very bad idea, but because you are in an programming class you know that you can use your newly acquired Python skills to solve this problem! For this program you will be writing some code that will simulate the throwing of a random dart at this modern art painting. To do this you can repeatedly generate a random coordinate within the painting area and test to see which shape (if any) the dart falls into. Note that the playing field is 800 units wide and 500 units high, so you will be generating random coordinates within this range as part of your simulation. When you are finished you should calculate the % chance of a dart hitting a particular shape. Refer to the schematic below for the exact measurements of the painting. Hint: Start off by simulating just one dart toss and use the coordinate plane to determine if the dart has fallen into one of the colored regions. Start off with the red rectangle since it will be the simplest shape to work with how can you write a statement to determine if a point falls within a rectangle? From there, expand this logic and apply it to the other shapes. Hint: you may need the distance formula again to determine if a point falls within a circular region! Once you are confident that you have designed an effective algorithm you can scale up and place your code inside a loop. 0,0 800,0 0,500 800,500 Canvas is 800 units by 500 units Origin point (0,0) is at the top left edge of the diagram Here's a a few sample runnings of the program: 1 Number of throws: 10000 2 5 3 Total time elapsed: 1.19 seconds Red: 357 (3.57%) Blue: 791 (7.91%) Green: 1,643 (16.43%) Dark Grey: 810 (8.10%) Light Grey: 91 (0.91%) Misses: 6,308 (63.08%) 7 9 1 Number of throws: -50 2 Invalid, try again! 3 Number of throws: 50000 4 5 6 7 Total time elapsed: 4.61 seconds Red: 1,932 (3.86%) Blue: 3,952 (7.90%) Green: 8,153 (16.31%) 9 Dark Grey: 3,956 (7.91%) 10 Light Grey: 414 (0.83%) 11 Misses: 31,593 (63.19%) Additional Hints: You can ask Python to generate the current time by calling the time.time() func- tion. You will need to import the time module in order to call this function. A Monte Carlo simulation approximates a solution to a problem. Because of this you will see different numbers when you run your program. The percentages that get generates should roughly match the percentages shown here. The more "throws you compute the closer you will get to the actual solution. You can generate a random floating point number within a given range by using the random.uniform() function. This function takes two arguments - a low boundary and a high boundary - and generates a floating point number within this range (edges inclusive) The coordinate system shown here is one that is standard in the world of computer graphics - notice that the origin point is at the top left side of the screen, and that the y axis only contains positive values. You will need to format your output to match the sample output above (i.e. all of your values should line up) Your "execution time" value will likely be different than the ones given here in the sample output. This is due to the fact that every computer will run at a slightly different rate based on processor speed, available memory, etc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago