Posted on:

18 Dec 2022

0

My code with two def function don't know this good or bad

`def transformation(x,y,t): # this function took two cordinate and one random choice
    if t == 1:
        x = x*0.5
        y = y*0.5
    elif t==2:
        x = x*0.5 + 0.5
        y = y*0.5 +0.5
    elif t==3:
        x = x*0.5 + 1
        y = y*0.5
    return round(x,2),round(y,2)
# print(transformation(0,0,2))
`
def sierpinski_tri(num):  # this function took one argument like how many times we wanna run our funcion
    trans_option = [1,2,3]
    x=y=0   #starting coordinate
    lis=[]
    lis1 = []
    for i in range(1,num):
        rand_choice = choice(trans_option)
        x,y= transformation(x,y,rand_choice)
        lis.append(x)
        lis1.append(y)
    plt.plot(lis,lis1,"o")
    plt.show()

sierpinski_tri(1000000) #Calling the function
0 answers ( 0 marked as helpful)

Submit an answer