Question

Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code.Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plThe chaos game refers to the following recipe . Pick a positive integer vnum2 3 and a real number 0 < f < 1 » Pick vnum pointdef sierpinski(p0, vs, f, inum): Generate points for the Sierpinski gasket Args: pe: 2-element np.ndarray [x, yl represent

Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plot the points to see the structure. Please complete the following function: def sierpinski (po, v, f, inum) The four arguments are ·po the initial point. You may assume this is the origin, i.e., po = [0, 0] . v: the vertices. You may assume these are given by v above. . f: the fractional value between the current point and the randomly selected vertex used to select the next point. You may assume f 0.5 inum: the number of points. You may assume inum - 100000. This function should return a set of points, denoted p, stored as a numpy array, of dimension inum × 2, where the column store the r and y coordinates of each point, and the points are generated using the recipe above.
The chaos game refers to the following recipe . Pick a positive integer vnum2 3 and a real number 0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have tried to solve your question. I could not understand it clearly, but coded it till I understood. Since we are generating 100000 points the program might take a few seconds to run.

CODE:

###################################

import random

def sierpinski(p0, vs, f, inum):

curr = p0
pts_list = []
for i in range(inum):
pts_list.append(curr)

curr[0] = curr[0]+random.random()*f
curr[1] = curr[1]+random.random()*f

return pts_list

print(sierpinski([0,0], [[1,2,3], [1,2,3]], 0.5, 100000))

##################################

Add a comment
Know the answer?
Add Answer to:
Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT