✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Complete sierpinski.py by selecting one of the given code snippets below. The code snippet you select must enable sierpinski.py to generate Figure A when it is executed.
Voltooi sierpinski.py deur een van die gegewe kode uitreksels te kies. Die kode uitreksel wat jy kies moet sierpinski.py in staat stel om Figuur A te genereer.
#sierpinski.pyimport stddraw
def main(): #YOUR CHOSEN CODE SNIPPET WILL BE INSERTED HERE
cx = [0.000, 1.000, 0.500] cy = [0.000, 0.000, 0.866] stddraw.setXscale(-0.1,1.1) stddraw.setYscale(-0.1,1.1)
stddraw.line(cx[0],cy[0],cx[1],cy[1]) stddraw.line(cx[1],cy[1],cx[2],cy[2]) stddraw.line(cx[2],cy[2],cx[0],cy[0]) stddraw.setPenColor(stddraw.RED) stddraw.filledCircle(cx[0], cy[0], 0.05) stddraw.setPenColor(stddraw.BLACK) stddraw.text(cx[0], cy[0], "0") x = 0.0 y= 0.0 for v in range(0,len(vertices)):
r = vertices[v] x = (x + cx[r]) / 2.0 y = (y + cy[r]) / 2.0 if (r == 0): stddraw.setPenColor(stddraw.RED) elif (r == 1): stddraw.setPenColor(stddraw.GREEN) elif (r == 2): stddraw.setPenColor(stddraw.BLUE) stddraw.filledCircle(x, y, 0.05) if (r == 2): stddraw.setPenColor(stddraw.WHITE) else: stddraw.setPenColor(stddraw.BLACK) stddraw.text(x, y, ""+str(v+1)) stddraw.show()
if __name__ == "__main__": main()
Figure A/Figuur A