Question: Write code in Python Generating a Sierpinski Triangle General Outline: Create a class Dice - an instance of this class will return values between 1

Write code in Python Write code in Python Generating a Sierpinski Triangle General Outline: Create

Generating a Sierpinski Triangle General Outline: Create a class Dice - an instance of this class will return values between 1 and 6, inclusive Create a class sierpinski with two methods: generate_data() and plot_data) The object Sierpinski is to be constructed as follows 1. Take three vertes points in a plane to form a triangle, .e. [[0,0],[20,201,140,0]| 2. select point 1,1 inside the triangle as your initial point and consider that your current position. 3. Randomly select any one of the three vertex points by calling (rolling) the instance of Dice object: if 1 or 2 comes up, select point [0,01 if 3 or 4 comes up, select point 120,20 if 5 or 6 comes up, select point [40,0 4. Move half the distance from your current position to the selected vertex and make that your 5. Plot the current position (add all data to lists x and Y, then use matplotlib.pyplot at the 6. Repeat from step 3 a 1000 times current position end to plot all points after all1 iterations have been completed) Your main function should look like this: #s sierpinski ([[Plx,P1y],[P2x,P2y],[P3x,P3y]], number-of-iterations, s Sierpinski(lo,01,120,201,140,0, 1000, 1, 1) s.generate_data) s.plot_data) current-pos-x, current-pos-y) Generating a Sierpinski Triangle General Outline: Create a class Dice - an instance of this class will return values between 1 and 6, inclusive Create a class sierpinski with two methods: generate_data() and plot_data) The object Sierpinski is to be constructed as follows 1. Take three vertes points in a plane to form a triangle, .e. [[0,0],[20,201,140,0]| 2. select point 1,1 inside the triangle as your initial point and consider that your current position. 3. Randomly select any one of the three vertex points by calling (rolling) the instance of Dice object: if 1 or 2 comes up, select point [0,01 if 3 or 4 comes up, select point 120,20 if 5 or 6 comes up, select point [40,0 4. Move half the distance from your current position to the selected vertex and make that your 5. Plot the current position (add all data to lists x and Y, then use matplotlib.pyplot at the 6. Repeat from step 3 a 1000 times current position end to plot all points after all1 iterations have been completed) Your main function should look like this: #s sierpinski ([[Plx,P1y],[P2x,P2y],[P3x,P3y]], number-of-iterations, s Sierpinski(lo,01,120,201,140,0, 1000, 1, 1) s.generate_data) s.plot_data) current-pos-x, current-pos-y)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!